C++實(shí)現(xiàn)超市商品管理系統(tǒng)最新版
超市商品管理系統(tǒng),供大家參考,具體內(nèi)容如下
一、問題描述及功能要求
1.提供商品系統(tǒng)的添加、刪除、編輯、顯示等功能。
2.同類系統(tǒng)多數(shù)使用結(jié)構(gòu)體數(shù)組來操作數(shù)據(jù),本系統(tǒng)使用鏈表結(jié)構(gòu)操作數(shù)據(jù),提高了數(shù)據(jù)處理的效率。
二、代碼實(shí)現(xiàn) 帶有注釋
廢話不說,直接代碼,歡迎指正。
大家CV可能有不兼容的情況,可以滴滴,盡可能解決問題地回復(fù)。
#include <iostream> #include <string.h> #include <fstream> #include <conio.h>//用getch(); using namespace std; //以下是類的設(shè)計(jì) class commodity { public: char name[20]; char Id[20]; int buy;//進(jìn)貨價; int sale;//賣出價; int amount;//數(shù)量; int sum;//利潤; commodity * Next; void Input() { cout<<"\t\t請輸入商品的名稱:"; cin>>name; cout<<"\t\t請輸入商品的編號:"; cin>>Id; cout<<"\t\t請輸入進(jìn)貨價:"; cin>>buy; cout<<"\t\t請輸入售出價:"; cin>>sale; cout<<"\t\t請輸入商品數(shù)量:"; cin>>amount; sum=(sale-buy)*amount; } void ReadFile(istream & in) { in>>name>>Id>>sale>>buy>>sum; } void Show() { cout<<"商品名"<<name<<endl<<"編號:"<<Id<<endl<<"進(jìn)貨價"<<buy<<"售出價"<<sale<<"商品數(shù)量:"<< amount<<"預(yù)計(jì)總利潤:"<<sum<<endl<<endl<<endl; } }; //以下是對象或?qū)ο髷?shù)組的定義 //﹌﹌﹌﹌﹌﹌﹌﹌﹌Commoditymassage類﹌﹌﹌﹌﹌﹌﹌﹌﹌﹌﹌﹌ class Commoditymassage { public: Commoditymassage(); ~Commoditymassage(); void ShowMenu(); void Find(); void Save(); void ModifyItem(); void RemoveItem(); void Swap(commodity *,commodity *); void Sort(); int ListCount(); void Display() { for(commodity * p=Head->Next;p!=End;p=p->Next) p->Show(); cout<<"輸入任意字符!繼續(xù)……"; getch(); } void AddItem() { End->Input(); End->Next=new commodity; End=End->Next; cout<<"添加成功!"<<endl; cout<<"輸入任意字符!繼續(xù)……"; getch(); } private: commodity * Head,* End; ifstream in; ofstream out; commodity *FindItem(char * name) { for(commodity * p=Head;p->Next!=End;p=p->Next)//匹配成功則返回上一個指針,不成功就返回空 if(!strcmp(p->Next->name,name))return p; return NULL; } commodity *FindID(char * Id) { for(commodity * p=Head;p->Next!=End;p=p->Next)//匹配成功則返回上一個指針,不成功就返回空 if(!strcmp(p->Next->Id,Id))return p; return NULL; } }; //﹌﹌﹌﹌﹌﹌﹌﹌﹌﹌﹌﹌構(gòu)造函數(shù)﹌﹌﹌﹌﹌﹌﹌﹌﹌﹌﹌﹌ Commoditymassage::Commoditymassage() { Head=new commodity; Head->Next=new commodity; End=Head->Next; in.open("sort.txt"); if(!in) cout<<"無商品信息。請先輸入。"<<endl; else { while(!in.eof()) { End->ReadFile(in); if(End->name[0]=='\0')break; End->Next=new commodity; End=End->Next; } in.close(); cout<<"\t\t讀取商品信息成功!"<<endl; } } //﹌﹌﹌﹌﹌﹌﹌﹌﹌﹌﹌﹌析構(gòu)函數(shù)﹌﹌﹌﹌﹌﹌﹌﹌﹌﹌﹌﹌ Commoditymassage::~Commoditymassage() { Save(); for(commodity * temp;Head->Next!=End;) { temp=Head->Next; Head->Next=Head->Next->Next; delete temp; } delete Head,End; } //以下是主函數(shù) int main() { int x,i=0; bool quit=false; cout<<"\t\t**************************"<<endl; for(i=0;i<3;i++) cout<<"\t\t*\t\t\t\t\t\t *"<<endl; cout<<"\t\t*****【 歡迎進(jìn)入超市商品管理系統(tǒng) 】*****"<<endl; for(i=0;i<3;i++) cout<<"\t\t◎\t\t\t\t\t\t ◎"<<endl; cout<<"\t\t**************************\n"<<endl;; Commoditymassage Grade; cout<<"按任意鍵開始……"; getch(); while(!quit) { Grade.ShowMenu(); cin>>x; switch(x) { case 0:quit=true;break; case 1:Grade.AddItem();break; case 2:Grade.Display();break; case 3:Grade.Sort();break; case 4:Grade.Find();break; case 5:Grade.RemoveItem();break; case 6:Grade.ModifyItem();break; } } return 0; } void Commoditymassage::ShowMenu() { cout<<" 超 市 商 品 管 理 系 統(tǒng) "<<endl; cout<<" ┌────-────┐"<<endl; cout<<" │ 1.增加超市商品 │"<<endl; cout<<" │ 2.顯示超市商品 │"<<endl; cout<<" │ 3.排序統(tǒng)計(jì)商品 │"<<endl; cout<<" │ 4.查找超市商品 │"<<endl; cout<<" │ 5.刪除超市商品 │"<<endl; cout<<" │ 6.修改超市商品 │"<<endl; cout<<" │ 0.安全退出系統(tǒng) │"<<endl; cout<<" └────────-┘"<<endl; cout<<"\n\t\t\n\t\t請選擇:"; } //﹌﹌﹌﹌﹌﹌﹌﹌﹌﹌﹌﹌查找函數(shù)﹌﹌﹌﹌﹌﹌﹌﹌﹌﹌﹌﹌ void Commoditymassage::Find() { char name[20] ,Id[10]; int x; commodity * p=NULL; cout<<"\n\t\t*********************************\n"; cout<<"\t\t※ 1.按商品的名稱查找\n\t\t※ 2.按商品編號查找"; cout<<"\n\t\t*********************************\n請選擇:"; cin>>x; switch(x) { case 1:{cout<<"\t\t請輸入要查找的商品的名稱:";cin>>name; if(p=FindItem(name)) { p->Next->Show(); cout<<"輸入任意字符!繼續(xù)……"; getch(); } else { cout<<"\t\t沒有找到該名稱的商品!"<<'\n'<<endl; cout<<"輸入任意字符!繼續(xù)……"; getch(); } }break; case 2: { cout<<"\t\t請輸入要查找的商品的編號:";cin>>Id; if(p=FindID(Id)) { p->Next->Show(); cout<<"輸入任意字符!繼續(xù)……"; getch(); } else { cout<<"\t\t沒有找到該編號的商品!"<<'\n'<<endl; cout<<"輸入任意字符!繼續(xù)……"; getch(); } }break; } } //﹌﹌﹌﹌﹌﹌﹌﹌﹌﹌﹌﹌修改商品信息﹌﹌﹌﹌﹌﹌﹌﹌﹌﹌﹌﹌ void Commoditymassage::ModifyItem() //修改商品信息 { char name[20]; commodity * p=NULL; cout<<"\t\t請輸入要修改的商品的名稱:";cin>>name; if(p=FindItem(name)) { cout<<"\t\t已找到商品的信息,請輸入新的信息!"<<endl; p->Next->Input(); cout<<"修改成功!"<<endl; cout<<"輸入任意字符!繼續(xù)……"; getch(); } else { cout<<"\t\t沒有找到!"<<endl; cout<<"輸入任意字符!繼續(xù)……"; getch(); } } //﹌﹌﹌﹌﹌﹌﹌﹌﹌﹌﹌﹌刪除信息﹌﹌﹌﹌﹌﹌﹌﹌﹌﹌﹌﹌ void Commoditymassage::RemoveItem() // 刪除信息 { char name[20]; commodity * p=NULL,*temp=NULL; cout<<"\t\t請輸入要刪除的商品的名稱:"<<endl;cin>>name; if(p=FindItem(name)) { temp=p->Next; p->Next=p->Next->Next; delete temp; cout<<"\t\t刪除成功!"<<endl; cout<<"輸入任意字符!繼續(xù)……"; getch(); } else { cout<<"\t\t沒有找到!"<<endl; cout<<"輸入任意字符!繼續(xù)……"; getch(); } } //﹌﹌﹌﹌﹌﹌﹌﹌﹌﹌﹌﹌﹌﹌﹌﹌﹌﹌﹌﹌﹌﹌﹌﹌ void Commoditymassage::Swap(commodity *p1, commodity *p2)//交換兩個combox變量的數(shù)據(jù)域 { commodity *temp=new commodity; strcpy(temp->name,p1->name); strcpy(temp->Id,p1->Id); temp->sale=p1->sale; temp->buy=p1->buy; temp->sum=p1->sum; strcpy(p1->name,p2->name); strcpy(p1->Id,p2->Id); p1->sale=p2->sale; p1->buy=p2->buy; p1->sum=p2->sum; strcpy(p2->name,temp->name); strcpy(p2->Id,temp->Id); p2->sale=temp->sale; p2->buy=temp->buy; p2->sum=temp->sum; } //﹌﹌﹌﹌﹌﹌﹌﹌﹌﹌﹌﹌﹌﹌﹌﹌﹌﹌﹌﹌﹌﹌﹌﹌ int Commoditymassage::ListCount()//統(tǒng)計(jì)當(dāng)前鏈表的記錄總數(shù),返回一個整數(shù) { if(! Head) return 0; int n=0; for(commodity * p=Head->Next;p!=End;p=p->Next) { n++; } return n; } //﹌﹌﹌﹌﹌﹌﹌﹌﹌﹌﹌﹌﹌﹌﹌﹌﹌﹌﹌﹌﹌﹌﹌﹌ void Commoditymassage::Sort()//對當(dāng)前鏈表進(jìn)行排序 { cout <<"Sorting..."<<endl; commodity *p=NULL,*p1=NULL,*k=NULL; int n=Commoditymassage::ListCount(); if(n<2) return; for(p=Head->Next;p!=End;p=p->Next) for(k=p->Next;k!=End;k=k->Next) { if(p->sum>k->sum) { Commoditymassage::Swap(p,k); } } cout <<"排序完成!"<<endl; getch(); return; } //﹌﹌﹌﹌﹌﹌﹌﹌﹌﹌﹌保存函數(shù)﹌﹌﹌﹌﹌﹌﹌﹌﹌﹌﹌﹌﹌ void Commoditymassage::Save() { out.open("sort.txt"); for(commodity *p=Head->Next;p!=End;p=p->Next) out<<p->name<<"\t"<<p->Id<<"\t"<<p->sum<<'\n'; out.close(); }
以上就是本文的全部內(nèi)容,希望對大家的學(xué)習(xí)有所幫助,也希望大家多多支持腳本之家。
- C++實(shí)現(xiàn)簡單的圖書管理系統(tǒng)
- C++實(shí)現(xiàn)簡單職工信息管理系統(tǒng)
- C++實(shí)現(xiàn)簡單的學(xué)生管理系統(tǒng)
- C++學(xué)生信息管理系統(tǒng)
- C++實(shí)現(xiàn)停車場管理系統(tǒng)
- C++實(shí)現(xiàn)簡單的信息管理系統(tǒng)
- C++實(shí)現(xiàn)企業(yè)職工工資管理系統(tǒng)
- C++基礎(chǔ)學(xué)生管理系統(tǒng)
- C++實(shí)現(xiàn)簡單職工管理系統(tǒng)
- C++實(shí)現(xiàn)學(xué)校運(yùn)動會管理系統(tǒng)
相關(guān)文章
C++實(shí)現(xiàn)LeetCode(42.收集雨水)
這篇文章主要介紹了C++實(shí)現(xiàn)LeetCode(42.收集雨水),本篇文章通過簡要的案例,講解了該項(xiàng)技術(shù)的了解與使用,以下就是詳細(xì)內(nèi)容,需要的朋友可以參考下2021-07-07C++實(shí)現(xiàn)LeetCode(59.螺旋矩陣之二)
這篇文章主要介紹了C++實(shí)現(xiàn)LeetCode(59.螺旋矩陣之二),本篇文章通過簡要的案例,講解了該項(xiàng)技術(shù)的了解與使用,以下就是詳細(xì)內(nèi)容,需要的朋友可以參考下2021-07-07簡單了解C++語言中的二元運(yùn)算符和賦值運(yùn)算符
這篇文章主要介紹了C++語言中的二元運(yùn)算符和賦值運(yùn)算符,文中列出了可重載的運(yùn)算符列表,需要的朋友可以參考下2016-01-01詳解C++?STL模擬實(shí)現(xiàn)vector
這篇文章主要為大家詳細(xì)介紹了C++如何模擬實(shí)現(xiàn)STL容器vector,文中的示例代碼講解詳細(xì),對我們學(xué)習(xí)C++有一定幫助,需要的可以參考一下2023-01-01Dev C++編譯時運(yùn)行報錯source file not compile問題
這篇文章主要介紹了Dev C++編譯時運(yùn)行報錯source file not compile問題,具有很好的參考價值,希望對大家有所幫助,如有錯誤或未考慮完全的地方,望不吝賜教2024-01-01基于malloc與free函數(shù)的實(shí)現(xiàn)代碼及分析
本篇文章介紹了malloc與free函數(shù)的實(shí)現(xiàn)代碼及分析。需要的朋友參考下2013-05-05