当前位置:网站首页>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;
}
边栏推荐
- P1363 幻象迷宫(dfs)
- Leetcode 1208. Try to make the strings equal as much as possible (finally solved, good night)
- 【Pytorch】用自动微分求sin(x)的导数
- [Shangshui Shuo series] day three - preview4
- Xiaojinwei, chairman of Chenglian Technology: implement the national strategy of data economy and lead the development of new consumption in the digital era!
- How to use shell script to monitor file changes
- Prince language under insect date category
- P1347 sorting (TOPO)
- Pytoch --- use pytoch's pre training model to realize four weather classification problems
- 2022年起重机械安全管理考试题库及答案
猜你喜欢

What is metadata

Particle animation background login page particles js

svg d3. JS generate tree tree view

LabVIEW displays both hexadecimal and normal characters in the same table

Latest programming language rankings

C语言刷题随记 —— 自由落体的球

Twitter cooperates with Shopify to introduce merchant products into twitter shopping

Inscription of lougu brush

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

X24cxx series EEPROM chip C language universal reading and writing program
随机推荐
JD cloud distributed database stardb won the "stability practice pioneer" of China Academy of information technology
OpenJudge NOI 1.13 50:数根
[deep learning] deep learning reasoning framework tensorrt MNN openvino onnxruntime
Pytoch --- pytoch customizes the dataset
在线JSON转CSharp(C#)Class工具
Avltree - arbre de recherche binaire équilibré
What are the characteristics of SRM supplier management system developed by manufacturing enterprises
Pta:7-85 data spacing (overload + function template)
Twitter cooperates with Shopify to introduce merchant products into twitter shopping
Zhongang Mining: the demand for fluorite in the new energy and new material industry chain has increased greatly
Analysis on the current situation of the Internet of things in 2022
自动化测试常见的面试题
Cool mouse following animation JS plug-ins 5
Sequence table lookup
How to use shell script to monitor file changes
Ms-fsrvp forced abuse of POC
Latest programming language rankings
Prince language under insect date category
【二叉树】二叉树的完全性检验
[从零开始学习FPGA编程-40]:进阶篇 - 设计-竞争与风险Risk或冒险