物品库存管理课程设计报告(2)

2019-02-20 23:40

紫金学院 Visual C++课程设计 2012级 计科、网络、软件

{ cout<<\错误,不能打开文件.\ getch(); exit(1); } timer=time(NULL); file<

InModify()同样也与进货功能有关。因为所进的品种可能是也有的品种,只是增加其中的数量而已。所以,在输入进货品种或品种代码时要判断是否是库中已有的品种,若是就调用这个函数,只从键盘输入具体的品牌数量或新增品牌数据即可,而不用在键入品种的各种数据,同时,新键入的各种数据也输出到进货清单。实际上该函数是对链表中所存在的结点的数据部分的修改。此函数先判断出货量是不是大于库存量,如果大于将显示“库存不足,重新输入”。如果小于的话将会继续程序,通过brnd[choice-1].quantity-=count;把原有量减去省下剩余量。

void CItem::InModify()//已有商品,再次进货,修改结点中的数据部分 { char name[20]; char choice; int count,jinhuo=0; int prenBrnd=nBrnd; //原先品牌数 int n=1; //用于判断是否继续进货 int flag=0; //用于判断是否新品牌 int * num; num=new int[prenBrnd]; for(int i=0;i

5

紫金学院 Visual C++课程设计 2012级 计科、网络、软件

{ cout<<\输入品牌名称:\ Flush(cin); cin.getline(name,20); for(int i=0;i>count; brnd[i].quantity+=count; quantity+=count; flag=1; break; } } if(flag==0) { strcpy(brnd[nBrnd].brnd_name,name); cout<<\输入品牌代码:\ cin>>brnd[nBrnd].Brand_code; cout<<\输入数量:\ cin>>brnd[nBrnd].quantity; cout<<\输入价格:\ cin>>brnd[nBrnd].brnd_price; quantity+=brnd[nBrnd].quantity; nBrnd++; } cout<<\继续进货:y/n \ cin>>choice; if(choice=='y'||choice=='Y') n=1; else n=0; }

ofstream file(\进货清单.txt\ if(!file) { cout<<\错误,不能打开文件.\ getch(); exit(1); }

timer=time(NULL); file<

file<<\品种\代码\颜色\

6

紫金学院 Visual C++课程设计 2012级 计科、网络、软件

file<prenBrnd) { for(i=prenBrnd;i

void add()这个函数实现添加客户资料功能。创建了一个“客户资料”文件,从键盘输入客户资料,再将客户的资料传到文件中,从而实现添加的功能。

void customer::add() //加入客户资料 { ofstream file( \客户资料.txt\ if(!file) { cout<<\错误,无法打开文件\ getch(); exit(1); } customer p2; p2.getdata(); //从键盘输入客户资料 //将该客户的资料传到文件中 file.write(reinterpret_cast (&p2),sizeof(customer));//reinterpret_cast将其他类型的数据转换为字符指针 }

void showab()这个函数实现的是显示客户资料的功能。首先以输入方式打开文件,读取“客户资料”文件,再读取,从而实现显示的功能。

void customer::showab() //全部显示 { ifstream file( \客户资料.txt\ //以输入方式打开文件

7

紫金学院 Visual C++课程设计 2012级 计科、网络、软件

if(!file) { cout<<\错误,无法打开文件\ getch(); exit(1); }

customer p2; file.read(reinterpret_cast (&p2),sizeof(customer));//读取文件内容 while(!file.eof())//读入正确,显示,接着读取 { p2.showdata(); getch(); file.read(reinterpret_cast (&p2),sizeof(customer)); } }

void search()这个函数实现的是查询客户资料的功能。增加了一个子菜单,选择是按客户名称查询,或者是按客户代码查询,亦或者是退出。同样的,我们所需的数据是要从“客户资料”文件中读取的。

void customer::search() //搜索 { char name1[10]; int code; int choice;

cout<<\按客户名称查询 \ cout<<\按客户代码查询 \ cout<<\退出 \ cout<<\输入选择: \ cin>>choice; switch(choice) { case 1: cout<<\输入客户名称: \ cin>>name1; code=0; break; case 2: cout<<\输入客户代码: \ cin>>code;

strcpy(name1,\ break; } fstream file( \客户资料.txt\ if(!file) {

8

紫金学院 Visual C++课程设计 2012级 计科、网络、软件

cout<<\错误,无法打开文件\ getch(); exit(1); }

char flag='a'; customer p2;

file.read(reinterpret_cast(&p2),sizeof(customer)); while( !file.eof() ) { if((strcmp(p2.customer_name,name1)==0) || (p2.customer_code==code)) { p2.showdata(); getch(); flag='z'; break; }

file.read(reinterpret_cast (&p2),sizeof(customer)); }

if(flag !='z') { cout<<(\客户未找到\\n\\n\ getch(); } }

void remove()这个函数实现的是删除客户资料的功能。和search函数一样,也是添加了一个子菜单,打开文件,若文件存在,则删除原文件,否则显示,“错误 文件无法打开”,依次读取文件内容,将未删除的文件写入temp中,然后再将temp文件中的内容写回file1中。

void customer::remove() //删除客户 {

char name1[10]; int code; int choice;

cout<<\按客户名称删除 \ cout<<\按客户代码删除 \ cout<<\退出 \ cout<<\输入选择: \ cin>>choice; if(choice==1) { cout<<\输入客户名称: \ cin>>name1; code=0; } else

9


物品库存管理课程设计报告(2).doc 将本文的Word文档下载到电脑 下载失败或者文档不完整,请联系客服人员解决!

下一篇:“党员义工服务月活动”启动仪式主持稿

相关阅读
本类排行
× 注册会员免费下载(下载后可以自由复制和排版)

马上注册会员

注:下载文档有可能“只有目录或者内容不全”等情况,请下载之前注意辨别,如果您已付费且无法下载或内容有问题,请联系我们协助你处理。
微信: QQ: