-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtable.cpp
More file actions
47 lines (39 loc) · 1.04 KB
/
table.cpp
File metadata and controls
47 lines (39 loc) · 1.04 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
#include "table.h"
Table::Table(const string & name){
this->name = name;
}
const string & Table::getName() const {
return name;
}
void Table::addColumn(const Column & column) {
columns.push_back(column);
}
void Table::addRow(const Row & row){
if (row.getValues().size() != columns.size()) {
throw runtime_error("Error: Column count mismatch.");
}
rows.push_back(row);
}
const vector<Column> & Table::getColumns() const {
return columns;
}
const vector<Row> & Table::getRows() const {
return rows;
}
void Table::print() const{
cout << "Table: " << getName()<<endl;
cout << "Columns:"<<endl;
vector<Column> columns = getColumns();
for (int j = 0; j < columns.size(); j++) {
columns[j].print();
}
cout << "Rows:"<<endl;
for (int j = 0; j < columns.size(); j++) {
columns[j].printHeader(); cout << "\t";
}
cout<< endl << endl;
vector<Row> rows = getRows();
for (int k = 0; k < rows.size(); k++) {
rows[k].print();
}
}