|
|
|
@ -1,5 +1,6 @@
|
|
|
|
|
#pragma once
|
|
|
|
|
#include "cnumber.hpp"
|
|
|
|
|
#include <iomanip>
|
|
|
|
|
#include <iostream>
|
|
|
|
|
using namespace std;
|
|
|
|
|
class matrix;
|
|
|
|
@ -11,12 +12,12 @@ private:
|
|
|
|
|
|
|
|
|
|
public:
|
|
|
|
|
bool is_error() { return this->err; }
|
|
|
|
|
vector() {};
|
|
|
|
|
vector(){};
|
|
|
|
|
vector(const long long dimention) {
|
|
|
|
|
this->err = false;
|
|
|
|
|
this->dimention = dimention;
|
|
|
|
|
free(this->entries);
|
|
|
|
|
this->entries = (cnumber *)malloc(sizeof(cnumber)* dimention);
|
|
|
|
|
this->entries = (cnumber *)malloc(sizeof(cnumber) * dimention);
|
|
|
|
|
for (long long i = 0; i < dimention; i++) {
|
|
|
|
|
this->set_entry(i, cnumber(0, 0));
|
|
|
|
|
}
|
|
|
|
@ -25,7 +26,7 @@ public:
|
|
|
|
|
this->err = false;
|
|
|
|
|
this->dimention = v.get_dimention();
|
|
|
|
|
free(this->entries);
|
|
|
|
|
this->entries = (cnumber *)malloc(sizeof(cnumber)* v.get_dimention());
|
|
|
|
|
this->entries = (cnumber *)malloc(sizeof(cnumber) * v.get_dimention());
|
|
|
|
|
for (long long i = 0; i < v.get_dimention(); i++) {
|
|
|
|
|
this->set_entry(i, v.get_entry(i));
|
|
|
|
|
}
|
|
|
|
@ -33,7 +34,7 @@ public:
|
|
|
|
|
~vector() {
|
|
|
|
|
this->dimention = 0;
|
|
|
|
|
free(this->entries);
|
|
|
|
|
//this->entries = NULL;
|
|
|
|
|
// this->entries = NULL;
|
|
|
|
|
this->err = true;
|
|
|
|
|
}
|
|
|
|
|
long long get_dimention() const { return this->dimention; }
|
|
|
|
@ -59,8 +60,20 @@ public:
|
|
|
|
|
cnumber &operator[](const long long index) { return this->entries[index]; }
|
|
|
|
|
|
|
|
|
|
friend ostream &operator<<(ostream &os, const vector &v) {
|
|
|
|
|
int longest = 0;
|
|
|
|
|
for (long long i = 0; i < v.get_dimention(); i++) {
|
|
|
|
|
os << "| " << v[i] << " |";
|
|
|
|
|
ostringstream oss;
|
|
|
|
|
oss << v[i];
|
|
|
|
|
string s = oss.str();
|
|
|
|
|
if (longest < s.length())
|
|
|
|
|
longest = s.length();
|
|
|
|
|
}
|
|
|
|
|
for (long long i = 0; i < v.get_dimention(); i++) {
|
|
|
|
|
ostringstream oss;
|
|
|
|
|
oss << v[i];
|
|
|
|
|
string s = oss.str();
|
|
|
|
|
int padding = longest - s.length() +1;
|
|
|
|
|
os << "|" << v[i] << std::setw(padding) << "|";
|
|
|
|
|
if (i != v.get_dimention() - 1)
|
|
|
|
|
os << endl;
|
|
|
|
|
}
|
|
|
|
@ -69,7 +82,7 @@ public:
|
|
|
|
|
void operator=(const vector &v) {
|
|
|
|
|
this->dimention = v.get_dimention();
|
|
|
|
|
free(this->entries);
|
|
|
|
|
this->entries = (cnumber *)malloc(sizeof(cnumber)* dimention);
|
|
|
|
|
this->entries = (cnumber *)malloc(sizeof(cnumber) * dimention);
|
|
|
|
|
for (long long i = 0; i < v.get_dimention(); i++) {
|
|
|
|
|
this->set_entry(i, v.get_entry(i));
|
|
|
|
|
}
|
|
|
|
|