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

PROGRAMMING:Processing time of beverage

Luz5年前 (2021-05-10)题库415
A tea bar offers three kinds of drinks: tea, coffee and milk. The processing time of local tea is 50 seconds and that of other teas is 20 seconds; Add 120 seconds for freshly ground coffee and 20 seconds for other coffees; Milk for 10 seconds.
The following basic class framework is given
Class Drink
{
protected:
int NO; // number
int amount; // number
public:
virtual void display()=0;// Output delivery time
}
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. 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.
The output number and processing time are required.
Hint: using virtual function to realize polymorphism
Input example:
1 106 3 1
1 103 2 2
3 109 1
2 107 2 1
2 232 3 29
0
sample output
106 150
103 40
109 10
107 240
232 60






answer:If there is no answer, please comment