attribute works as expects

This commit is contained in:
Rebecca Schofield 2015-09-15 20:55:21 -05:00
parent 903b6c98d5
commit 94912e6b14
4 changed files with 38 additions and 39 deletions

View file

@ -9,25 +9,36 @@ using namespace std;
class Attribute { class Attribute {
//a named column of a relation //a named column of a relation
string name; string name;
string type;
bool isKey; bool key;
int size; int size;
public: public:
vector<string> values; vector<string> values;
void initializeAttribute(string n, vector<string> a){ Attribute(string n, string t, bool k){
name = n; name = n;
values = a; type = t;
key = k;
size = 0;
}
void addRow(string v) {
values.push_back(v);
} }
string getName(){ string getName(){
return name; return name;
} }
Attribute(){ } string getType(){
return type;
}
bool isKey(){
return key;
}
void display() void display()
{ {

View file

@ -6,21 +6,19 @@ using namespace std;
//NOT DONE //NOT DONE
class Relation { class Relation {
//a table with rows and columns
string name; //The title the user gives it string name; //The title the user gives it
vector< Attribute > att; //A vector of the columns vector<Attribute> att; //A vector of the columns
public: public:
Relation(); Relation();
//constructor //constructor
Relation(string n, vector< Attribute > a) { Relation(string n, vector<Attribute> a) {
name = n; name = n;
att = a; att = a;
} }
void addTuple(vector< string > tuple) { void addTuple(vector< string > tuple) {
//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++) {
@ -28,11 +26,15 @@ public:
for(int j = 0; j < att[i].values.size(); j++){ 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 //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]); att[i].addRow(tuple[i]);
} }
} }
} }
string getTableName() {
return name;
}
void displayTableName() { void displayTableName() {
cout << "The table name is: " << name << endl; cout << "The table name is: " << name << endl;
} }

BIN
a.out Executable file

Binary file not shown.

View file

@ -6,39 +6,25 @@
using namespace std; using namespace std;
int main() { int main() {
Attribute atributo("shamWow", "VARCHAR(10)", false);
/* atributo.addRow("rag");
DBEngine engine; atributo.addRow("sponge");
Relation r; atributo.addRow("wooow");
Attribute<int> a; atributo.addRow("cloth");
*/
vector<string> shamWow;
shamWow.push_back("rag");
shamWow.push_back("sponge");
shamWow.push_back("wooow");
shamWow.push_back("cloth");
Attribute atributo;
atributo.initializeAttribute("atributo",shamWow);
atributo.display(); atributo.display();
vector<string> doom; Attribute atributo2("doom", "VARCHAR(20)", false);
doom.push_back("zombieman");
doom.push_back("revenant"); atributo2.addRow("zombieman");
doom.push_back("imp"); atributo2.addRow("revenant");
doom.push_back("archvile"); atributo2.addRow("imp");
atributo2.addRow("archvile");
Attribute atributo2;
atributo2.initializeAttribute("attribute_2", doom);
atributo2.display(); atributo2.display();
string line1 = "Table_1"; string line1 = "Table_1";
//Relation r(line1, my_attributes); //Relation r(line1, my_attributes);
} }