/
main.cpp
44 lines (40 loc) · 1.3 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
#include <iostream>
#include <vector>
#include "trip.h"
int main()
{
Trip t(
"Rom",
6 /* days */,
350 /* euros */
);
// call getter-functions
std::cout << "Reise nach " << t.get_destination() << " kostet " << t.get_price() << "€\n";
/*
* Attributes of Trip are private, not visible to us.
* The next line produces the following error
*
* main.cpp:26:7: error: 'price' is a private member of 'Trip'
* t.price = 1;
* ^
* ./trip.h:17:18: note: declared private here
* unsigned int price;
* ^
*/
t.price = 1;
/*
* Attributes of Rating are public, we can read them directly
* They are however constant, meaning they can't be reassigned
* The following error will be produced
*
* main.cpp:42:15: error: cannot assign to non-static data member 'quality' with const-qualified type 'const double'
* r.quality = 5;
* ~~~~~~~~~ ^
* ./rating.h:14:18: note: non-static data member 'quality' declared const here
* const double quality;
* ~~~~~~~~~~~~~^~~~~~~
*/
Rating r = Rating::input_rating();
std::cout << "Average rating is " << ((r.quality + r.pricing + r.cleanliness + r.accomodation) / 4) << "\n";
r.quality = 5;
}