c语言程序设计 本 科 课 程 设 计文档格式.docx
- 文档编号:6750180
- 上传时间:2023-05-07
- 格式:DOCX
- 页数:14
- 大小:90.63KB
c语言程序设计 本 科 课 程 设 计文档格式.docx
《c语言程序设计 本 科 课 程 设 计文档格式.docx》由会员分享,可在线阅读,更多相关《c语言程序设计 本 科 课 程 设 计文档格式.docx(14页珍藏版)》请在冰点文库上搜索。
请选择下面的一个项目:
1排队
2打饭
3充值
4查询
5删除
6按消费总额排序
7显示
8退出
二.设计要求
程序要求
1)各个题目所需信息均采用链表结构存储;
2)各项功能的使用通过选择菜单项实现;
3)显示或输出可根据需要显式输出(即选择菜单中的输出或显示)或隐式输出(完成某项操作后即刻输出);
4)可以选择使用文件存储系统中的数据
5)如果同学认为自己有特殊想法也可编程实现。
三.设计分析
(1)建立一个函数,用来保存学生的学号,姓名,电话号码,班级,饭卡余额,密码等信息,完成餐卡功能。
主函数用八个子函数,分别完成排队,打饭,充值,查询,删除,消费总额,显示,退出。
(2)main()主函数:
定义本程序用到的各个变量及函数,然后读取文件进行的流程图如图
(一)
二)
(三)
#include<
stdio.h>
stdlib.h>
structnote{
intID;
charname[40];
floatmoney;
floatexpensemoney;
structnote*nextPtr;
};
//结构
typedefstructnoteLISTNODE;
typedefLISTNODE*LISTNODEPTR;
LISTNODEPTRheadPtr=NULL,lastPtr=NULL,headPtr1=NULL;
intenterChoice(void);
voidnewstudent(void);
voidbuyfood(void);
voidrecharge(void);
voidfind(void);
voiddeleteNode(void);
voidprintList(LISTNODEPTRcurrentPtr);
intenterChoice(void);
voiddestroyList(LISTNODEPTRheadPtr);
//函数原型
voidmain()
{
intchoice;
while((choice=enterChoice())!
=7){
switch(choice){
case1:
newstudent();
break;
case2:
buyfood();
case3:
recharge();
case4:
find();
case5:
deleteNode();
case6:
printList(headPtr);
}
}
destroyList(headPtr);
//选择功能
system("
pause"
);
return;
}
voidnewstudent(void)//排队,新加入一个同学
LISTNODEPTRcurrentPtr=NULL;
currentPtr==malloc(sizeof(LISTNODE));
/*分配结点内存*/
if(currentPtr!
=NULL){/*插入结点*/
if(headPtr==NULL){/*若创建的是头结点*/
headPtr=currentPtr;
lastPtr=currentPtr;
}
else{
lastPtr->
nextPtr=currentPtr;
/*将结点连上链表尾结点*/
/*使lastPtr指向当前链表的最后一个结点*/
printf("
EnterID\n"
scanf("
%d"
&
currentPtr->
ID);
Entername\n"
getchar();
gets(currentPtr->
name);
Entermoney\n"
%f"
money);
Enterexpensemoney\n"
expensemoney);
nextPtr=NULL;
/*设置链表结束标记*/
voidbuyfood(void)//买饭,并将第一个节点删掉
LISTNODEPTRcurrentPtr=NULL;
买饭成功,退出队伍"
if(headPtr->
nextPtr!
=NULL){
currentPtr=headPtr->
nextPtr;
headPtr=currentPtr;
headPtr=NULL;
voidrecharge(void){//充值
intnum;
请输入您要充值的金额:
\n"
num);
headPtr->
expensemoney=headPtr->
expensemoney+num;
voidfind(void)//查找并打印
LISTNODEPTRcurrentPtr;
intID1;
currentPtr=headPtr;
请输入要查询的学号:
ID1);
while(currentPtr!
=NULL&
&
currentPtr->
ID!
=ID1){
currentPtr=currentPtr->
if(currentPtr==NULL){
队列中无这名同学"
%-16s%-16s%-11s%10s\n"
"
ID"
name"
money"
expensemoney"
%-16d%-16s%-11.2f%10.2f\n"
currentPtr->
ID,currentPtr->
name,currentPtr->
money,currentPtr->
voiddeleteNode(void)//查找并删除
LISTNODEPTRpreviousPtr,currentPtr;
previousPtr=NULL;
/*将头接点地址赋给currentPtr*/
请输入要删除的学号:
/*查找待删除结点,若找到,则由currentPt指向该结点*/
while(currentPtr!
=ID1){
previousPtr=currentPtr;
if(currentPtr!
=NULL){/*如果找到要删除的结点*/
if(previousPtr==NULL)/*删除的是头结点*/
headPtr=currentPtr->
/*更新头结点*/
else/*删除的是中间结点或者尾结点*/
previousPtr->
nextPtr=currentPtr->
free(currentPtr);
/*释放结点内存*/
else
printf("
);
//没有找到符合条件的结点
voidprintList(LISTNODEPTRcurrentPtr)//打印
if(currentPtr==NULL)
thelistisempty\n"
while(currentPtr!
intenterChoice(void)//选项1,2,3,4,5代表不同的操作
intmenuChoice;
\nEnteryourchoice\n"
"
1.排队\n"
2.第一个同学打饭,并删除该同学信息\n"
3.第一个同学充值\n"
4.查询一个同学的信息,并打印\n"
5.删除一个同学的信息\n"
6.显示当前所有排队同学的信息\n"
7.退出\n"
menuChoice);
returnmenuChoice;
//返回对应的选项序号
voiddestroyList(LISTNODEPTRheadPtr)//释放内存//释放动态空间
LISTNODEPTRtempPtr;
while(headPtr!
tempPtr=headPtr;
headPtr=headPtr->
free(tempPtr);
- 配套讲稿:
如PPT文件的首页显示word图标,表示该PPT已包含配套word讲稿。双击word图标可打开word文档。
- 特殊限制:
部分文档作品中含有的国旗、国徽等图片,仅作为作品整体效果示例展示,禁止商用。设计者仅对作品中独创性部分享有著作权。
- 关 键 词:
- c语言程序设计 语言程序设计