This repository has been archived on 2025-04-11. You can view files and clone it, but cannot push or open issues or pull requests.
dmspine64backup/Relation.h
2015-09-15 21:49:49 -05:00

85 lines
1.6 KiB
C++
Executable file

#include <iostream>
#include <vector>
#include "Attribute.h"
//Functional
class Relation {
//a table with rows and columns
string name; //the name of the relation (table)
vector<Attribute> att;
vector<string> attributeNames;
public:
//Relation();
void initializeRelation(string n, vector<string> attNames, vector<Attribute> a)
{
attributeNames = attNames;
name = n;
att = a;
}
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++) {
att[i].pushBack(tuple[i]);
}
}
}
void removeTuple(int tupleNum)
{
if (tupleNum > att[0].getSize() || tupleNum < 0)
{
cout<<"ERROR! index out of bound"<<endl;
}
else
{
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();
}
}
};