Update Relation.h
This commit is contained in:
parent
8dc821422b
commit
3a18ac0608
1 changed files with 55 additions and 30 deletions
87
Relation.h
87
Relation.h
|
@ -4,57 +4,82 @@
|
|||
|
||||
//Functional
|
||||
class Relation {
|
||||
string name; //The title the user gives it
|
||||
vector<Attribute> att; //A vector of the columns
|
||||
//a table with rows and columns
|
||||
string name; //the name of the relation (table)
|
||||
vector<Attribute> att;
|
||||
vector<string> attributeNames;
|
||||
|
||||
public:
|
||||
Relation();
|
||||
//Relation();
|
||||
|
||||
//constructor
|
||||
Relation(string n, vector<Attribute> a) {
|
||||
void initializeRelation(string n, vector<string> attNames, vector<Attribute> a)
|
||||
{
|
||||
attributeNames = attNames;
|
||||
name = n;
|
||||
att = a;
|
||||
}
|
||||
|
||||
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
|
||||
for(int i = 0; i < att.size(); 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]);
|
||||
att[i].pushBack(tuple[i]);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
string getTableName() {
|
||||
return name;
|
||||
void removeTuple(int tupleNum)
|
||||
{
|
||||
if (tupleNum > att[0].getSize() || tupleNum < 0)
|
||||
{
|
||||
cout<<"ERROR! index out of bound"<<endl;
|
||||
}
|
||||
|
||||
void displayTableName() {
|
||||
cout << "The table name is: " << name << endl;
|
||||
}
|
||||
|
||||
vector<Attribute> getAttributes() {
|
||||
return att;
|
||||
}
|
||||
|
||||
int getSize() {
|
||||
return att.size();
|
||||
}
|
||||
|
||||
void display() {
|
||||
cout<<"\n\nDisplay of relation--------------------------------"<<endl;
|
||||
cout<<"Relation name: "<<name<<endl;
|
||||
for (int i = 0; i < att.size(); ++i)
|
||||
else
|
||||
{
|
||||
|
||||
cout<<"\nAttribute name: "<<att[i].getName()<<": ";
|
||||
for(int i = 0; i < att.size(); ++i) //for all the attributes
|
||||
{
|
||||
att[i].erase(tupleNum);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void projectQuery(string input)
|
||||
{
|
||||
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();
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
};
|
||||
|
|
Reference in a new issue