use this code

This commit is contained in:
Rebecca Schofield 2015-09-15 22:18:19 -05:00
commit b6e66e298b
2 changed files with 50 additions and 58 deletions

View file

@ -7,68 +7,49 @@ using namespace std;
//template<typename T> //template<typename T>
class Attribute { class Attribute {
//a named column of a relation vector<string> values;
string name; string name;
bool isKey; string type;
bool key;
int size; int size;
public: public:
Attribute(string n, string t, bool k){
vector<string> values;
void initializeAttribute(string n, vector<string> a){
name = n; name = n;
values = a; type = t;
key = k;
size = 0;
} }
string getName(){ void addRow(string v) {
return name; values.push_back(v);
} }
Attribute(){ } vector<string> getValues() { return values; }
string getName(){ return name; }
string getType(){ return type; }
bool isKey(){ return key; }
int getSize(){ return size; }
void display() void display()
{ {
//cout<<"\nAtribute name:\t"<<name<<"\n"; cout<<"Attribute name:\t"<< name <<"\n";
//cout<<"Elements: "; cout<<"Elements: ";
for (int i = 0; i < values.size(); ++i) for (int i = 0; i < values.size(); ++i)
{ {
cout<<values[i]<<" "; cout<<values[i]<<" ";
} }
} }
int getSize() void Attribute(string n, vector<string> a){
{
return values.size();
}
void pushBack(string s) name = n;
{ values = a;
values.push_back(s);
} }
void erase(int position) void erase(int position)
{ {
values.erase(values.begin()+ position); values.erase(values.begin()+ position);
} }
/*
Attribute(vector<string> v){
this.values = v;
}
Attribute(const Attribute<string>& a){
this.values = a.getAll();
}
Attribute& operator=(const Attribute<string>& a){
this.values = a.getAll();
}
vector<string> getAll(){
return this.values;
}
*/
}; };

View file

@ -4,17 +4,12 @@
//Functional //Functional
class Relation { class Relation {
//a table with rows and columns string name; //The title the user gives it
string name; //the name of the relation (table) vector<Attribute> att; //A vector of the columns
vector<Attribute> att; itn size;
vector<string> attributeNames;
int size;
public: public:
//Relation(); Relation(string n, vector<Attribute> a) {
void initializeRelation(string n, vector<string> attNames, vector<Attribute> a) {
attributeNames = attNames;
name = n; name = n;
att = a; att = a;
size = 0; size = 0;
@ -23,13 +18,15 @@ public:
int getSize() { return size; } int getSize() { return size; }
void addTuple(vector<string> tuple) { void addTuple(vector<string> tuple) {
if(tuple.size() != att.size()){
cout << "\n ERROR" << endl;
}
else {
//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++) {
att[i].pushBack(tuple[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++;
} }
} }
} }
@ -50,6 +47,20 @@ public:
} }
} }
int getSize() { return size; }
string getTableName() {
return name;
}
void displayTableName() {
cout << "The table name is: " << name << endl;
}
vector<Attribute> getAttributes() {
return att;
}
void projectQuery(string input) { void projectQuery(string input) {
cout << "-----------Initiated Query Projection---------" << endl; cout << "-----------Initiated Query Projection---------" << endl;
for(int i = 0; i < att.size(); i++) { for(int i = 0; i < att.size(); i++) {