#include<bits/stdc++.h>
using namespace std;
class tank
{
private:
int F;
int vin;
int vout;
int gravity;
public:
tank():F(0),vin(0),vout(0),gravity(0){ }
~tank(){
};
void set(int f,int in,int out)
{
F=f;
vin=in;
vout=out;
}
int getin(int t0,int te)
{
gravity+=(te-t0)*vin;
return gravity;
}
int getout(int t0,int te)
{
gravity-=(te-t0)*vout;
if(gravity<=0)
{
gravity=0;
}
return gravity;
}
int getresult()
{
if(gravity<F)
{
return gravity;
}
else
{
return F;
}
}
};
int main()
{
tank t1;
t1.set(10000,200,160);
tank t2;
t2.set(5000,150,100);
tank t3;
t3.set(5000,100,120);
t1.getin(0,30);
t2.getin(20,50);
t3.getin(40,50);
t3.getout(60,70);
t1.getout(60,80);
int res=t1.getresult()+t2.getresult()+t3.getresult();
cout<<res;
return 0;
}
假设某水果店销售
4
种水果:苹果
A
(每个重量
0.1kg
,
10
元
/kg
)、梨
B
(每个重量
0.1kg
,
12
元
/kg
)、桃
C
(每个重量
0.05kg
,
14
元
/kg
)、菠萝
D
(每个重量
0.4kg
,
16
元
/kg
)。例如一顾客
拿出一张
100
元面额的纸钞,要购买一批水果:
AAAAABBBBCCCDD
,即
5
个苹果、
4
个梨、
3
个桃、
2
个菠萝,水果店需要给该批水果称重、计算应付金额、找零钱。
请设计水果店
类
完成称重、计算应付金额、找零钱等功能,顾客
类
完成购买商品的行为;请
设 计 有 关 代 码 模 拟 实 现 水 果 店 与 该 顾 客 之 间 的 交 易 。 顾 客 购 买 的 商 品 模 拟 为 字 符 串
“
AAAAABBBBCCCDD
”,请将该字符串作为输入参数。
#include<bits/stdc++.h>
using namespace std;
class CFruit_stand
{
public:
CFruit_stand();
~CFruit_stand();
double weight;
double price;
void charge(char*,double);
void print();
};
CFruit_stand::CFruit_stand()
{
weight=0;
price=0;
}
CFruit_stand::~CFruit_stand()
{
}
void CFruit_stand::charge(char *p,double money)
{
while(*p!='\0')
{
if(*p=='A')
{
weight+=0.1;
price+=0.1*10;
}
else if(*p=='B')
{
weight+=0.1;
price+=0.1*12;
}
else if(*p=='C')
{
weight+=0.05;
price=0.05*14;
}
else if(*p=='D')
{
weight+=0.4;
price+=0.4*16;
}
p++;
}
cout<<"收顾客钱"<<money<<endl;
cout<<"水果的总价"<<price<<endl;
cout<<"水果的总重"<<weight<<endl;
cout<<"应找钱"<<money-price<<endl;
}
int main()
{
CFruit_stand a;
a.charge("AAAAABBBBCCCDD",100);
}