C++实现超市商品管理系统最新版
更新时间:2021年6月18日 00:02 点击:1629
超市商品管理系统,供大家参考,具体内容如下
一、问题描述及功能要求
1.提供商品系统的添加、删除、编辑、显示等功能。
2.同类系统多数使用结构体数组来操作数据,本系统使用链表结构操作数据,提高了数据处理的效率。
二、代码实现 带有注释
废话不说,直接代码,欢迎指正。
大家CV可能有不兼容的情况,可以滴滴,尽可能解决问题地回复。
#include <iostream> #include <string.h> #include <fstream> #include <conio.h>//用getch(); using namespace std; //以下是类的设计 class commodity { public: char name[20]; char Id[20]; int buy;//进货价; int sale;//卖出价; int amount;//数量; int sum;//利润; commodity * Next; void Input() { cout<<"\t\t请输入商品的名称:"; cin>>name; cout<<"\t\t请输入商品的编号:"; cin>>Id; cout<<"\t\t请输入进货价:"; cin>>buy; cout<<"\t\t请输入售出价:"; cin>>sale; cout<<"\t\t请输入商品数量:"; cin>>amount; sum=(sale-buy)*amount; } void ReadFile(istream & in) { in>>name>>Id>>sale>>buy>>sum; } void Show() { cout<<"商品名"<<name<<endl<<"编号:"<<Id<<endl<<"进货价"<<buy<<"售出价"<<sale<<"商品数量:"<< amount<<"预计总利润:"<<sum<<endl<<endl<<endl; } }; //以下是对象或对象数组的定义 //﹌﹌﹌﹌﹌﹌﹌﹌﹌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<<"输入任意字符!继续……"; getch(); } void AddItem() { End->Input(); End->Next=new commodity; End=End->Next; cout<<"添加成功!"<<endl; cout<<"输入任意字符!继续……"; 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; } }; //﹌﹌﹌﹌﹌﹌﹌﹌﹌﹌﹌﹌构造函数﹌﹌﹌﹌﹌﹌﹌﹌﹌﹌﹌﹌ 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; } } //﹌﹌﹌﹌﹌﹌﹌﹌﹌﹌﹌﹌析构函数﹌﹌﹌﹌﹌﹌﹌﹌﹌﹌﹌﹌ Commoditymassage::~Commoditymassage() { Save(); for(commodity * temp;Head->Next!=End;) { temp=Head->Next; Head->Next=Head->Next->Next; delete temp; } delete Head,End; } //以下是主函数 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*****【 欢迎进入超市商品管理系统 】*****"<<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<<" 超 市 商 品 管 理 系 统 "<<endl; cout<<" ┌────-────┐"<<endl; cout<<" │ 1.增加超市商品 │"<<endl; cout<<" │ 2.显示超市商品 │"<<endl; cout<<" │ 3.排序统计商品 │"<<endl; cout<<" │ 4.查找超市商品 │"<<endl; cout<<" │ 5.删除超市商品 │"<<endl; cout<<" │ 6.修改超市商品 │"<<endl; cout<<" │ 0.安全退出系统 │"<<endl; cout<<" └────────-┘"<<endl; cout<<"\n\t\t\n\t\t请选择:"; } //﹌﹌﹌﹌﹌﹌﹌﹌﹌﹌﹌﹌查找函数﹌﹌﹌﹌﹌﹌﹌﹌﹌﹌﹌﹌ 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<<"输入任意字符!继续……"; getch(); } else { cout<<"\t\t没有找到该名称的商品!"<<'\n'<<endl; cout<<"输入任意字符!继续……"; getch(); } }break; case 2: { cout<<"\t\t请输入要查找的商品的编号:";cin>>Id; if(p=FindID(Id)) { p->Next->Show(); cout<<"输入任意字符!继续……"; getch(); } else { cout<<"\t\t没有找到该编号的商品!"<<'\n'<<endl; cout<<"输入任意字符!继续……"; 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<<"输入任意字符!继续……"; getch(); } else { cout<<"\t\t没有找到!"<<endl; cout<<"输入任意字符!继续……"; 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<<"输入任意字符!继续……"; getch(); } else { cout<<"\t\t没有找到!"<<endl; cout<<"输入任意字符!继续……"; getch(); } } //﹌﹌﹌﹌﹌﹌﹌﹌﹌﹌﹌﹌﹌﹌﹌﹌﹌﹌﹌﹌﹌﹌﹌﹌ void Commoditymassage::Swap(commodity *p1, commodity *p2)//交换两个combox变量的数据域 { 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()//统计当前链表的记录总数,返回一个整数 { if(! Head) return 0; int n=0; for(commodity * p=Head->Next;p!=End;p=p->Next) { n++; } return n; } //﹌﹌﹌﹌﹌﹌﹌﹌﹌﹌﹌﹌﹌﹌﹌﹌﹌﹌﹌﹌﹌﹌﹌﹌ void Commoditymassage::Sort()//对当前链表进行排序 { 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; } //﹌﹌﹌﹌﹌﹌﹌﹌﹌﹌﹌保存函数﹌﹌﹌﹌﹌﹌﹌﹌﹌﹌﹌﹌﹌ 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(); }
以上就是本文的全部内容,希望对大家的学习有所帮助,也希望大家多多支持猪先飞。
上一篇: 详解C++实现匈牙利算法
下一篇: C++实现俄罗斯方块源码
相关文章
- vector是表示可以改变大小的数组的序列容器,本文主要介绍了C++STL标准库std::vector的使用详解,文中通过示例代码介绍的非常详细,具有一定的参考价值,感兴趣的小伙伴们可以参考一下...2022-03-06
- 这篇文章主要介绍了C++中取余运算的实现,文中通过示例代码介绍的非常详细,对大家的学习或者工作具有一定的参考学习价值,需要的朋友们下面随着小编来一起学习学习吧...2021-02-23
- 这篇文章主要介绍了C++ string常用截取字符串方法,文中通过示例代码介绍的非常详细,对大家的学习或者工作具有一定的参考学习价值,需要的朋友们下面随着小编来一起学习学习吧...2020-04-25
- 本文通过例子,讲述了C++调用C#的DLL程序的方法,作出了以下总结,下面就让我们一起来学习吧。...2020-06-25
- 本篇文章主要介绍了C++中四种加密算法之AES源代码,小编觉得挺不错的,现在分享给大家,也给大家做个参考。...2020-04-25
- 整数拆分,指把一个整数分解成若干个整数的和。本文重点给大家介绍C++ 整数拆分方法详解,非常不错,感兴趣的朋友一起学习吧...2020-04-25
- 这篇文章主要介绍了C++中Sort函数详细解析,sort函数是algorithm库下的一个函数,sort函数是不稳定的,即大小相同的元素在排序后相对顺序可能发生改变...2022-08-18
- 这篇文章主要介绍了C++万能库头文件在vs中的安装步骤(图文),文中通过示例代码介绍的非常详细,对大家的学习或者工作具有一定的参考学习价值,需要的朋友们下面随着小编来一起学习学习吧...2021-02-23
- 这篇文章主要为大家详细介绍了python实现学生通讯录管理系统,文中示例代码介绍的非常详细,具有一定的参考价值,感兴趣的小伙伴们可以参考一下...2021-02-25
- 这篇文章主要介绍了C++ bitset用法,文中通过示例代码介绍的非常详细,对大家的学习或者工作具有一定的参考学习价值,需要的朋友们下面随着小编来一起学习学习吧...2020-04-25
- 本篇文章小编并不是为大家讲解string类型的用法,而是讲解我个人比较好奇的问题,就是string 类型占几个字节...2020-04-25
- 这篇文章主要为大家详细介绍了C++ Eigen库计算矩阵特征值及特征向量,具有一定的参考价值,感兴趣的小伙伴们可以参考一下...2020-04-25
- 这篇文章主要介绍了C++ pair的用法实例详解的相关资料,需要的朋友可以参考下...2020-04-25
- 这篇文章主要介绍了VSCode C++多文件编译的简单使用方法,本文给大家介绍的非常详细,对大家的学习或工作具有一定的参考借鉴价值,需要的朋友可以参考下...2021-03-29
- 虽然C++11引入了智能指针的,但是开发人员在与内存的斗争问题上并没有解放,如果我门实用不当仍然有内存泄漏问题,其中智能指针的循环引用缺陷是最大的问题。下面通过实例代码给大家介绍c++中的循环引用,一起看看吧...2020-04-25
- 这篇文章主要给大家介绍了关于C++随机点名生成器的相关资料,文中通过示例代码介绍的非常详细,对大家的学习或者工作具有一定的参考学习价值,需要的朋友们下面随着小编来一起学习学习吧...2020-04-25
- map容器是C++ STL中的重要一员,删除map容器中value为指定元素的问题是我们经常与遇到的一个问题,下面这篇文章主要给大家介绍了关于利用C++如何删除map容器中指定值的元素的相关资料,需要的朋友可以参考借鉴,下面来一起看看吧。...2020-04-25
- 护卫神·主机管理系统该版本支持在Windows Server 200320082012,含32位和64位,直接开设配置WEB站、FTP站,以及SQL Server和MySQL,是您开设和管理虚拟主机的绝好帮手。但是对于新用户可能在使用上有一些困难,因此请仔细阅读如下说明文档...2016-01-27
- 这篇文章主要介绍了C++ 约瑟夫环问题案例详解,本篇文章通过简要的案例,讲解了该项技术的了解与使用,以下就是详细内容,需要的朋友可以参考下...2021-08-15
- 这篇文章主要介绍了C++中cin的用法详细,文中通过示例代码介绍的非常详细,对大家的学习或者工作具有一定的参考学习价值,需要的朋友们下面随着小编来一起学习学习吧...2020-04-25