日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 编程资源 > 编程问答 >内容正文

编程问答

货品的进出库模型

發布時間:2024/4/15 编程问答 50 豆豆
生活随笔 收集整理的這篇文章主要介紹了 货品的进出库模型 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

貨品包括貨號和重量屬性,實現簡單的入庫出庫統計功能,實例用于加深指針和鏈表的認識以及類的使用。

#include <iostream> #include <string> using namespace std; class StockWeight {public:StockWeight(int c,int w = 0):weight(w),code(c){totalWeight += w;//入庫總重量增加cout << c << "stock input! total " << totalWeight << endl;}~StockWeight(){totalWeight -= weight;//出庫析構總重量減少cout << code << "stock output! left " << totalWeight << endl;}int getCode(){return code;//返回貨號 }static int getTotalWeight(){return totalWeight;//返回總重量 }StockWeight *next;private:int weight;//重量int code;//貨號static int totalWeight;//靜態成員 總共的重量 }; int StockWeight::totalWeight = 0; void inputWeight(StockWeight *&head,int code,int w) {StockWeight *g,*p = new StockWeight(code, w);//新對象結點p->next = NULL;if (head == NULL){head = p;return;}//鏈表沒有內容//循環將新結點插入到最后g = head;while (g->next != NULL){g = g->next;//指針挪動 }g->next = p; } void outputWeight(StockWeight *&head, int code) {StockWeight *g,*p;if (head == NULL){cout << " there is no goods!" << endl; return;}//鏈表沒有內容g = head;//跟蹤指針while (g->getCode() != code && g->next != NULL)//如果當前指針的code不等于特定的code 或者鏈表已經沒有下一結點便停止循環 {g = g->next;//指針挪動 }if (g->getCode() != code) { cout << " there is no goods code " << code << endl; return; }//沒找到貨品code//找到了code//第一個結點特殊處理if (g == head){head = head->next;//頭指針改變delete g;//出庫析構return;}//遍歷找出它的上結點p = head;while (p->next != g){p = p->next;//指針挪動break;}p->next = g->next;//重指向delete g;//出庫析構 } void main() {StockWeight *head = NULL;//鏈表頭指針int leng,code,weight;//leng是指令。。code是貨號。。weight是重量do{cin >> leng;//輸入指令switch (leng){case 1://入貨 {cout << "inputWeight:" << endl;//入庫cout << "code:";cin >> code;//輸入貨號cout << "weight:";cin >> weight;//輸入重量inputWeight(head, code, weight);//調用方法入庫break;}case 2://出貨 {cout << "outputWeight:" << endl;//出庫cout << "code:";cin >> code;//輸入貨號outputWeight(head, code);//調用方法出庫break;}case 3://輸出總重量 {cout << "total Weight:" << StockWeight::getTotalWeight() << endl;break;}default:break;}} while (leng);//無限循環知道輸入0 getchar();getchar(); }

?

轉載于:https://www.cnblogs.com/godehi/p/8320862.html

總結

以上是生活随笔為你收集整理的货品的进出库模型的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。