Make it possible to print as row
This commit is contained in:
parent
d88f108aec
commit
10d74236e7
1 changed files with 17 additions and 4 deletions
21
vector.hpp
21
vector.hpp
|
@ -8,6 +8,7 @@ private:
|
|||
uint64_t dimention = 0;
|
||||
cnumber *entries = NULL;
|
||||
bool err = true;
|
||||
bool row = false;
|
||||
|
||||
public:
|
||||
bool is_error() { return this->err; }
|
||||
|
@ -44,6 +45,8 @@ public:
|
|||
}
|
||||
return cnumber(0, 0);
|
||||
}
|
||||
void make_row() { this->row = true; }
|
||||
void make_column() { this->row = false; }
|
||||
void set_entry(const uint64_t index, const cnumber z) {
|
||||
if (index < this->get_dimention()) {
|
||||
this->entries[index] = z;
|
||||
|
@ -60,18 +63,28 @@ public:
|
|||
|
||||
friend std::ostream &operator<<(std::ostream &os, const vector &v) {
|
||||
int longest = 0;
|
||||
if (v.row) {
|
||||
os << '(';
|
||||
for (uint64_t i = 0; i < v.get_dimention(); i++) {
|
||||
os << v[i];
|
||||
if (i != v.get_dimention() - 1)
|
||||
os << ',';
|
||||
}
|
||||
os << ')';
|
||||
return os;
|
||||
}
|
||||
for (uint64_t i = 0; i < v.get_dimention(); i++) {
|
||||
std::ostringstream oss;
|
||||
std::ostringstream oss;
|
||||
oss << v[i];
|
||||
std::string s = oss.str();
|
||||
if (longest < s.length())
|
||||
longest = s.length();
|
||||
longest = s.length();
|
||||
}
|
||||
for (uint64_t i = 0; i < v.get_dimention(); i++) {
|
||||
std::ostringstream oss;
|
||||
std::ostringstream oss;
|
||||
oss << v[i];
|
||||
std::string s = oss.str();
|
||||
int padding = longest - s.length() +1;
|
||||
int padding = longest - s.length() + 1;
|
||||
os << "|" << v[i] << std::setw(padding) << "|";
|
||||
if (i != v.get_dimention() - 1)
|
||||
os << std::endl;
|
||||
|
|
Loading…
Add table
Reference in a new issue