Update Relation.h

This commit is contained in:
Brandon Jackson 2015-09-15 21:37:11 -05:00
parent d28e68beb0
commit 66196158fc

View file

@ -7,41 +7,65 @@ using namespace std;
//NOT DONE //NOT DONE
class Relation { class Relation {
//a table with rows and columns //a table with rows and columns
string name; //The title the user gives it string name; //the name of the relation (table)
vector< Attribute > att; //A vector of the columns vector<Attribute> att;
vector<string> attributeNames;
public: public:
Relation(); //Relation();
//constructor void initializeRelation(string n, vector<string> attNames, vector<Attribute> a)
Relation(string n, vector< Attribute > a) { {
attributeNames = attNames;
name = n; name = n;
att = a; att = a;
} }
void addTuple(vector< string > tuple) { void addTuple(vector< string > tuple) {
if(tuple.size() != att.size()){
cout << "\n ERROR" << endl;
}
else {
//Loop through the attribute columns //Loop through the attribute columns
for(int i = 0; i < att.size(); i++) { for(int i = 0; i < att.size(); i++) {
att[i].pushBack(tuple[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
(att[i].values[j]).assign(tuple[i]);
} }
} }
} }
void displayTableName() {
cout << "The table name is: " << name << endl; void projectQuery(string input)
{
cout << "-----------Initiated Query Projection---------" << endl;
for(int i = 0; i < att.size(); i++) {
if(att[i].getName() == input) {
cout << "Column Title: " << input << endl;
for(int j = 0; j < att[i].getSize(); j++) {
cout << att[i].values[j] << endl;
} }
vector< Attribute > getAttributes(){ break;
return att; }
else
cout << "Attribute input not valid" << endl;
}
}
void display()
{
cout<<"\n\nDisplay of relation--------------------------------"<<endl;
cout<<"Relation name: "<<name<<endl;
for (int i = 0; i < attributeNames.size(); ++i)
{
cout<<"\nAttribute name: "<<attributeNames[i]<<": ";
att[i].display();
} }
int getSize() {
return att.size();
} }
}; };