///以下以办公室常用的饮水机(夏天)为例:
//
//
//
//
#include <iostream.h>
#include <time.h>
#include <stdlib.h>
//#define random(x) (rand()%x)
class Cyongchi{
private:
int x;
int y;
int z;
public:
int shishui(int intRongliang,int intShishui);
int zhushui(int intRongliang,int intZhushui);
Cyongchi(int x,int y,int z){
intRongliang=x;
intShishui=y;
intZhushui=z;
}
int intRongliang;
int intShishui;
int intZhushui;
};
Cyongchi::shishui(int intRongliang,int intShishui){
intRongliang-=intShishui;
return intRongliang;
};
Cyongchi::zhushui(int intRongliang,int intZhushui){
intRongliang+=intZhushui;
return intRongliang;
};
//int rand()
//{
// srand((int)time(0));
// return random(50);
//}
int jiance(int r){
if(r<=60&&r>=0)
return 0;
else if(r<=100 && r>60)
return 1;
else
return 2;
}
void main(){
int intRl,intSs,intZs,i;
Cyongchi cc(100,30,10);
intRl=cc.intRongliang;
intSs=cc.intShishui;
intZs=cc.intZhushui;
while(1){
cout<<"请输入取水量:"<<endl;
cin>>intSs;
intRl=cc.shishui(intRl,intSs);
cout<<"取水后的容量为:"<<intRl<<endl;
if(jiance(intRl)==0){
i=0;
while(jiance(intRl)==0){
++i;
cout<<"当前的容量为:"<<intRl<<",容量过低,必须注水!!"<<endl;
intRl=cc.zhushui(intRl,intZs);
cout<<"这是第"<<i<<"次注水"<<endl;
cout<<"注水后的容量为:"<<intRl<<endl;
}
cout<<"注水成功!"<<endl;
}
}
}
//
//
//
//
#include <iostream.h>
#include <time.h>
#include <stdlib.h>
//#define random(x) (rand()%x)
class Cyongchi{
private:
int x;
int y;
int z;
public:
int shishui(int intRongliang,int intShishui);
int zhushui(int intRongliang,int intZhushui);
Cyongchi(int x,int y,int z){
intRongliang=x;
intShishui=y;
intZhushui=z;
}
int intRongliang;
int intShishui;
int intZhushui;
};
Cyongchi::shishui(int intRongliang,int intShishui){
intRongliang-=intShishui;
return intRongliang;
};
Cyongchi::zhushui(int intRongliang,int intZhushui){
intRongliang+=intZhushui;
return intRongliang;
};
//int rand()
//{
// srand((int)time(0));
// return random(50);
//}
int jiance(int r){
if(r<=60&&r>=0)
return 0;
else if(r<=100 && r>60)
return 1;
else
return 2;
}
void main(){
int intRl,intSs,intZs,i;
Cyongchi cc(100,30,10);
intRl=cc.intRongliang;
intSs=cc.intShishui;
intZs=cc.intZhushui;
while(1){
cout<<"请输入取水量:"<<endl;
cin>>intSs;
intRl=cc.shishui(intRl,intSs);
cout<<"取水后的容量为:"<<intRl<<endl;
if(jiance(intRl)==0){
i=0;
while(jiance(intRl)==0){
++i;
cout<<"当前的容量为:"<<intRl<<",容量过低,必须注水!!"<<endl;
intRl=cc.zhushui(intRl,intZs);
cout<<"这是第"<<i<<"次注水"<<endl;
cout<<"注水后的容量为:"<<intRl<<endl;
}
cout<<"注水成功!"<<endl;
}
}
}
//以下为运行结果::