课程设计报告 作者 张雷

上传人:小** 文档编号:55938319 上传时间:2018-10-08 格式:DOC 页数:19 大小:210.50KB
返回 下载 相关 举报
课程设计报告  作者 张雷_第1页
第1页 / 共19页
课程设计报告  作者 张雷_第2页
第2页 / 共19页
课程设计报告  作者 张雷_第3页
第3页 / 共19页
课程设计报告  作者 张雷_第4页
第4页 / 共19页
课程设计报告  作者 张雷_第5页
第5页 / 共19页
点击查看更多>>
资源描述

《课程设计报告 作者 张雷》由会员分享,可在线阅读,更多相关《课程设计报告 作者 张雷(19页珍藏版)》请在金锄头文库上搜索。

1、1C C 语言及程序设计语言及程序设计 课程设计报告课程设计报告班级:软件班级:软件 81501 学号学号:150047131 姓名:张姓名:张 雷雷2016 年 1 月2一、题目内容描述 输入超市 10 种菜的价格信息,每个信息含有成员名为“编号、菜名、卖菜人、单价、数 量、优惠折扣、金额(由计算得到)、金额排名”,分别编写六个函数求: (1)输入一个卖菜人,查询所有该卖菜人的信息并输出,若不存在显示没找到。 (2)输入一个新菜名的信息,按编号顺序将该信息插入后输出。 (3)输入一个已存在菜名信息,删除该菜名的信息后输出。 (4)求每种菜的金额=单价*数量*(1-优惠折扣); (5)求所有菜

2、的总数量和总金额并输出; (6)对所有菜按金额进行降序排序并输出其信息。 要求: 10 种菜的数据用文件存储,每种菜信息的结构体用数组和单链表,首先建立一个具有 10 种菜数据的单链表或数组,并在程序执行后先显示“菜单”,当输入为 1 时,执行第 (1)个函数;当输入为 2 时,执行第(2)个函数;当输入为 3 时,执行第(3)个函数; 当输入为 4 时,执行第(4)个函数;当输入为 5 时,执行第(5)个函数;当输入为 6 时, 执行第(6)个函数;当输入为 7 时,退出系统,当输入其他数字时,提示输入有错误。二、应用程序功能的详细说明 输入数字 1 查询卖菜人信息 输入数字 2 输入一个新

3、菜名的信息,按编号顺序将该信息插入后输出 输入数字 3 输入一个已存在菜名信息,删除该菜名的信息后输出 输入数字 4 每种菜的总金额 输入数字 5 所有菜的总数量和总金额 输入数字 6 所有菜按金额进行降序排序并输出其信息 输入数字 7 退出程序 输入其他数字 提示输入错误 三、输入数据类型、格式和内容数据类型数据类型:int num; char vge_name8; char name10; float price; int mount; float discount; float money; int race; 四、 主要模块的算法描述主函数:主函数:3(一)查找工人信息(一)查找工人信

4、息4(二)添加蔬菜信息(二)添加蔬菜信息(三)删除蔬菜信息(三)删除蔬菜信息5(四)计算每一种菜的总价(四)计算每一种菜的总价6(5)输出所有菜的数量及价格总和输出所有菜的数量及价格总和7(六)降序输出蔬菜信息(六)降序输出蔬菜信息8(7)退出程序退出程序(八)输入错误(八)输入错误五、程序的源代码清单数组法:数组法:#include #include #include #include #define LEN sizeof(struct vegetable)struct vegetable int num; char vge_name8; char name10; float price;

