attribute works as expects
This commit is contained in:
parent
903b6c98d5
commit
94912e6b14
4 changed files with 38 additions and 39 deletions
23
Attribute.h
23
Attribute.h
|
@ -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()
|
||||||
{
|
{
|
||||||
|
|
|
@ -6,7 +6,6 @@ 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
|
||||||
|
|
||||||
|
@ -20,7 +19,6 @@ public:
|
||||||
}
|
}
|
||||||
|
|
||||||
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
BIN
a.out
Executable file
Binary file not shown.
36
test.cpp
36
test.cpp
|
@ -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);
|
||||||
}
|
}
|
||||||
|
|
Reference in a new issue