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 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289
|
#include <iostream>
#include <string>
using namespace std;
class Order{
private:
int quantity, numToppings;
char size;
double cost, totalCost;
bool pepperoni, sausage, onion;
long creditcardNumber, phoneNumber;
string customerName;
public:
Order();
Order(long creditcard, long phone);
double updateCost();
void setCustomerName(string name);
void promptSize();
void promptPepperoni();
void promptSausage();
void promptOnion();
void promptAddPizza();
void promptCreditCard(long card);
void displayPizza();
void setCreditCard(long card);
void setPhone(long phone);
void resetOrder();
void reviewOrder();
string getcustomerName();
long getCreditCard();
long getPhone();
};
Order::Order(){
quantity = 0;
totalCost = 0;
numToppings = 0;
customerName = "John Doe";
}
Order::Order(long creditcard, long phone){
creditcardNumber = creditcard;
phoneNumber = phone;
}
void Order::setCustomerName(string name){
customerName = name;
}
void Order::promptSize(){ // asks user to input size.
cout << "Choose your pizza size." << endl;
cout << "Enter 'S' for small (12in)." << endl;
cout << "Enter 'M' for medium (14in)." << endl;
cout << "Enter 'L' for large (16in)." << endl;
cout << "Enter 'X' for extra large (18in)." << endl;
cin >> size;
promptPepperoni(); // begining of toppings loop
}
void Order::promptPepperoni(){
string yN;
cout << "would you like to add pepperoni to your pizza?" << endl;
cin >> yN;
pepperoni = false; //indicates no topping, useful for adding another pizza so boolean values don't
if(yN == "Yes"){ // carry over
pepperoni = true;
numToppings = numToppings + 1;
}
else if(yN == "yes"){
pepperoni = true; //variety of input will add pepperoni as a topping
numToppings = numToppings + 1;
}
else if(yN == "Y"){
pepperoni = true;
numToppings = numToppings + 1;
}
else if(yN == "y"){
pepperoni = true;
numToppings = numToppings + 1;
}
promptSausage(); // moves onto next topping
}
void Order::promptSausage(){
string yN;
cout << "Would you like to add sausage to your pizza?" << endl;
cin >> yN;
sausage = false;
if(yN == "Yes"){ // I want to use if(yN == "Yes" || yN == "yes" || .....) but it doesn't seem to work,
sausage = true; // what's a more efficent way to check the cases?
numToppings = numToppings + 1;
}
else if(yN == "yes"){
sausage = true;
numToppings = numToppings + 1;
}
else if(yN == "Y"){
sausage = true;
numToppings = numToppings + 1;
}
else if(yN == "y"){
sausage = true;
numToppings = numToppings + 1;
}
promptOnion();
}
void Order::promptOnion(){
string yN;
cout << "would you like to add onions to your pizza?" << endl;
cin >> yN;
onion = false;
if(yN == "Yes"){
onion = true;
numToppings = numToppings + 1;
}
else if(yN == "yes"){
onion = true;
numToppings = numToppings + 1;
}
else if(yN == "Y"){
onion = true;
numToppings = numToppings + 1;
}
else if(yN == "y"){
onion = true;
numToppings = numToppings + 1;
}
quantity = quantity + 1; //updates the number of pizzas. mainly for displayPizza function
displayPizza(); // shows the Pizza details
updateCost();
promptAddPizza();
}
void Order::promptAddPizza(){
string addPizza;
cout << "Would you like to add another pizza to your order? " ;
cin >> addPizza;
if(addPizza == "Yes"){ // if any of the conditions are met, the loop starts over at promptSize
promptSize();
}
else if(addPizza == "yes"){
promptSize();
}
else if(addPizza == "Y"){
promptSize();
}
else if(addPizza == "y"){
promptSize();
}
}
void Order::promptCreditCard(long card){ //called if creditcard# is less than 16 digits
cout << "Please re-enter your credit card number: ";
cin >> card;
setCreditCard(card);
}
double Order::updateCost(){
double cost =0; // sets LOCAL variable cost to 0, needs to be reset if more than 1 pizza
double toppingsPerPizza = 0; // same as above
if(size == 'S'){
cost = 10;
}
else if(size == 'M'){
cost = 12;
}
else if(size == 'L'){
cost = 14;
}
else if(size == 'X'){
cost = 16;
}
toppingsPerPizza = numToppings;
cost = cost + (toppingsPerPizza * 2); // $2 per topping, med pizza is 12+(2*2
totalCost = totalCost + cost; //updates total cost by adding cost (subtotal + cost of new pizza)
numToppings = 0;
toppingsPerPizza = 0;
cout << "Your subtotal is $" << totalCost << endl; //displays subtotal after every pizza added
}
void Order::displayPizza(){
string displayPepperoni; //shows topping if topping is set to true
string displaySausage;
string displayOnion;
if(pepperoni == true)
displayPepperoni = "Pepperoni";
else{
displayPepperoni = "";
}
if(sausage == true)
displaySausage = "Sausage";
else{
displaySausage = "";
}
if(onion == true)
displayOnion = "Onion";
else{
displayOnion = "";
}
for(int i=1; i<=quantity; i++){ //calculates number of pizzas to display based on quantity
string toppings;
string _size;
if(size == 'S')
_size = "Small";
else if(size == 'M')
_size = "Medium";// I want this to output the detail for each pizza, currently it creates a list of
else if(size == 'L')// pizzas, but they all have the same details as most recent pizza, how can I modify this
_size = "Large";// to display the size and topping of each pizza? Arrays?
else if(size == 'X')
_size = "Extra Large";
toppings = "Toppings: " + displayPepperoni + " " + displaySausage + " " + displayOnion;
cout << "Pizza #" << i << ":\t" << "Size: " << _size << "\t "<< toppings << endl;
}
}
void Order::setCreditCard(long card){ //receives card from int main
if (card > 1000000000000000){
creditcardNumber = card;
cout << "Thank you" << endl; // checks if card is valid (16 + digits),
}
else {
promptCreditCard(card); // prompts user to re-enter number if invalid
}
}
void Order::setPhone(long phone){
phoneNumber = phone;
}
void Order::resetOrder(){ //resets cost, toppings and quantity
totalCost = 0;
numToppings = 0;
quantity = 0;
}
void Order::reviewOrder(){ //asks users to review information. Proceeds to creditcard if they comply,
string proceed; //otherwise calls function to reset order
cout << "Proceed to checkout?" << endl;
cin >> proceed;
if(proceed == "No"){
cout << "Your Order has been reset. Please re-enter the information." << endl; // same deal here as above,
resetOrder(); // a lot of extra code, but I'm tyring to make it more advanced
promptSize();// entering something case specific.
reviewOrder();
}
else if(proceed == "no"){
cout << "Your Order has been reset. Please re-enter the information." << endl;
resetOrder();
promptSize();
reviewOrder();
}
else if(proceed == "N"){
cout << "Your Order has been reset. Please re-enter the information." << endl;
resetOrder();
promptSize();
reviewOrder();
}
else if(proceed == "n"){
cout << "Your Order has been reset. Please re-enter the information." << endl;
resetOrder();
promptSize();
reviewOrder();
}
}
string Order::getcustomerName(){
return customerName;
}
long Order::getCreditCard(){
return creditcardNumber;
}
long Order::getPhone(){
return phoneNumber;
}
int main(){
string name;
long phone;
long card;
cout << "Please enter your name: ";
getline(cin, name);
Order order1;
order1.setCustomerName(name);
order1.promptSize(); // this function starts a chain for 4 or 5 more functions before proceeding to review order
order1.reviewOrder();
cout << "Please Enter your credit card number: " << endl;
cin >> card;
order1.setCreditCard(card);
cout << "Please Enter your phone number: ";
cin >> phone;
order1.setPhone(phone);
cout << "Name: " << order1.getcustomerName() << endl;
cout << "Credit Card #: " << order1.getCreditCard() << endl;
cout << "Phone: " << order1.getPhone() << endl;
cout << "Thanks for your order " << order1.getcustomerName() << endl;
return 0;
}
|