5、int mount; float discount; float money; int race; x15;void print1() printf(“ *n“);void print() /从文件输入 int i; FILE*f1; 9f1=fopen(“D:xy.txt“,“r“);for(i=0;i #include #include #include #define LEN sizeof(struct vegetable)struct vegetable int num; char vge_name8; char name10; float price; int mount; floa

6、t discount; float money; int race; struct vegetable *next; ; int n;void print1() printf(“ *n“);struct vegetable *creat()/创建链表函数int i;struct vegetable *p1,*p2,*head;FILE*f1; f1=fopen(“D:xy.txt“,“r“);p1=p2=head=(struct vegetable*)malloc(LEN);for(i=0;inum,p1-vge_name,p1-name,p1=(struct vegetable*)mallo

7、c(LEN);p2-next=p1;p2=p1;p2=NULL;return(head); void print(struct vegetable *head)/查询卖菜人信息函数 int i; char a10;14scanf(“%s“,a); for(i=1;iname,a)=0) break; else head=head-next; if(i=10) printf(“无该人信息n“); else printf(“查找结果如下:n“);printf(“n“); printf(“ 编号 菜名 姓名 单价数量折扣n“); printf(“ n“); printf(“%6.2d %-6s %-

8、6s%3.2f%3d %3.2fn“,head-num,head- vge_name,head-name,head-price,head-mount,head-discount);printf(“n“); float add3(struct vegetable *head) /一种菜的总价 int i; struct vegetable *p; p=head;printf(“n“); printf(“ 菜名 总金额 n“); for(i=1;ivge_name,(p-price)*(p-mount)*(p-discount); p=p-next;printf(“n“); float add4(

9、struct vegetable *head)/所有菜的总数量和总金额 int i,j,all=0;float all1=0.0; struct vegetable *p,*b;p=head;b=head; for(j=0;jmoney=(p-price)*(p-mount)*(p-discount);all1+=p-money; p=p-next; 15for(i=0;imount;b=b-next; printf(“n“);printf(“总数量 总金额 n“);printf(“n“);printf(“%4d %6.2f n“,all,all1);printf(“n“); struct v

10、egetable insert(struct vegetable *head)/插入函数 int i,j; struct vegetable *p,*p1,*p2,*p3,t; p1=malloc(LEN);scanf(“%d%s%s%f%d%f“,p2=head;head=p1;p1-next=p2; p=head;for(i=0;inext;for(j=0;jnumnum)t=*p;*p=*p2;*p2=t; p3=p-next;p-next=p2- next;p2-next=p3;p2=p2-next;p=p-next;printf(“结果如下n“);printf(“n“); print

11、f(“ 编号 菜名 姓名 单价数量折扣n“); for(i=0;inum,head- vge_name,head-name,head-price,head-mount,head-discount);head=head-next; 16printf(“n“);void dele(struct vegetable *head)/删除菜信息函数 int i=0; char a20; struct vegetable *p,*p1; p=head;p1=head; printf(“请输入想删除的蔬菜名:n“); scanf(“%s“,a); while(strcmp(p-vge_name,a)!=0i

12、+; if(i=10) printf(“无此菜信息n“); else if(i=0) head=head-next;printf(“n“);printf(“ 编号 菜名 姓名 单价数量折扣n“); for(i=0;inum,head-vge_name,head-name,head-price,head-mount,head- discount);head=head-next; printf(“n“); else p1-next=p-next;printf(“n“);printf(“ 编号 菜名 姓名 单价数量折扣n“); for(i=0;inum,head-vge_name,head-name

13、,head-price,head-mount,head-17discount);head=head-next; printf(“n“); void sort(struct vegetable *head)/排序函数 int i,j; struct vegetable *p,*p1,*p2,*p3,t; p1=head; p=head; for(i=0;imoney=p1-price*p1-mount*p1-discount; p1=p1-next; for(i=0;inext;for(j=0;jmoneymoney)t=*p;*p=*p2;*p2=t; p3=p-next;p- next=p2-next;p2-next=p3;p2=p2-next;p=p-next;printf(“n“); printf(“ 编号 菜名 姓名 单价数量折扣 总价 n“); for(i=0;inum,head-vge_name,head-name,head-price,head-mount,head-discount,head-money);head=head-next; 18printf(“n“); main() int i,c; print1(); printf(“ * 1.查询卖菜人信息

展开阅读全文
相关资源
相关搜索

当前位置:首页 > 商业/管理/HR > 管理学资料

电脑版 |金锄头文库版权所有
经营许可证:蜀ICP备13022795号 | 川公网安备 51140202000112号