Update Relation.h
This commit is contained in:
parent
d28e68beb0
commit
66196158fc
1 changed files with 45 additions and 21 deletions
66
Relation.h
66
Relation.h
|
@ -7,41 +7,65 @@ using namespace std;
|
||||||
//NOT DONE
|
//NOT DONE
|
||||||
class Relation {
|
class Relation {
|
||||||
//a table with rows and columns
|
//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;
|
||||||
|
vector<string> attributeNames;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
Relation();
|
//Relation();
|
||||||
|
|
||||||
//constructor
|
void initializeRelation(string n, vector<string> attNames, vector<Attribute> a)
|
||||||
Relation(string n, vector< Attribute > a) {
|
{
|
||||||
|
attributeNames = attNames;
|
||||||
name = n;
|
name = n;
|
||||||
att = a;
|
att = a;
|
||||||
}
|
}
|
||||||
|
|
||||||
void addTuple(vector< string > tuple) {
|
void addTuple(vector< string > tuple) {
|
||||||
|
|
||||||
//Loop through the attribute columns
|
|
||||||
for(int i = 0; i < att.size(); i++) {
|
if(tuple.size() != att.size()){
|
||||||
|
cout << "\n ERROR" << endl;
|
||||||
//Loop through the elements in the i'th column
|
}
|
||||||
for(int j = 0; j < att[i].values.size(); j++){
|
else {
|
||||||
|
//Loop through the attribute columns
|
||||||
//In this column, at this element's spot, assign an element from the tuple vector to this spot
|
for(int i = 0; i < att.size(); i++) {
|
||||||
(att[i].values[j]).assign(tuple[i]);
|
att[i].pushBack(tuple[i]);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void displayTableName() {
|
|
||||||
cout << "The table name is: " << name << endl;
|
|
||||||
}
|
|
||||||
|
|
||||||
vector< Attribute > getAttributes(){
|
void projectQuery(string input)
|
||||||
return att;
|
{
|
||||||
|
cout << "-----------Initiated Query Projection---------" << endl;
|
||||||
|
for(int i = 0; i < att.size(); i++) {
|
||||||
|
if(att[i].getName() == input) {
|
||||||
|
|
||||||
|
cout << "Column Title: " << input << endl;
|
||||||
|
for(int j = 0; j < att[i].getSize(); j++) {
|
||||||
|
cout << att[i].values[j] << endl;
|
||||||
|
}
|
||||||
|
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
cout << "Attribute input not valid" << endl;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void display()
|
||||||
|
{
|
||||||
|
cout<<"\n\nDisplay of relation--------------------------------"<<endl;
|
||||||
|
cout<<"Relation name: "<<name<<endl;
|
||||||
|
for (int i = 0; i < attributeNames.size(); ++i)
|
||||||
|
{
|
||||||
|
|
||||||
|
cout<<"\nAttribute name: "<<attributeNames[i]<<": ";
|
||||||
|
|
||||||
|
att[i].display();
|
||||||
|
|
||||||
int getSize() {
|
}
|
||||||
return att.size();
|
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
Reference in a new issue