面向对象的程序设计-26-对于商品库存量计算的实例
2013-01-16 18:40
375 查看
///*作业一:
//某商店经销一种货物。货物成箱购进,成箱卖出,购进和卖出时以重量为单位,各箱的重量不一样,因此,商店需要记录下目录库存的总重量。
//现在用C++模拟商店货物购进和卖出的情况,设计一个可以统计货物总重量的程序。要求定义一个Goods类,完成此功能。*/
//#include <iostream>
//using namespace std;
//class Goods
//{
// int mass;//质量
// static int i;//记录箱数
//public:
// Goods(){mass=0;}
// Goods(int m){mass=m;++i;}
// int read_mass(){return mass;}
// static int read_total(){return i;};
// int sell(){return -mass;}
// int buy(){return mass;}
//};
//int Goods::i=0;
//void main()
//{
// Goods g1(20),g2(30),g3(50);
// cout<<"经手的箱数:"<<Goods::read_total()<<endl;
// int total=0;
// total=g1.buy()+g2.sell()+g3.buy();
// cout<<"所有的存放质量:"<<total<<endl;
//
//};
/*
以前的例子,对于同一品种货物的买进与卖出的描述。建立该货物对象后,买进多少,再卖出多少,能够计算当下的库存量
*/
#include <iostream>
using namespace std;
class Goods
{
double total,remain,saled;
public:
Goods(){total=remain=saled=0;}
Goods(double i){total=remain=i;saled=0;}
void Buy(double i)
{
remain=total=i+remain;
cout<<"购入货物总量(kg):"<<i<<endl;
cout<<"目前库存剩余总量(kg):"<<remain<<endl;
}
void Sale()
{
double j;
cout<<"输入卖出货物重量(kg):";
cin>>j;
if(remain<j){cout<<"库存不足!"<<endl;}
else
{
remain-=j;saled+=j;
cout<<"已卖出货物(kg):"<<saled<<endl<<"目前库存剩余总量(kg):"<<remain<<endl;
}
}
};
void main()
{
Goods g(500);
g.Buy(300);g.Sale();g.Sale();
}
//某商店经销一种货物。货物成箱购进,成箱卖出,购进和卖出时以重量为单位,各箱的重量不一样,因此,商店需要记录下目录库存的总重量。
//现在用C++模拟商店货物购进和卖出的情况,设计一个可以统计货物总重量的程序。要求定义一个Goods类,完成此功能。*/
//#include <iostream>
//using namespace std;
//class Goods
//{
// int mass;//质量
// static int i;//记录箱数
//public:
// Goods(){mass=0;}
// Goods(int m){mass=m;++i;}
// int read_mass(){return mass;}
// static int read_total(){return i;};
// int sell(){return -mass;}
// int buy(){return mass;}
//};
//int Goods::i=0;
//void main()
//{
// Goods g1(20),g2(30),g3(50);
// cout<<"经手的箱数:"<<Goods::read_total()<<endl;
// int total=0;
// total=g1.buy()+g2.sell()+g3.buy();
// cout<<"所有的存放质量:"<<total<<endl;
//
//};
/*
以前的例子,对于同一品种货物的买进与卖出的描述。建立该货物对象后,买进多少,再卖出多少,能够计算当下的库存量
*/
#include <iostream>
using namespace std;
class Goods
{
double total,remain,saled;
public:
Goods(){total=remain=saled=0;}
Goods(double i){total=remain=i;saled=0;}
void Buy(double i)
{
remain=total=i+remain;
cout<<"购入货物总量(kg):"<<i<<endl;
cout<<"目前库存剩余总量(kg):"<<remain<<endl;
}
void Sale()
{
double j;
cout<<"输入卖出货物重量(kg):";
cin>>j;
if(remain<j){cout<<"库存不足!"<<endl;}
else
{
remain-=j;saled+=j;
cout<<"已卖出货物(kg):"<<saled<<endl<<"目前库存剩余总量(kg):"<<remain<<endl;
}
}
};
void main()
{
Goods g(500);
g.Buy(300);g.Sale();g.Sale();
}
相关文章推荐
- PHP面向对象程序设计实例分析
- [.net 面向对象程序设计深入](26)Redis——基础
- [.net 面向对象程序设计深入](26)Redis——基础
- PHP面向对象程序设计方法实例详解
- python通过面向对象程序设计方法 实现铅球运行轨迹的计算
- 面向对象的程序设计-学习笔记-25-运用实例
- 26_面向对象程序设计(原型【九】模拟extjs底层继承方式
- [.net 面向对象程序设计进阶] (26) 团队开发利器(五)分布式版本控制系统Git——图形化Git客户端工具TortoiseGit
- 18--26 面向对象程序设计24(深入解析原型继承的概念)
- 【C++程序设计】-面向对象设计实例
- 18--26 面向对象程序设计25(继承的三种方式)
- 18--26 面向对象程序设计22(创建一个原生的原型)
- 18_面向对象程序设计(对象【一】类的创建于实例对象)
- [.net 面向对象程序设计深入](26)Redis——基础
- [.net 面向对象程序设计深入](26)实战设计模式——策略模式 Strategy (行为型)
- [.net 面向对象程序设计深入](26)Redis——基础
- PHP面向对象程序设计之类常量用法实例
- 面向对象的程序设计-12-类型转换和运算符重载的实例
- 面向对象的程序设计-14-用虚函数实现价格的统计(实例)
- 面向对象程序设计实例——模拟网上购书的结帐功能