Hi all, I'm working on this homework problem but am having trouble with the way I make reference.
For instance, I get an error " error C4430: missing type specifier - int assumed. Note: C++ does not support default-int" for line 51,
Pizzatype Pizza::getType()
I'm guessing the way I defined Pizzatype as int is wrong. Could someone point out how to fix the problem?
I'm having so much troubles with compiling the codes, that is over 40+ errors
If anyone could run it and help me with the errors would very much appreciated.
For reference, this is the homework problem:
Define a class called Pizza that has member variables to track the type of pizza (either deep dish, hand tossed, or pan) along with the size (either small, medium, or large) and the number of pepperoni or cheese toppings (up to 4 toppings). You can use constants to represent the type and size. Include mutator and accessor functions for your class.
Create a void function, outputDescription ( ), that output a textual description of the pizza object.
Include a function, computePrice ( ), that computes the cost of the pizza and returns it as a double according to the following rules:
Small pizza = $10 + $2 per topping
Medium pizza = $14 + $2 per topping
Large pizza = $17 + $2 per topping
Write a suitable test program that creates and outputs a description and price of various pizza objects ordered by the user. Here prompt the user to select a type and size for his pizza as well as the number of toppings and then will print out the description and price of the pizza.
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
|
#include<iostream>
#include <string>
using namespace std;
// Class prototype
class Pizza
{
public:
// default constructor
Pizza();
// enumeration declaration
enum Pizzatype {
Deepdish = 1,
Handtossed = 2,
Pan = 3
};
void setType(int type_num);
Pizzatype getType();
enum Pizzasize {
Small = 4,
Medium = 5,
Large = 6
};
void setSize(int size_num);
Pizzasize getSize();
// mutators and accessors
void getPepperoni(bool Pepp);
void getCheese(bool Che);
bool setPepperoni(int pepperonitoppings);
bool setCheese(int cheesetoppings);
void outputDescription();
double computePrice();
private:
Pizzatype type;
Pizzasize size;
bool Pepperoni;
bool Cheese;
};
Pizza::Pizza()
{
Pizzatype type = Deepdish;
Pizzasize size = Small;
Pepperoni = Cheese = 0;
}
Pizzatype Pizza::getType()
{
return type;
}
Pizzasize Pizza::getSize()
{
return size
}
void Pizza::setType(int type_num)
{
int error = 0.0;
if (type_num != 1 || type_num!= 2 || type_num!= 3)
return error;
else
return type = type_num;
}
void Pizza::setSize(int size_num)
{
int error = 0.0;
error = "undefined";
if (size_num != 4 || size_num != 5 || size_num != 6)
return error;
else
return size = size_num;
}
void Pizza::getPepperoni(bool Pepp)
{
Pepperoni = Pepp
}
void Pizza::getCheese(bool Che)
{
Cheese = Che
}
bool Pizza::setPepperoni(int pepperonitoppings)
{
if (pepperonitoppings < 0 )
// don't allow negative Pepperoni toppings
return false;
else
{
Pepperoni = Pepperonitoppings
return true;
}
bool Pizza::setCheese(int cheesetoppings)
{
if (cheesetoppings < 0 )
// don't allow negative Cheese toppings
return false;
else
{
Cheese = cheesetoppings
return true;
}
}
void Pizza::outputDescriptionDesciption()
{
switch (type) {
case 1 :
cout << "Deep dish ";
break;
case 2 :
cout << "Hand tossed ";
break;
case 3 :
cout << "Pan ";
break;
}
switch (size) {
case 4 :
cout << "Small ";
break;
case 5 :
cout << "Medium ";
break;
case 6 :
cout << "Large ";
break;
}
cout << "pizza with " << Pepperoni << "pepperoni and "
<< Cheese << "cheese toppings.";
}
double Pizza::computePrice()
{
double cost
//Initialize variable
cost = 0.0;
switch (size) {
case 4 :
cost += 10;
break;
case 5 :
cost += 14;
break;
case 6 :
cost += 17;
break;
}
if (pepperonitoppings)
cost += 2.0
if (cheesetoppings)
cost += 2.0)
return cost;
}
int main()
{
// Declare variables
char pepptoppings, chetoppings, temp;
int type, size, qType, qSize;
// Type question for ordering
cout << "What pizza type would you like? Please enter type numer; Deepdish(1) / Hand-tossed(2) / Pan (3): ";
cin >> qType;
switch(qType){
case 1:
type = Deepdish;
break;
case 2:
type = Handtossed;
break;
case 3:
type = Pan;
break;
}
// Size question for ordering
cout << "What pizza size would you like? Please enter size number; Small(4) / Medium (5) / Large (6): ";
cin >> qSize;
switch(qSize){
case 4:
size = SMALL;
break;
case 5:
size = MEDIUM;
break;
case 6:
size = LARGE;
break;
}
// Default pizza
Pizza Italy;
Italy.setType(type);
Italy.setSize(size);
// Pepperoni toppings
cout << "Would you like add pepperoni toppings (y/n)? ";
cin >> pepptoppings;
if (topping == 'Y' || topping == 'y')
Italy.getPepperoni(true);
cout << "Would you like cheese topping (y/n)? ";
cin >> chetoppings;
if (topping == 'Y' || topping == 'y')
Italy.getCheese(true);
// Description of the final order
cout << "Order description: ";
Italy.outputDescription();
cout << endl;
// Cost
cout << "Total: $" << myPizza.computePrice() << endl;
system("pause");
return 0;
}
|