-->
当前位置:首页 > 题库

PROGRAMMING:The price of drinks

Luz5年前 (2021-05-10)题库405
A tea bar offers three kinds of drinks: tea, coffee and milk. 50% service charge for local tea and 20% service charge for other teas; 100% service charge for freshly ground coffee and 20% service charge for other coffees; There is no service charge for milk. The service charge is accurate to one decimal point.
The following basic class framework is given
Class Drink
{
protected:
int NO; // number
int amount; // number
float price; // Unit Price
public:
virtual void display()=0;// Export costs
}
Taking drink as the base class, tea, coffee and milk are constructed.
Generate the above class, and write the main function, which requires that the main function has a base class drink pointer array, with no more than 10 elements.
Drink *pd[10];
The main function establishes tea, coffee or milk class objects according to the input information, and gives the charge.
Input format: each test case occupies one line, and each line gives the basic information of beverage. The first one is the type of beverage, tea is 1, coffee is 2, and milk is 3. Next is the application number (100-999), followed by the quantity and unit price. For tea, enter a region code, where 1 represents local. For coffee, the next step is to enter a processing code, where 1 represents the current grinding. The last line is 0.
Require output number and charge (1 decimal place after decimal point).
Hint: using virtual function to realize polymorphism
Input example:
1 106 3 33 1
1 103 2 20 2
3 109 1 15
2 107 2 15.8 1
2 232 3 21 29
0
Output example:
106 148.5
103 48.0
109 15.0
107 63.2
232 75.6






answer:If there is no answer, please comment