-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.cpp
95 lines (76 loc) · 1.84 KB
/
main.cpp
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
#include <iostream>
#include <string>
#include <vector>
using namespace std;
class Restaurant {
public:
Restaurant();
Restaurant(string pName, int pRating);
void setName(string restaurantName);
void setRating(int userRating);
string getName();
int getRating();
void print();
private:
string name;
int rating;
};
int main() {
// Automatically calls the default constructor
Restaurant favLunchPlace;
int numRests;
string tempName;
int tempRating;
vector<Restaurant> restVec;
cout << "How many restaurants would you like to enter? ";
cin >> numRests;
restVec.resize(numRests);
cout << endl;
// read in restaurant info into vector
for (int i = 0; i < numRests; i++)
{
cout << "Restaurant " << i << " name: ";
cin >> tempName;
cout << "Restaurant " << i << " rating: ";
cin >> tempRating;
restVec.at(i).setName(tempName);
restVec.at(i).setRating(tempRating);
}
cout << endl;
// display restaurant info from vector
for (int i = 0; i < numRests; i++)
{
cout << "Restaurant " << i << " name: ";
cout << restVec.at(i).getName() << endl;
cout << restVec.at(i).getRating() << endl << endl;
}
return 0;
}
Restaurant::Restaurant() : name("No Name"), rating(-1)
{
name = "No Name";
rating = 1;
}
Restaurant::Restaurant(string pName, int pRating) : name(pName), rating(pRating)
{
setName(pName);
setRating(pRating);
}
void Restaurant::setName(string restaurantName) {
name = restaurantName;
}
void Restaurant::setRating(int userRating) {
rating = userRating;
}
// Prints name and rating on one line
void Restaurant::print() {
cout << name << " -- " << rating << endl;
}
string Restaurant::getName()
{
return name;
}
int Restaurant::getRating()
{
return rating;
}