2015-09-15 20:17:52 -05:00
|
|
|
#include <iostream>
|
|
|
|
#include <vector>
|
|
|
|
#include "Attribute.h"
|
|
|
|
|
2015-09-15 21:31:19 -05:00
|
|
|
//Functional
|
2015-09-15 20:17:52 -05:00
|
|
|
class Relation {
|
|
|
|
string name; //The title the user gives it
|
2015-09-15 20:55:21 -05:00
|
|
|
vector<Attribute> att; //A vector of the columns
|
2015-09-15 20:17:52 -05:00
|
|
|
|
|
|
|
public:
|
|
|
|
Relation();
|
|
|
|
|
|
|
|
//constructor
|
2015-09-15 20:55:21 -05:00
|
|
|
Relation(string n, vector<Attribute> a) {
|
2015-09-15 20:17:52 -05:00
|
|
|
name = n;
|
|
|
|
att = a;
|
2015-09-15 20:55:21 -05:00
|
|
|
}
|
2015-09-15 20:17:52 -05:00
|
|
|
|
2015-09-15 21:31:19 -05:00
|
|
|
void addTuple(vector<string> tuple) {
|
2015-09-15 20:17:52 -05:00
|
|
|
//Loop through the attribute columns
|
|
|
|
for(int i = 0; i < att.size(); i++) {
|
|
|
|
|
|
|
|
//Loop through the elements in the i'th column
|
|
|
|
for(int j = 0; j < att[i].values.size(); j++){
|
|
|
|
|
|
|
|
//In this column, at this element's spot, assign an element from the tuple vector to this spot
|
2015-09-15 20:55:21 -05:00
|
|
|
att[i].addRow(tuple[i]);
|
2015-09-15 20:17:52 -05:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-09-15 20:55:21 -05:00
|
|
|
string getTableName() {
|
|
|
|
return name;
|
|
|
|
}
|
|
|
|
|
2015-09-15 20:17:52 -05:00
|
|
|
void displayTableName() {
|
|
|
|
cout << "The table name is: " << name << endl;
|
|
|
|
}
|
|
|
|
|
2015-09-15 21:31:19 -05:00
|
|
|
vector<Attribute> getAttributes() {
|
2015-09-15 20:17:52 -05:00
|
|
|
return att;
|
|
|
|
}
|
|
|
|
|
|
|
|
int getSize() {
|
|
|
|
return att.size();
|
|
|
|
}
|
2015-09-15 20:23:47 -05:00
|
|
|
|
2015-09-15 21:31:19 -05:00
|
|
|
void display() {
|
2015-09-15 20:23:47 -05:00
|
|
|
cout<<"\n\nDisplay of relation--------------------------------"<<endl;
|
|
|
|
cout<<"Relation name: "<<name<<endl;
|
2015-09-15 21:31:19 -05:00
|
|
|
for (int i = 0; i < att.size(); ++i)
|
2015-09-15 20:23:47 -05:00
|
|
|
{
|
|
|
|
|
2015-09-15 21:31:19 -05:00
|
|
|
cout<<"\nAttribute name: "<<att[i].getName()<<": ";
|
2015-09-15 20:23:47 -05:00
|
|
|
|
2015-09-15 20:36:33 -05:00
|
|
|
att[i].display();
|
2015-09-15 20:23:47 -05:00
|
|
|
|
|
|
|
}
|
|
|
|
}
|
2015-09-15 20:17:52 -05:00
|
|
|
};
|