-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdonut.cpp
More file actions
49 lines (39 loc) · 1.35 KB
/
Copy pathdonut.cpp
File metadata and controls
49 lines (39 loc) · 1.35 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
#include "donut.h"
Donut::Donut(std::string name, double price, double cost, Frosting frosting, bool sprinkles, Filling filling)
: Product{name, price, cost}, _frosting{frosting}, _sprinkles{sprinkles}, _filling{filling} { }
Donut::Donut(std::istream& ist): Product{ist} {
int temp;
ist >> temp; ist.ignore();
if(temp ==1) _sprinkles = true;
else _sprinkles = false;
ist >> temp; ist.ignore();
_frosting = (Frosting)temp;
ist >> temp; ist.ignore();
_filling = (Filling)temp;
}
void Donut::save(std::ostream& ost) {
ost << "(DONUT)"<< std::endl;
ost << _name << std::endl;
ost << _price << std::endl;
ost << _cost << std::endl;
ost << _sprinkles << std::endl;
ost <<(int) _frosting << std::endl;
ost << (int)_filling << std::endl;
}
std::string Donut::to_string() {
std::string result = Product::to_string();
std::string separator = " (";
std::string terminator = "";
if (_frosting != Unfrosted) {
result += separator + "frosted with " + frosting_to_string[_frosting];
if (_sprinkles) result += " and sprinkles";
separator = ", ";
terminator = ")";
}
if (_filling != Unfilled) {
result += separator + "filled with " + filling_to_string[_filling];
terminator = ")";
}
result += terminator;
return result;
}