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 {
//a named column of a relation
string name;
bool isKey;
string type;
bool key;
int size;
public:
vector<string> values;
void initializeAttribute(string n, vector<string> a){
Attribute(string n, string t, bool k){
name = n;
values = a;
type = t;
key = k;
size = 0;
}
void addRow(string v) {
values.push_back(v);
}
string getName(){
return name;
}
Attribute(){ }
string getType(){
return type;
}
bool isKey(){
return key;
}
void display()
{

View file

@ -6,21 +6,19 @@ using namespace std;
//NOT DONE
class Relation {
//a table with rows and columns
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:
Relation();
//constructor
Relation(string n, vector< Attribute > a) {
Relation(string n, vector<Attribute> a) {
name = n;
att = a;
}
void addTuple(vector< string > tuple) {
//Loop through the attribute columns
for(int i = 0; i < att.size(); i++) {
@ -28,11 +26,15 @@ public:
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]);
att[i].addRow(tuple[i]);
}
}
}
string getTableName() {
return name;
}
void displayTableName() {
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;
int main() {
Attribute atributo("shamWow", "VARCHAR(10)", false);
/*
DBEngine engine;
Relation r;
Attribute<int> a;
*/
atributo.addRow("rag");
atributo.addRow("sponge");
atributo.addRow("wooow");
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();
vector<string> doom;
doom.push_back("zombieman");
doom.push_back("revenant");
doom.push_back("imp");
doom.push_back("archvile");
Attribute atributo2("doom", "VARCHAR(20)", false);
atributo2.addRow("zombieman");
atributo2.addRow("revenant");
atributo2.addRow("imp");
atributo2.addRow("archvile");
Attribute atributo2;
atributo2.initializeAttribute("attribute_2", doom);
atributo2.display();
string line1 = "Table_1";
//Relation r(line1, my_attributes);
}