-
-
Notifications
You must be signed in to change notification settings - Fork 0
/
CanBabcock.cpp
125 lines (120 loc) · 2.8 KB
/
CanBabcock.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
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
/**********************************
* Name: Basic OO and Encapsulation
* Author: Tanner Babcock
* Created: August 26, 2022
* Course: CIS 152 - Data Structures
* Version: 1.0
* OS: Void GNU/Linux
* Complexity: O(1)
* IDE: Emacs
* Copyright : This is my own original work based
* on specifications issued by our instructor.
* Academic Honesty: I attest that this is my original
* work. I have not used unauthorized source code,
* either modified or unmodified. I have not given
* other fellow student(s) access to my program.
***********************************/
#include <iostream>
#include <string>
using namespace std;
class Can {
private:
string company;
string content;
float size;
float price;
public:
/* constructors */
Can(void) {
company = "Unknown";
content = "Unknown";
size = 1.0;
price = 2.0;
}
Can(string comp) {
company = comp;
content = "Unknown";
size = 1.0;
price = 2.0;
}
Can(string comp, string cont) {
company = comp;
content = cont;
size = 1.0;
price = 2.0;
}
Can(string comp, string cont, float s) {
company = comp;
content = cont;
size = s;
price = 2.0;
}
Can(string comp, string cont, float s, float p) {
company = comp;
content = cont;
size = s;
price = p;
}
/* getters and setters */
void setCompany(string comp) {
company = comp;
}
string getCompany(void) {
return company;
}
void setContent(string cont) {
content = cont;
}
string getContent(void) {
return content;
}
void setSize(float s) {
size = s;
}
float getSize(void) {
return size;
}
void setPrice(float p) {
price = p;
}
float getPrice(void) {
return price;
}
/* mutators */
void doublePrice(void) {
price *= 2;
}
void doubleSize(void) {
size *= 2;
}
void halfPrice(void) {
price /= 2;
}
void halfSize(void) {
size /= 2;
}
/* display function */
void print(void) {
cout << getCompany() << " " << getContent() << endl;
cout << "Size: " << getSize() << " ounces, Price: $" << getPrice() << endl;
}
};
int main(void) {
Can *a = new Can("Field Day", "Black Beans", 13.0, 0.99);
Can *b = new Can("S&W", "Peaches", 12.0, 2.39);
Can *c = new Can("Green Giant", "Green Beans", 11.9, 1.79);
Can *d = new Can("Del Monte", "Creamed Corn", 13.4, 2.49);
cout << "Can 1:" << endl;
a->print();
cout << "Can 2:" << endl;
b->print();
cout << "Can 3:" << endl;
c->print();
cout << "Can 4:" << endl;
d->print();
delete a;
delete b;
delete c;
delete d;
return 0;
}