#include "pch.h"
#include <iostream>
using namespace std;
class goods {
public:
goods(int w) {
weight = w;
total_weight += w;
}
~goods() {
total_weight -= weight;
}
static int total_weight_fun() {//类的函数,不能访问普通成员变量和普通函数
return total_weight;
}
goods *next; private:
int weight;
static int total_weight;//类的成员
}; int goods::total_weight = ;//声明与定义静态数据成员 void purchase(goods *&front, goods *&rear, int w) {
goods *p = new goods(w);
p->next = NULL; if (front == NULL) {
front = rear = p;
}
else {
rear->next = p;
rear = rear->next;
}
} void sale(goods *&front, goods *&rear) {
if (front == NULL) {
cout << "no any goods" << endl;
return;
} goods *q = front;
front = front->next;
delete q;
cout << "sale front goods" << endl;
}
int main()
{
goods *front = NULL, *rear = NULL;
int choice;
int weight;
do {
cout << "Key in 1 is purchase,\nKey in 2 is sale,\nKey in 0 is over.\n";
cin >> choice; switch(choice) {
case :
{
cout << "input weiht:";
cin >> weight;
purchase(front, rear, weight);
break;
}
case :
{
sale(front, rear);
break;
}
case :
break; } cout << "now total weight is: "<< goods::total_weight_fun()<<endl;
} while (choice);
cout << "exit!\n";
}

最新文章

  1. PHP 使用 mcrypt 扩展中的 mcrypt_encrypt() 和 mcrypt_decrypt() 对数据进行加密和解密
  2. VHDL学习之模块调用
  3. vim c++补全
  4. 【FTP】在自己的电脑上建立FTP服务器
  5. vi/vim使用指北 ---- Moving Around in a Hurry
  6. 推荐一个网站Stack Overflow
  7. Android View事件传递机制
  8. (2015年郑州轻工业学院ACM校赛题)H 五子棋
  9. C/C++变量命名规则
  10. poj1562--Oil Deposits
  11. 对于deferred的一点点理解
  12. windows hook (转)
  13. 【笔记】《通俗详细地讲解什么是P和NP问题》的概念记录
  14. 数据库.MongoDB.Java样例
  15. [MCM] 多目标优化 MOP(multi-objective programming)
  16. Redis + keepalived 高可用行配置检测脚本
  17. Python之进程 3 - 进程池和multiprocess.Poll
  18. win10 store 无法连接网络(原创)
  19. c# 生成验证码图片
  20. Mybatis 中 columnPrefix别名的用法

热门文章

  1. CS API 测试3
  2. springboot+beetlsql+mysql整合
  3. list&lt;?&gt;转换成 对应的 class
  4. [GO]非结构体匿名字段
  5. (1)WePHP 开启WePHP
  6. 搜狐 WEB 标准-前端技术应用规范
  7. CodeForces 339B Xenia and Ringroad(水题模拟)
  8. CodeForces 288B Polo the Penguin and Houses (暴力或都快速幂)
  9. SpringMVC源码解读 - RequestMapping注解实现解读 - ConsumesRequestCondition
  10. [LintCode笔记了解一下]41.Maximum Subarray