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
|
finaladt.h
#ifndef FINALADT_H
#define FINALADT_H
#include <iostream>
using namespace std;
template<class Type>
class finalADT
{
public:
finalADT();
int choose_pizza(int pchoice);
int choose_drink(int dchoice);
void show_choices(char cpizza, char cdrink, int pchoice, int dchoice);
void show_receipt(double total);
double calculate(double total,double subTotal, int pchoice, int dchoice);
~finalADT();
};
template<class Type>
int finalADT<Type>::choose_pizza(int pchoice)
{
for(;;)
{
cout << "What pizza would you like? [1-5]: \n";
cin >> pchoice;
if(1 <= pchoice && pchoice <= 5)
{
break;
}
else
{
cout << "Please enter 1 - 5\n";
}
}
return pchoice;
}
template <class Type>
int finalADT<Type>::choose_drink(int dchoice)
{
for(;;)
{
cout << "What drink would you like? [1-5]: \n";
cin >> dchoice;
if(1 <= dchoice && dchoice <= 5)
{
break;
}
else
{
cout << "Please enter 1 - 5\n";
}
}
return dchoice;
}
template<class Type>
void finalADT<Type>::show_choices(char cpizza, char cdrink, int pchoice, int dchoice)
{
cout << "Would you like a pizza? (Y/N): \n";
cin >> cpizza;
switch(cpizza)
{
case 'y':
case 'Y':
pchoice = choose_pizza(pchoice);
break;
case 'n':
case 'N':
break;
default:
cout << "No answer? OK...\n";
}
cout << "Would you like a drink? (Y/N): \n";
cin >> cdrink;
switch(cdrink)
{
case 'y':
case 'Y':
dchoice = choose_drink(dchoice);
break;
case 'n':
case 'N':
break;
default:
cout << "No answer? OK...\n";
}
}
template <class Type>
double finalADT<Type>:: calculate(double total, double subTotal, int pchoice, int dchoice)
{
switch(pchoice)
{
case 1:
subTotal += 3;
break;
case 2:
subTotal += 4;
break;
case 3:
subTotal += 5;
break;
case 4:
subTotal += 7;
break;
case 5:
subTotal += 8.5;
break;
}
switch(dchoice)
{
case 1:
subTotal += .1;
break;
case 2:
subTotal += .11;
break;
case 3:
subTotal += .12;
break;
case 4:
subTotal += .14;
break;
case 5:
subTotal += .15;
break;
}
total = subTotal * .1 + subTotal;
return total;
}
template <class Type>
void finalADT<Type>::show_receipt(double total)
{
cout << "Your total is: $" << total << "\n";
}
#endif // FINALADT_H
|