How do I know if the classes in my program are being used?

In this program the intention is to create a menu driven program for a pizza restaurant. I have to use a class called Pizza and have to include at least three public functions; one is called SetSize, another one is called Display, and the last one is called ComputePrice. A small pizza is worth $10, a medium is $14, and a large is $17. Each topping is worth 2 dollars. I know that the program runs correctly, but I have doubts over the classes and function actually being utilized correctly or at all.

Program:

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
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
#include <iostream>
#include <iomanip>
#include <cmath>
using namespace std;

class Pizza
{
	private:

			int size;
			int style;
			int quantity;
			int toppings;
			int initialcost;
	public:

			void setsize(int, int, int, int, int);
			void computePrice(int, int, int, int, double, double);
			void outputDescription(int, int, int, int, double, double);

};

void Pizza::setsize(int sz, int stl, int tppngs, int qty, int icost)
{
	size = sz;
	style = stl;
	toppings = tppngs;
	quantity = qty;
	initialcost = icost;
}

void Pizza::computePrice(int sz, int stl, int tppngs, int qty, double icost, double total)
{

	total = (icost + (tppngs*2)) * qty;
	cout<<total<<endl;

};

void Pizza::outputDescription(int s, int stl, int tppngs, int qty, double icost, double total)
{
	cout<<"The total is of: $";
	computePrice(s,stl,tppngs,qty,icost,total);
	cout<<endl;
}

int main()
{

	Pizza pizzapie;


	int sz = 0, stl = 0, tppngs = 0, qty = 0, toppingc = 0, toppingp = 0;
	double total = 0, icost = 0;
	cout<<fixed<<showpoint<<setprecision(2);

		cout<<setw(13)<<"SIZES"<<endl<<endl;		
		cout<<"1: Small Pizza"<<endl;
		cout<<"2: Medium Pizza"<<endl;
		cout<<"3: Large Pizza"<<endl;
		cout<<"4: To Finish Order"<<endl<<endl;
		cout<<"Enter your choice: ";

		cin>>sz;
		cout<<endl;

		switch (sz)
		{
				case 1:
					cout<<setw(13)<<"STYLES"<<endl<<endl;	
					cout<<"1: Handtossed Pizza"<<endl;
					cout<<"2: Deepdish  Pizza"<<endl;
					cout<<"3: Pan Pizza"<<endl<<endl;
					cout<<"Enter the style of pizza you want: ";
					cin>>stl;
					cout<<endl;
					icost = 10;
						switch (stl)
						{
							case 1:
									cout<<"Enter how many cheese toppings you want: ";
									cin>>toppingc;
									cout<<"Enter how many pepperoni toppings you want: ";
									cin>>toppingp;
									cout<<endl;

									tppngs = toppingc + toppingp;
									
									cout<<"How many pizzas of this kind do you want?: ";
									cin>>qty;
									
									cout<<endl;
									pizzapie.setsize(sz,stl,tppngs,qty,icost);
								break;
							case 2:
									cout<<"Enter how many cheese toppings you want: ";
									cin>>toppingc;
									cout<<"Enter how many pepperoni toppings you want: ";
									cin>>toppingp;
									cout<<endl;

									tppngs = toppingc + toppingp;
									
									cout<<"How many pizzas of this kind do you want?: ";
									cin>>qty;
									
									cout<<endl;
									pizzapie.setsize(sz,stl,tppngs,qty,icost);
								break;
							case 3:
									cout<<"Enter how many cheese toppings you want: ";
									cin>>toppingc;
									cout<<"Enter how many pepperoni toppings you want: ";
									cin>>toppingp;
									cout<<endl;
									
									tppngs = toppingc + toppingp;
									
									cout<<"How many pizzas of this kind do you want?: ";
									cin>>qty;
									
									cout<<endl;
									pizzapie.setsize(sz,stl,tppngs,qty,icost);
								break;
						}

				break;

			case 2:
					cout<<setw(13)<<"STYLES"<<endl<<endl;	
					cout<<"1: Handtossed Pizza"<<endl;
					cout<<"2: Deepdish  Pizza"<<endl;
					cout<<"3: Pan Pizza"<<endl<<endl;
					cout<<"Enter the style of pizza you want: ";
					cin>>stl;
					cout<<endl;
					icost = 14;
						switch (stl)
						{
							case 1:
									cout<<"Enter how many cheese toppings you want: ";
									cin>>toppingc;
									cout<<"Enter how many pepperoni toppings you want: ";
									cin>>toppingp;
									cout<<endl;
									
									tppngs = toppingc + toppingp;
									
									cout<<"How many pizzas of this kind do you want?: ";
									cin>>qty;
									
									cout<<endl;
									pizzapie.setsize(sz,stl,tppngs,qty,icost);
								break;
							case 2:
									cout<<"Enter how many cheese toppings you want: ";
									cin>>toppingc;
									cout<<"Enter how many pepperoni toppings you want: ";
									cin>>toppingp;
									cout<<endl;
									
									tppngs = toppingc + toppingp;
									
									cout<<"How many pizzas of this kind do you want?: ";
									cin>>qty;
									
									cout<<endl;
									pizzapie.setsize(sz,stl,tppngs,qty,icost);
								break;
							case 3:
									cout<<"Enter how many cheese toppings you want: ";
									cin>>toppingc;
									cout<<"Enter how many pepperoni toppings you want: ";
									cin>>toppingp;
									cout<<endl;
									
									tppngs = toppingc + toppingp;
									
									cout<<"How many pizzas of this kind do you want?: ";
									cin>>qty;
									
									cout<<endl;
									pizzapie.setsize(sz,stl,tppngs,qty,icost);
								break;
						}
				break;

			case 3:
					cout<<setw(13)<<"STYLES"<<endl<<endl;	
					cout<<"1: Handtossed Pizza"<<endl;
					cout<<"2: Deepdish  Pizza"<<endl;
					cout<<"3: Pan Pizza"<<endl<<endl;
					cout<<"Enter the style of pizza you want: ";
					cin>>stl;
					cout<<endl;
					icost = 17;
						switch (stl)
						{
							case 1:
									cout<<"Enter how many cheese toppings you want: ";
									cin>>toppingc;
									cout<<"Enter how many pepperoni toppings you want: ";
									cin>>toppingp;
									cout<<endl;

									tppngs = toppingc + toppingp;
									
									cout<<"How many pizzas of this kind do you want?: ";
									cin>>qty;
									
									cout<<endl;
									pizzapie.setsize(sz,stl,tppngs,qty,icost);
								break;
							case 2:
									cout<<"Enter how many cheese toppings you want: ";
									cin>>toppingc;
									cout<<"Enter how many pepperoni toppings you want: ";
									cin>>toppingp;
									cout<<endl;
									
									tppngs = toppingc + toppingp;
									
									cout<<"How many pizzas of this kind do you want?: ";
									cin>>qty;
									pizzapie.setsize(sz,stl,tppngs,qty,icost);
									
									cout<<endl;
								break;
							case 3:
									cout<<"Enter how many cheese toppings you want: ";
									cin>>toppingc;
									cout<<"Enter how many pepperoni toppings you want: ";
									cin>>toppingp;
									cout<<endl;
									
									tppngs = toppingc + toppingp;
									
									cout<<"How many pizzas of this kind do you want?: ";
									cin>>qty;
									pizzapie.setsize(sz,stl,tppngs,qty,icost);
									cout<<endl;
								break;
						}

			case 4:
				break;
		}
		
		pizzapie.outputDescription(sz,stl,tppngs,qty,icost,total);


	system("pause");
}
Last edited on
Try to use of source code tag for your code. This way it will be readable easily and you can get answers with a higher probability :-)
Last edited on
Line 28: Pizza::computePrice Why are you passing in all these arguments? You already called setsize which stored the value into your Pizzsa object. Why not use the values you've stored? Also, why are you passing total in as an argument. It should be a local variable.

