当前位置:网站首页>PTA: price of 7-65 beverage
PTA: price of 7-65 beverage
2022-06-23 04:38:00 【Sy_ Faker】
A tea bar offers three kinds of drinks : tea 、 Coffee and milk . The local tea should be added 50% Service charge , Other teas should be added 20% Service charge ; Freshly ground coffee needs to be added 100% Service charge , Add other coffee 20% Service charge ; No service charge for milk , The service charge is accurate to one decimal place .
Give the following base class framework :
Class Drink { protected:
int NO; // Number
int amount; // Number
float price; // The unit price
public:
virtual void display()=0;// Output costs
}
With Drink Base class , build Tea, Coffee and Milk Three categories .
Generate the above class , And write the main function , The main function is required to have a base class Drink Pointer array , Array elements do not exceed 10 individual .
Drink *pd[10];
The main function is based on the input information , Corresponding establishment Tea, Coffee or Milk Class object , And give the charge .
Input format : One line per test case , Each line gives basic information about the drink , The first is the type of drink , Cha Wei 1, Coffee is 2, Milk is 3. Next is the number of the application (100-999), Then the quantity and unit price . For tea , Next, enter a region code , among 1 Representing local . For coffee , Next, enter a machining code , among 1 Stands for present grinding . Last act 0. Request output number and charge ( After the decimal point 1 Decimal place ).
Tips : Using virtual function to realize polymorphism
sample input :
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
sample output :
106 148.5
103 48.0
109 15.0
107 63.2
232 75.6
#include<iostream>
using namespace std;
class Drink
{
protected:
int NO; // Number
int amount; // Number
float price; // The unit price
public:
Drink(int n,int a,float p):NO(n),amount(a),price(p){
;}
virtual void display()=0;// Output costs
};
class Tea:public Drink
{
int pd;
public:
Tea(int n,int a,float p,int k):Drink(n,a,p){
pd=k;}
virtual void display()
{
float temp=amount*price;
if(pd==1)temp*=1.5;
else temp*=1.2;
printf("%d %.1f\n",NO,temp);
}
};
class Coffee:public Drink
{
int pd;
public:
Coffee(int n,int a,float p,int k):Drink(n,a,p){
pd=k;}
virtual void display()
{
float temp=amount*price;
if(pd==1)temp*=2;
else temp*=1.2;
printf("%d %.1f\n",NO,temp);
}
};
class Milk:public Drink
{
public:
Milk(int n,int a,float p):Drink(n,a,p){
;}
virtual void display()
{
float temp=amount*price;
printf("%d %.1f\n",NO,temp);
}
};
int main()
{
Drink *pd[10];
int type;
cin>>type;
int n,a,pp,i=0;
float p;
while(type!=0)
{
cin>>n>>a>>p;
switch(type)
{
case 1:
cin>>pp;
pd[i]=new Tea(n,a,p,pp);
break;
case 2:
cin>>pp;
pd[i]=new Coffee(n,a,p,pp);
break;
case 3:
pd[i]=new Milk(n,a,p);
break;
}
pd[i++]->display();
cin>>type;
}
delete *pd;
}
边栏推荐
- OpenJudge NOI 1.13 49:计算对数
- 在线文本过滤小于指定长度工具
- PTA:7-60 宠物的生长
- Pta:6-33 student ranking table (destructor)
- Permission Operation in dynamics 365 plug-in
- 国家药品不良反应监测中心 ADR 电子传输EDI解决方案
- 2022年起重机械安全管理考试题库及答案
- Pytoch --- use pytoch's pre training model to realize four weather classification problems
- LabVIEW displays both hexadecimal and normal characters in the same table
- Twitter cooperates with Shopify to introduce merchant products into twitter shopping
猜你喜欢

语料库数据处理个案实例(分词和分句、词频统计、排序)

抖音x-bogus和_signature参数分析

Basic skills of x64dbg

Leetcode 1208. 尽可能使字符串相等(终于解决,晚安)

应急响应-hw复习

Pytoch --- use pytoch's pre training model to realize four weather classification problems

x64dbg 基本使用技巧

Mobile terminal city list sorting JS plug-in vertitylist js

Please use the NLTK Downloader to obtain the resource

If you want to understand PostgreSQL, you must first brush the architecture
随机推荐
After Huawei online battle service players quickly match, different players receive different lists of players in the same room
How to make the page number start from the specified page in word
TS进阶之infer
PTA:7-58 图书音像出租管理
Monitoring artifact ZABBIX, from deployment to application, goes deep layer by layer
【多模态】UNIMO
Permission Operation in dynamics 365 plug-in
Basic skills of x64dbg
顺序表查找
[Shangshui Shuo series] day three - preview4
2022年烷基化工艺考题及模拟考试
Pytoch --- pytoch customizes the dataset
What are the characteristics of SRM supplier management system developed by manufacturing enterprises
Dynamics 365 插件中权限操作
Pytorch---使用Pytorch的预训练模型实现四种天气分类问题
PTA: spacing of 7-69 data
Software development in 2022: five realities CIOs should know
深度学习 TensorFlow入门
x64dbg 基本使用技巧
[acnoi2022] no way without guessing