diff --git a/Attribute.h b/Attribute.h index 6621b08..fde2fcc 100755 --- a/Attribute.h +++ b/Attribute.h @@ -7,68 +7,49 @@ using namespace std; //template class Attribute { - //a named column of a relation + vector values; string name; - bool isKey; + string type; + bool key; int size; public: - - vector values; - - void initializeAttribute(string n, vector a){ - + Attribute(string n, string t, bool k){ name = n; - values = a; + type = t; + key = k; + size = 0; } - string getName(){ - return name; + void addRow(string v) { + values.push_back(v); } - Attribute(){ } + vector getValues() { return values; } + string getName(){ return name; } + string getType(){ return type; } + bool isKey(){ return key; } + int getSize(){ return size; } void display() { - //cout<<"\nAtribute name:\t"< a){ + + name = n; + values = a; } void erase(int position) { values.erase(values.begin()+ position); - } -/* - Attribute(vector v){ - this.values = v; - } - - Attribute(const Attribute& a){ - this.values = a.getAll(); - } - - Attribute& operator=(const Attribute& a){ - this.values = a.getAll(); - } - - - - vector getAll(){ - return this.values; - } -*/ + } }; diff --git a/Relation.h b/Relation.h index ee95ad7..64b8aa3 100755 --- a/Relation.h +++ b/Relation.h @@ -4,17 +4,12 @@ //Functional class Relation { - //a table with rows and columns - string name; //the name of the relation (table) - vector att; - vector attributeNames; - int size; + string name; //The title the user gives it + vector att; //A vector of the columns + itn size; public: - //Relation(); - - void initializeRelation(string n, vector attNames, vector a) { - attributeNames = attNames; + Relation(string n, vector a) { name = n; att = a; size = 0; @@ -23,13 +18,15 @@ public: int getSize() { return size; } void addTuple(vector tuple) { - if(tuple.size() != att.size()){ - cout << "\n ERROR" << endl; - } - else { - //Loop through the attribute columns - for(int i = 0; i < att.size(); i++) { - att[i].pushBack(tuple[i]); + //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 + att[i].addRow(tuple[i]); + size++; } } } @@ -49,6 +46,20 @@ public: } } } + + int getSize() { return size; } + + string getTableName() { + return name; + } + + void displayTableName() { + cout << "The table name is: " << name << endl; + } + + vector getAttributes() { + return att; + } void projectQuery(string input) { cout << "-----------Initiated Query Projection---------" << endl;