Line 33: Pizza::outputDescription same comments.

Line 39: main() You have lots and lot of repeated code. Any time you have repeated code, that is a good indication the code belongs in a function.

Line 66: Nested switch statements are ugly and very prone to error. Much better to isolate nested switch statements to their own function.

PLEASE USE CODE TAGS (the <> formatting button) when posting code.
It makes it easier to read your code and also easier to respond to your post.
http://www.cplusplus.com/articles/jEywvCM9/
Hint: You can edit your post, highlight your code and press the <> formatting button.

I used those functions to access the private members of the class. Then I passed the arguments so that they can be transferred to the private members. And the Display function is in case I would need a receipt; I just need to put ofstream to create a text file.
I used those functions to access the private members of the class.


No, you're not. setsize() transfers arguments to the private members. That fine. Once you've set the private members, there is no reason to pass them again as arguments to computePrice() and OutputDescription.

computePrice() and outputDescription() are members of your class and should be using the private members of the class, NOT a long list of arguments. Those functions are using the arguments passed, not the private members of the class. If you going to pass all those arguments to those two functions, why did you make them members of your class?

Last edited on
So is the class not being used at all?
You're calling functions that are members of your class, but those functions are NOT using the variables that are part of your class. Defeats the purpose of creating variables in your class.
For things like computePrice(), you should have it return the value of the pizza's price. You have an understanding of "set functions" try looking up get functions.
Cool thanks man, I'll definitely look into get functions.
Topic archived. No new replies allowed.