?? sellwatermelon.cpp
字號:
//王婆賣瓜原程序
#include <iostream.h>
//水果類的聲明及實(shí)現(xiàn)
class fruit
{
static int Tnumber,Rnumber;//靜態(tài)數(shù)據(jù)成員
static double Weight;
public:
void totalweight(double weig)//重量
{
Weight+=weig;
cout<<"至今所賣的總重量是:"<<Weight<<endl;
}
void totalnumber(int num)//賣的數(shù)量
{
Tnumber+=num;
cout<<"至今所賣的總個(gè)數(shù)是:"<<Tnumber<<endl;
}
void returnnumber(int num)//退的數(shù)量
{
Rnumber+=num;
cout<<"至今所退的個(gè)數(shù)是:"<<Rnumber<<endl;
}
};
int fruit::Tnumber=0;//靜態(tài)數(shù)據(jù)成員初始化
int fruit::Rnumber=0;
double fruit::Weight=0;
void main()
{
fruit Xigua;
char Input;
int Snumber,Renumber;
double weight;
cout<<"Sell or Return:"<<endl;
cin>>Input;
while (Input=='s' || Input=='r')//給用戶提供很好的需求 利用循環(huán)來實(shí)現(xiàn)
{
if(Input=='s')
{
cout<<"Input sellnumber:"<<endl;
cin>>Snumber;
cout<<"Input weight:"<<endl;
cin>>weight;
Xigua.totalnumber(Snumber);
Xigua.totalweight(weight);
Xigua.returnnumber(0);
cout<<"Sell or Return:"<<endl;
cin>>Input;
}
else
{
cout<<"input Return number"<<endl;
cin>>Renumber;
Xigua.returnnumber(Renumber);
Xigua.totalnumber(0);
Xigua.totalweight(0);
cout<<"Sell or Return:"<<endl;
cin>>Input;
}
}
}
?? 快捷鍵說明
復(fù)制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -