Update Relation.h

This commit is contained in:
Brandon Jackson 2015-09-15 21:49:49 -05:00
parent 8dc821422b
commit 3a18ac0608

View file

@ -4,57 +4,82 @@
//Functional //Functional
class Relation { class Relation {
string name; //The title the user gives it //a table with rows and columns
vector<Attribute> att; //A vector of the columns string name; //the name of the relation (table)
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) {
//Loop through the attribute columns
for(int i = 0; i < att.size(); i++) {
if(tuple.size() != att.size()){
//Loop through the elements in the i'th column cout << "\n ERROR" << endl;
for(int j = 0; j < att[i].values.size(); j++){ }
else {
//In this column, at this element's spot, assign an element from the tuple vector to this spot //Loop through the attribute columns
att[i].addRow(tuple[i]); for(int i = 0; i < att.size(); i++) {
att[i].pushBack(tuple[i]);
} }
} }
} }
string getTableName() { void removeTuple(int tupleNum)
return name; {
if (tupleNum > att[0].getSize() || tupleNum < 0)
{
cout<<"ERROR! index out of bound"<<endl;
}
else
{
for(int i = 0; i < att.size(); ++i) //for all the attributes
{
att[i].erase(tupleNum);
}
}
} }
void displayTableName() { void projectQuery(string input)
cout << "The table name is: " << name << endl; {
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;
}
break;
}
else
cout << "Attribute input not valid" << endl;
}
} }
vector<Attribute> getAttributes() { void display()
return att; {
}
int getSize() {
return att.size();
}
void display() {
cout<<"\n\nDisplay of relation--------------------------------"<<endl; cout<<"\n\nDisplay of relation--------------------------------"<<endl;
cout<<"Relation name: "<<name<<endl; cout<<"Relation name: "<<name<<endl;
for (int i = 0; i < att.size(); ++i) for (int i = 0; i < attributeNames.size(); ++i)
{ {
cout<<"\nAttribute name: "<<att[i].getName()<<": "; cout<<"\nAttribute name: "<<attributeNames[i]<<": ";
att[i].display(); att[i].display();
} }
} }
}; };