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>
class Attribute {
//a named column of a relation
vector<string> values;
string name;
bool isKey;
string type;
bool key;
int size;
public:
vector<string> values;
void initializeAttribute(string n, vector<string> a){
Attribute(string n, string t, bool k){
name = n;
values = a;
type = t;
key = k;
size = 0;
}
string getName(){
return name;
void addRow(string v) {
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()
{
//cout<<"\nAtribute name:\t"<<name<<"\n";
//cout<<"Elements: ";
cout<<"Attribute name:\t"<< name <<"\n";
cout<<"Elements: ";
for (int i = 0; i < values.size(); ++i)
{
cout<<values[i]<<" ";
}
}
int getSize()
{
return values.size();
}
void Attribute(string n, vector<string> a){
void pushBack(string s)
{
values.push_back(s);
name = n;
values = a;
}
void erase(int 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
class Relation {
//a table with rows and columns
string name; //the name of the relation (table)
vector<Attribute> att;
vector<string> attributeNames;
int size;
string name; //The title the user gives it
vector<Attribute> att; //A vector of the columns
itn size;
public:
//Relation();
void initializeRelation(string n, vector<string> attNames, vector<Attribute> a) {
attributeNames = attNames;
Relation(string n, vector<Attribute> a) {
name = n;
att = a;
size = 0;
@ -23,13 +18,15 @@ public:
int getSize() { return size; }
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]);
//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]);
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) {
cout << "-----------Initiated Query Projection---------" << endl;
for(int i = 0; i < att.size(); i++) {