merged with brandon
This commit is contained in:
commit
903b6c98d5
4 changed files with 132 additions and 57 deletions
84
Attribute.h
84
Attribute.h
|
@ -1,37 +1,47 @@
|
||||||
#include <iostream>
|
#include <iostream>
|
||||||
#include <vector>
|
#include <vector>
|
||||||
|
|
||||||
using namespace std;
|
using namespace std;
|
||||||
|
|
||||||
//Funtional, might need more functionality
|
//Funtional, might need more functionality
|
||||||
|
|
||||||
template<typename T>
|
//template<typename T>
|
||||||
class Attribute {
|
class Attribute {
|
||||||
//a named column of a relation
|
//a named column of a relation
|
||||||
string name;
|
string name;
|
||||||
vector<T> values;
|
|
||||||
bool isKey;
|
bool isKey;
|
||||||
int size;
|
int size;
|
||||||
public:
|
|
||||||
Attribute(){ }
|
public:
|
||||||
|
|
||||||
Attribute(vector<T> v){
|
vector<string> values;
|
||||||
this.values = v;
|
|
||||||
}
|
void initializeAttribute(string n, vector<string> a){
|
||||||
|
|
||||||
Attribute(const Attribute<T>& a){
|
name = n;
|
||||||
this.values = a.getAll();
|
values = a;
|
||||||
}
|
}
|
||||||
|
|
||||||
Attribute& operator=(const Attribute<T>& a){
|
string getName(){
|
||||||
this.values = a.getAll();
|
return name;
|
||||||
}
|
}
|
||||||
|
|
||||||
string getName(){
|
Attribute(){ }
|
||||||
return name;
|
|
||||||
}
|
void display()
|
||||||
|
{
|
||||||
vector<T> getAll(){
|
cout<<"Atribute name:\t"<<name<<"\n";
|
||||||
return this.values;
|
cout<<"Elements: ";
|
||||||
}
|
for (int i = 0; i < values.size(); ++i)
|
||||||
};
|
{
|
||||||
|
cout<<values[i]<<" ";
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
vector<string> getElements(){
|
||||||
|
return values;
|
||||||
|
}
|
||||||
|
*/
|
||||||
|
};
|
||||||
|
|
|
@ -4,7 +4,7 @@
|
||||||
#include "Relation.h"
|
#include "Relation.h"
|
||||||
|
|
||||||
using namespace std;
|
using namespace std;
|
||||||
|
|
||||||
class DBEngine {
|
class DBEngine {
|
||||||
//member variables
|
//member variables
|
||||||
//NOT DONE
|
//NOT DONE
|
||||||
|
|
63
Relation.h
63
Relation.h
|
@ -1,16 +1,47 @@
|
||||||
#include <iostream>
|
#include <iostream>
|
||||||
#include <vector>
|
#include <vector>
|
||||||
#include "Attribute.h"
|
#include "Attribute.h"
|
||||||
|
|
||||||
using namespace std;
|
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;
|
string name; //The title the user gives it
|
||||||
vector< Attribute<T> > att;
|
vector< Attribute > att; //A vector of the columns
|
||||||
public:
|
|
||||||
Relation();
|
public:
|
||||||
Relation(vector< Attribute<T> > a) { att = a; }
|
Relation();
|
||||||
void addTuple(vector< Attribute<T> > tuple);
|
|
||||||
};
|
//constructor
|
||||||
|
Relation(string n, vector< Attribute > a) {
|
||||||
|
name = n;
|
||||||
|
att = a;
|
||||||
|
}
|
||||||
|
|
||||||
|
void addTuple(vector< string > tuple) {
|
||||||
|
|
||||||
|
//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].values[j]).assign(tuple[i]);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void displayTableName() {
|
||||||
|
cout << "The table name is: " << name << endl;
|
||||||
|
}
|
||||||
|
|
||||||
|
vector< Attribute > getAttributes(){
|
||||||
|
return att;
|
||||||
|
}
|
||||||
|
|
||||||
|
int getSize() {
|
||||||
|
return att.size();
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
40
test.cpp
40
test.cpp
|
@ -1,10 +1,44 @@
|
||||||
#include <iostream>
|
#include <iostream>
|
||||||
#include "DBEngine.h"
|
//#include "DBEngine.h"
|
||||||
|
#include <vector>
|
||||||
|
#include "Attribute.h"
|
||||||
|
|
||||||
using namespace std;
|
using namespace std;
|
||||||
|
|
||||||
int main() {
|
int main() {
|
||||||
|
|
||||||
|
/*
|
||||||
DBEngine engine;
|
DBEngine engine;
|
||||||
Relation r;
|
Relation r;
|
||||||
Attribute<int> a;
|
Attribute<int> a;
|
||||||
|
*/
|
||||||
|
|
||||||
|
vector<string> shamWow;
|
||||||
|
shamWow.push_back("rag");
|
||||||
|
shamWow.push_back("sponge");
|
||||||
|
shamWow.push_back("wooow");
|
||||||
|
shamWow.push_back("cloth");
|
||||||
|
|
||||||
|
Attribute atributo;
|
||||||
|
atributo.initializeAttribute("atributo",shamWow);
|
||||||
|
atributo.display();
|
||||||
|
|
||||||
|
vector<string> doom;
|
||||||
|
doom.push_back("zombieman");
|
||||||
|
doom.push_back("revenant");
|
||||||
|
doom.push_back("imp");
|
||||||
|
doom.push_back("archvile");
|
||||||
|
|
||||||
|
Attribute atributo2;
|
||||||
|
atributo2.initializeAttribute("attribute_2", doom);
|
||||||
|
atributo2.display();
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
string line1 = "Table_1";
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
//Relation r(line1, my_attributes);
|
||||||
}
|
}
|
||||||
|
|
Reference in a new issue