Está en la página 1de 3

#include <iostream>

#include <iomanip>

using namespace std;

class Tea
{
protected:
int size;
int topping;
double cost;
public:
void setTea(int a, int b)
{
size = a;
topping = b;
}

virtual void calCost() = 0; // pure virtual function


void displayCost()
{
cout << fixed << setprecision(2);
cout << "\nYour total cost is: RM" << cost << "." << endl;
}
};

class TeaOnMenu : public Tea


{
public:
void calCost()
{
cost = size + (2 * topping);
}
};

class CustomizedTea : public Tea


{
public:
void calCost()
{
cost = size + (1.5 * topping);
}
};

#include <iostream>
#include <string>

#define SMALL 5
#define MEDIUM 8
#define LARGE 12

using namespace std;

void main()
{
int choice, mSize, nSize, mTopping;
string teaType, oSize;
cout << "\nWelcome to TeaTime ordering service!" << endl;
do
{
cout << "\nPlease select your cup of tea." << endl;
cout << "1. Tea On Menu" << endl;
cout << "2. Customized Tea" << endl;
cout << "\nInput: ";
cin >> choice;
if (choice != 1 && choice != 2)
{
cout << "\nError: Invalid input. Please try again." << endl;
}
} while (choice != 1 && choice != 2);
do
{
cout << "\nPlease choose the size of your cup:" << endl;
cout << "1. Small" << endl;
cout << "2. Medium" << endl;
cout << "3. Large" << endl;
cout << "\nInput: ";
cin >> mSize;
if (mSize != 1 && mSize != 2 && mSize != 3)
{
cout << "\nError: Invalid input. Please try again." << endl;
}
} while (mSize != 1 && mSize != 2 && mSize != 3);
switch (mSize)
{
case 1:
{
nSize = SMALL;
oSize = "Small";
break;
}
case 2:
{
nSize = MEDIUM;
oSize = "Medium";
break;
}
case 3:
{
nSize = LARGE;
oSize = "Large";
break;
}
default: cout << "Error: Invalid input. Please try again."; break;
}
cout << "\nPlease enter the number of toppings for your cup: [Enter 0 for none]" <<
endl;
cout << "\nInput: ";
cin >> mTopping;
switch (choice)
{
case 1:
{
teaType = "Tea On Menu";
TeaOnMenu tea1;
tea1.setTea(nSize, mTopping);
tea1.calCost();
cout << "Your order details are as follows:-" << endl;
cout << "Tea Type: " << teaType << endl;
cout << "Cup Size: " << oSize << endl;
cout << "Number of Toppings: " << mTopping << endl;
tea1.displayCost();
break;
}
case 2:
{
teaType = "Customized Tea";
CustomizedTea tea2;
tea2.setTea(nSize, mTopping);
tea2.calCost();
cout << "\nYour order details are as follows:-" << endl << endl;
cout << "Tea Type: " << teaType << endl;
cout << "Cup Size: " << oSize << endl;
cout << "Number of Toppings: " << mTopping << endl;
tea2.displayCost();
break;
}
} // End of switch
cout << "\nThank you for using our ordering service. Please come again!" << endl;

cout << endl;


system("pause");
}

También podría gustarte