Chinaunix首页 | 论坛 | 博客
  • 博客访问: 2349704
  • 博文数量: 816
  • 博客积分: 10000
  • 博客等级: 上将
  • 技术积分: 5010
  • 用 户 组: 普通用户
  • 注册时间: 2008-12-17 17:57
文章分类

全部博文(816)

文章存档

2011年(1)

2008年(815)

分类:

2008-12-17 18:07:54

///////////////////////
//                   //
// editor:zhangping  //
// time:2006.10.20   //
//                   //
///////////////////////
#include
class Carlo
{
private:
float weight;
float price;
public:
Carlo(float =0,float =0);
void print(Carlo &);
};
Carlo::Carlo(float a,float b)
{
weight=a;
price=b;
}
void Carlo::print(Carlo &a)
{
static float weight_sum;
static float price_sum;
int i;
cout<<"你要进货(1)还是出货(0)"<<"\n";
cin>>i;
cout<<"请输入货物的质量:";
cin>>a.weight;
cout<<"请输入货物的价格:";
cin>>a.price;
if(i==1)
{
weight_sum+=a.weight;
price_sum+=a.weight*a.price;
}
else
{
weight_sum-=weight;
price_sum-=weight*price;
}
cout<<"货物的总质量是:"<cout<<"货物的总价格是:"<}
void main()
{
Carlo b;
char n;
do
{
  b.print(b);
  cout<<"你还想继续吗?(Y/N)"<<"\n";
      cin>>n;
}while(n=='Y');
}

--------------------next---------------------
#include
using namespace std;

class Carlo{
private:
float weight;
float price;
static float AllWeight;
static float Monney;
public:
Carlo()
{
cout<<"\n\t欢迎入库货品:\n"
<<"\n\t请输入货品的重量和单价:";
cin>>weight>>price;
AllWeight += weight;
Monney += weight*price;
}
~Carlo()
{
cout<<"\n\t欢迎卖出货品:\n";
AllWeight -= weight;
Monney -= weight*price;
}
void print()const
{
cout<<"\n\t现在输出当前有关货品的情况:\n"
<<"\t当前的货品重量为 :"< <<"\t当前库存总量为 :"< }
};
//初始化静态成员
float Carlo::AllWeight = 0;
float Carlo::Monney = 0;
void main()
{
Carlo carlo1;
Carlo carlo2;
carlo1.print();
{                              //在块中定义的类对象只在"{ }"存在,当程序离开"}",对象carlo3被销毁,注意的
Carlo carlo3;       //静态成员的变化
carlo3.print();
}
carlo2.print();
}

--------------------next---------------------

阅读(1219) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~