超市商品查询系统.doc_第1页
超市商品查询系统.doc_第2页
超市商品查询系统.doc_第3页
超市商品查询系统.doc_第4页
超市商品查询系统.doc_第5页
已阅读5页,还剩17页未读 继续免费阅读

下载本文档

版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领

文档简介

石河子大学课程设计报告超市商品查询系统目 录一、课程设计题目 1二、程序运行流程图 2三、参考文献 3附件一:源代码 4一、课程设计题目1本课程设计的基本要求 根据规定的题目,编写程序设计说明,程序设计说明包括以下内容: 1.设计的基本要求 2.程序运行的软硬件环境 3.程序的组成模块及每个模块的基本功能 4.每个模块的形式参数 5.每个模块的流程图 6.程序的使用方法 7.编程中的问题及解决的方法 8.心得体会2 课程设计题目 题目:超市商品查询系统。3 要求 1.有工作界面, (采用按钮或菜单方式)。 2.以商品为主,录入商品编号、商品名、生产地、单价、生产日期、类别、等字段;所录入的数据(至少6个记录)存入一个文本文件中;能根据情况调出数据。 3.具有商品编号排序功能。 4.具有对数据进行插入功能,并按其商品编号插入排序,使数据仍然有序。若插入同样的商品,其相应的数量增加。 5.具有删除记录功能。 6.可减少商品的数量,当输入数值,商品相应数量字段的值随之改变。 7.具有查询功能 (1)按商品编号、商品名、单价进行查询。 (2)按数量查询商品情况(每隔10个为一个数量段),当低于10个,可报警提示。 8.统计出每类商品的总价值和数量。 9.能在屏幕上输出所有商品的信息。二、程序运行流程图主菜单已有的数据库插入新的数据删除已有数据查询已有数据退出系统对已有数据进行排序统计数据显示所有信息收入支出三、程序设计的想法和具体思路四、参考文献李春葆,曾平,刘斌,C+语言程序设计题典,北京,清华大学出版社,2003年教师签名:签名日期:附件一:源代码/*/ /* Author: 韩镒赛 */ /* Date: 2008/6/25 */ /* Version: 1.0 */ /*/#include#include #include #include using namespace std;#define NULL 0 class Productionpublic: void input_message(); /输入信息函数声明 void show_message(); /展示函数声明 int get_num(); string get_name(); /获得私有数据name的函数声明 string get_addr();/获得私有数据addr的函数声明 double get_price();/获得私有数据price的函数声明 int get_count();/获得私有数据count的函数声明 double tongji();/统计函数声明 friend void Duihuan_xinxi(Production &p1,Production &p2);/交换信息函数声明 int reget_count(int);/count重新赋函数声明 void show_header(); void show_row(); Production *next; /private: int num; char name20; char addr20; double price; int count; int year; int month; int day; char nature; void Production:input_message() /1输入信息函数(采用先判断后定值的方法) coutnum; coutname; coutaddr; double d; coutd; while(d0) cout您的价格有误,请重新输入.endld; price=d; int e; coute; while(e0) cout您的数量有误,请重新输入.endle; count=e; coutnature; int f,g,h=0; cout请输入正确的生产日期:endl; coutf;/输入正确后,再赋值 while(f2050) cout请重新输入正确的年份段2000-2050endlf; year=f;/输入正确后,再赋值 /1,3,5,7,8,10,11为月大 /2,4,6,9,12为月小,2月看是否为闰年; if(year%4=0&year%100!=0)|(year%400=0) h=1;/判断是否为闰年 coutg; while(g12) cout月份错误,请重新输入(1-12)endlg; month=g;/输入正确后,再赋值 coutf; while(f31) cout日期错误,请重新输入(1-31)endlf; day=f;/输入正确后,在再赋值 if(month=4|month=6|month=9|month=12) cinf; while(f30) cout日期错误,请重新输入(1-30)endlf; day=f;/输入正确后,在再赋值 if(h=0&month=2)/非闰年的二月 cinf; while(f28) cout日期错误,请重新输入(1-28)endlf; day=f;/输入正确后,再赋值 if(h=1&month=2)/闰年的二月 cinf; while(f29) cout闰年,请重新输入(1-29)endlf; day=f;/输入正确后,再赋值 void Production:show_header()/显示表头 printf(-n); printf(|商品编号| 商品名称 | 生产地址 |商品价格|商品数量|商品属性| 生产日期 |n); printf(-n); void Production:show_row()/显示一行的数据 printf(|%3d |%10s|%11s|%8.2f| %3d | %c |%4d-%2d-%2d|n, num, name, addr, price, count, nature, year,month, day); printf(-n); void Production:show_message()/展示函数 cout商品编号: num ; cout商品名称: nameendl; cout商品生产地址:addr ; cout商品价格: priceendl; cout商品数量: count ; cout商品属性: natureendl; cout商品生产日期:year年month月day日endl; cout-endl; int Production:get_num() /获私有数据的成员函数的定义 return num; string Production:get_name() /获私有数据的成员函数的定义 return name; string Production:get_addr() /获私有数据的成员函数的定义 return addr; int Production:get_count() /获私有数据的成员函数的定义 return count; double Production:get_price() /获私有数据的成员函数的定义 return price; double Production:tongji() /统计成员函数的定义 return count*price; int Production:reget_count(int n) /重新设置私有数据-count数量 count=n; return count; static void show_welcome_msg(void) char sz_msg_begin256 = * Welcome to use Supper store query system *; char sz_msg_end256 = *; char * pc_msg; char c_bak; int i, i_step, i_interval; int i_len; i_step = 4; i_interval = 50; /* begin message */ pc_msg= sz_msg_begin; i_len = strlen(pc_msg); for (i = 0; ii_len; i += i_step) c_bak = pc_msgi_step; pc_msgi_step = 0; coutpc_msg; pc_msgi_step = c_bak; pc_msg += i_step; Sleep(i_interval); coutendl; cout 韩镒赛(2007级电子信息工程2班 )endl; cout1建立数据库 2插入 3删除endl; cout4查询 5排序 6统计endl; cout7显示所有信息 8支出 9收入endl; cout0退出endl; /* end message */ pc_msg= sz_msg_end; i_len = strlen(pc_msg); for (i = 0; ii_len; i += i_step) c_bak = pc_msgi_step; pc_msgi_step = 0; coutpc_msg; pc_msgi_step = c_bak; pc_msg += i_step; Sleep(i_interval); coutendl; coutendl; static int SUM=0;/全局变量 int main()/主函数 Production *creat(); /建立链表的函数 Production *insert(Production *head); Production *del(Production*head); /删除结点的函数 Production *Chaxun(Production*head); /查询 void Zhichu(Production*head); /查询 void Shouru(Production *head); void Paixu( Production *head); /排序 Production *Tongjizongliangshucha(Production *head); /统计 void Show(Production *head); /输出 ifstream open_SUM_file(SUM.txt,ios:binary); /输入1; /把数据库里的SUM找出来 /此时的SUM是上次操作后留下的 if(!open_SUM_file)/测试是否成功打开文件 cerr不存在SUM.TXT,请创建一个这样的文件!SUM; /取出值,并赋值给全局变量SUM open_SUM_file.close(); /取出后关闭文件 Production *head=NULL,*p,*p3; if(SUM!=0) ifstream infile(production.txt,ios:binary); if(!infile) cerr不存在production.txt,请创建一个这样的文件!next=NULL) k=0;/k=0时退出循环 else p=new Production; p3-next=p; while(k); /控制条件 infile.close(); string g; show_welcome_msg(); if(SUM=0) cout_endl; cout警告您的数据库是空的,请首先建立数据库!endl; cout_endl; coutg; while(g!=0) if(g=1) head=creat(); if(g=2) head=insert(head); if(g=3) head=del(head); if(g=4) head=Chaxun(head); if(g=5) Paixu(head); if(g=6) head=Tongjizongliangshucha(head); if(g=7) Show(head); if(g=8) Zhichu(head); if(g=9) Shouru(head); coutendl; cout提示*操作完毕请选择退出程序(选择命令0),否则您的数据将不能保存!*endl; /务必退出程序,否则处理结果无法保存 cout1建立数据库 2插入 3删除endl; cout4查询 5排序 6统计endl; cout7显示所有信息 8支出 9收入endl; cout0退出endl; coutg; if(head=NULL) SUM=0; ofstream SUM_file(SUM.txt,ios:binary); if(!SUM_file) cerropen error!endl; abort(); SUM_fileSUM; /存储人数到文件中 SUM_file.close(); ofstream outfile(production.txt,ios:binary); if(!outfile) cerropen error!next) outfile.write(char *)p,sizeof(Production); /写出信息到磁盘文件保存; outfile.close(); return 0;Production *creat() Production*p1,*p2,*head; if(SUM0) /此时不允许录入数据,只能使用添加功能录入 cout警告!您的数据库已经存在,若要重新建立,请清除 Production文件内容并使SUM文件归0endl; cout_endl; if(SUM=0)/判断条件 p1=p2=new Production; head=p1; int n; cout请输入需要建立的商品的数值:n; for(int i=0;in;i+) cout第i+1个商品的信息input_message(); /输入信息函数 p1=new Production; /申请空间 if(i=n-1) p2-next=NULL; else p2-next=p1; /指向下一接点 p2=p1; if(i=n) p2-next=NULL; /直到最后结尾点 SUM=n; return head; /返回头指针void Show(Production *head) head-show_header(); while(head!=NULL) /循环条件 head-show_row(); /调用展示成员函数 head=head-next; Production *insert(Production *head) /插入商品信息的一般函数 cout请输入要添加商品的详细信息:input_message(); /输入信息函数 while(p3-next!=NULL) if(p3-get_num()=p0-get_num() cout您输入重复,请重新输入!input_message(); p3=p3-next; p1=head; /使p1指向第一个结点 if(head=NULL) /原来的链表是空表 head=p0;p0-next=NULL; /使p0指向的结点作为头结点 if(p0-get_num()get_num() head=p0; p0-next=p1; else while(p0-get_num()p1-get_num() & (p1-next!=NULL) p2=p1; /使p2指向刚才p1指向的结点 p1=p1-next; /p1后移一个结点 if(p0-get_num()get_num() if(head=p1) head=p0; /插到原来第一个结点之前 else p2-next=p0; /插到p2指向的结点之后 p0-next=p1; else p1-next=p0; p0-next=NULL; /插到最后的结点之后 SUM+; return head;/返回头指针Production *del(Production *head) /删除结点的函数 Production *p1,*p2; int num; coutnum; if (head=NULL) /是空表 coutlist null!get_num() & p1-next!=NULL) /p1指向的不是所要找的结点且后面还有结点 p2=p1; p1=p1-next; /p1后移一个结点 if(num=p1-get_num() /找到了 if(p1=head) head=p1-next; /若p1指向的是首结点,把第二个结点地址赋予head else p2-next=p1-next; /否则将下一结点地址赋给前一结点地址 cout你已删除商品号-numendl; SUM=SUM-1; else coutcannot find num; /找不到该结点 return (head) ;Production *Chaxun(Production *head) if(head!=NULL) Production *p; int num; char i=A,j=B,k=C,d; char shangpinm20,shangpd20; cout按编号按A-商品名B-生产地Cd; if(d=i) coutnum; for(p=head;p!=NULL;p=p-next) if(num=p-get_num()p-show_message(); if(d=j) coutshangpinm; for(p=head;p!=NULL;p=p-next) if(shangpinm=p-get_name()p-show_message(); if(d=k) coutshangpd; for(p=head;p!=NULL;p=p-next) if(shangpd=p-get_addr()p-show_message(); return (head); /返回头指针 else cout这是一张空表!endl; return (head); void Duihuan_xinxi( Production &p1,Production &p2)/交换信息的函数 int t; double s; char q; char a20; t=p1.num;p1.num=p2.num;p2.num=t; t=p1.month;p1.month=p2.month;p2.month=t; t=p1.day;p1.day=p2.day;p2.day=t; t=p1.year;p1.year=p2.year;p2.year=t; t=p1.count;p1.count=p2.count;p2.count=t; s=p1.price;p1.price=p2.price;p2.price=s; q=p1.nature;p1.nature=p2.nature;p2.nature=q; strcpy(a,);strcpy(,);strcpy(,a); strcpy(a,p1.addr);strcpy(p1.addr,p2.addr);strcpy(p2.addr,a);void Paixu( Production *head)/冒泡法排序 Production *p1=head,*p2; char d; if(head!=NULL) cout按编号按A-商品名B-生产地Cd; if (d != A & d != B & d != C & d != a & d != b & d != c) cout错误的输入!endl; return; else cout这是一张空表!get_num()p2-get_num() Duihuan_xinxi(*(p1),*(p2); else if ( d = B | d = b) if( p1-get_name() p2-get_name() ) Duihuan_xinxi(*(p1),*(p2); else if ( d = C | d = c) if( p1-get_addr() p2-get_addr() ) Duihuan_xinxi(*(p1),*(p2); p2=p2-next; p1=p1-next; p2=p1; cout-endl; cout已经成功排序,想看结果请按7endl; cout-endl;Production *Tongjizongliangshucha(Production *head)/统计总数量的一般函数 Production *p; string fa=fangbianmian,xi=xiangshui,ya=yagao,ni=niunai; couta; if(a=fa) int zcount=0,sum=0; for(p=head;p!=NULL;p=p-next)/顺序查找 if(a=(p-get_name() zcount=p-get_count(); /找到数量 sum=p-tongji(); /统计 cout你要统计的商品总数为: zcountendl; cout你要统计的商品总价值为:sumnext) if(a=(p-get_name() zcount=p-get_count(); sum=p-tong

温馨提示

  • 1. 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
  • 2. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
  • 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
  • 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
  • 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
  • 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
  • 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。

评论

0/150

提交评论