-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathdatabasebuilder.h
More file actions
96 lines (90 loc) · 2.91 KB
/
databasebuilder.h
File metadata and controls
96 lines (90 loc) · 2.91 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
#ifndef DATABASEBUILDER_H
#define DATABASEBUILDER_H
#include <iostream>
#include <string>
#include <fstream>
#include <vector>
#include <sstream>
using namespace std;
#include "Pet.h"
#include "Cat.h"
#include "Dog.h"
#include "Fish.h"
#include "Bird.h"
#include "PetDatabase.h"
#include "PetDatabaseSortableByName.h"
#include "builder.h"
#include "BubbleSortIncreasing.h"
class DatabaseBuilder: public Builder {
protected:
vector<Pet*> petVector;
public:
virtual void addBird(string traits){
istringstream ss(traits);
string token = "";
vector<string> segments;
while (getline(ss,token,',')){
segments.push_back(token);
}
std::string modifier = "Diurnal ";
bool special = false;
if (segments[5]=="true"){
modifier = "Nocturnal ";
special = true;
}
double price = stod(segments[4]);
unsigned int weight = stoi(segments[3]);
Bird* birdPet = new Bird(segments[1],(modifier + segments[2]),price,weight,special);
petVector.push_back(birdPet);
}
virtual void addCat(string traits){
istringstream ss(traits);
string token = "";
vector<string> segments;
while (getline(ss,token,',')){
segments.push_back(token);
}
std::string modifier = "";
bool special = false;
if (segments[5]=="true"){
modifier = "Fluffy ";
special = true;
}
double price = stod(segments[4]);
unsigned int weight = stoi(segments[3]);
Cat* catPet = new Cat(segments[1],(modifier + segments[2]),price,weight,special);
petVector.push_back(catPet);
}
virtual void addDog(string traits){
istringstream ss(traits);
string token = "";
vector<string> segments;
while (getline(ss,token,',')){
segments.push_back(token);
}
double price = stod(segments[4]);
unsigned int weight = stoi(segments[3]);
Dog* dogPet = new Dog(segments[1],segments[2],price,weight,segments[5]);
petVector.push_back(dogPet);
}
virtual void addFish(string traits){
istringstream ss(traits);
string token = "";
vector<string> segments;
while (getline(ss,token,',')){
segments.push_back(token);
}
std::string modifier = (segments[5] + " ");
double price = stod(segments[4]);
unsigned int weight = stoi(segments[3]);
Fish* fishPet = new Fish(segments[1],(modifier + segments[2]),price,weight,segments[5]);
petVector.push_back(fishPet);
}
virtual PetDatabaseSortableByName* getDatabase(){
PetDatabaseSortableByName* petDatabaseSortableByName = new PetDatabaseSortableByName(petVector);
BubbleSortIncreasing bs;
bs.sort(petDatabaseSortableByName);
return petDatabaseSortableByName;
}
};
#endif // DATABASEBUILDER_H