货物链表类代码
来源:互联网 发布:java程序员工作内容 编辑:程序博客网 时间:2024/06/10 07:49
题目:某商店经销一种货物,货物购进和卖出以箱为单位,各箱的重量不一样,因此商店需要记录目前库存的总重量,现在用C++模拟商店货物卖出和买进的情况。
#include<iostream>
using namespace std;
class Goods
{
public:
Goods(int w)
{
weight = w;
total_weight += weight;
}//构造函数
~Goods()//析构函数
{
total_weight -= weight;
}
static int Total_weight()
{
return total_weight;
}
Goods *next;类指针
protected:
private:
int weight;
static int total_weight;
};
int Goods::total_weight = 0;
void purchase(Goods *&f,Goods *&r, int w)
{
Goods *p = new Goods(w);
p->next = NULL;
if (f == NULL)
{
f = r = p;
}
else
{
r->next = p; r = r->next;
}
}
void sale(Goods *&f, Goods *&r)
{
if (f == NULL)
{
cout << "no goods" << endl;
}
else
{
Goods *q = f;
f = f->next;
delete q;
cout << "saled\n";
}
}
void main()
{
Goods *front = NULL, *rear = NULL;
int w; int choice;
do
{
cout << "Please choose:" << endl;
cout << "key in 1 is purchase,\nkey in 2 is sale\nkey in 0 is over" << endl;
cin >> choice;
switch (choice)//操作选择
{
case 1:
{
cout << "input weight:" << endl;//选择1,购进1箱货物
cin >> w;
purchase(front, rear, w);//从表尾插入一个结点
break;
}
case 2:
{
sale(front, rear); break;//选择2,卖出1箱货物。从表头删除一个结点
}
case 0://键入0,结束。
{
break;
}
}
cout << "now total_weight is:" << Goods::Total_weight() << endl;
}while (choice);
system("pause");
}
- 货物链表类代码
- 商品订购及货物采购信息系统(代码分析)
- 货物管理
- 货物管理
- 运载货物
- 货物调度
- 搬货物
- 商店货物管理系统
- 货物的查询
- 出口货物流程
- 货物跟踪系统
- 货物出库管理信息系统
- 货物入库管理信息系统
- [CMD]公司货物系统
- hihoCoder 1168 运输货物
- hihocoder 1168 运输货物
- hihocoder #1168 : 运输货物
- 货物+输入+排序+输出
- VMWare虚拟机提示:锁定文件失败,打不开磁盘的解决办法
- 详细理解TranslateAnimation
- 数据结构例程——迷宫问题(用队列)
- android中进程小记(感谢海洋哥)
- Redis安全设置 - 设置密码、禁用指令
- 货物链表类代码
- Innodb中的事务隔离级别和锁的关系
- 使用C语言操作MySQL数据库
- svn 密码清除
- phpstorm 多个项目管理
- lua基础(1)
- iOS 如何设置子视图alpha不同于父视图
- 使用JQuery插件Pinto 和Lightbox 制作带网格布局的响应式(Responsible)画廊(gallery)
- Struts2中的Action