/*菜单函数,返回值为整数*/
menu_select()
{
char *menu[]={"***************MENU***************", /*定义菜单字符串数组*/
" 0. init list", /*初始化*/
" 1. Enter list", /*输入记录*/
" 2. Delete a record from list", /*从表中删除记录*/
" 3. print list ", /*显示单链表中所有记录*/
" 4. Search record on name", /*按照姓名查找记录*/
" 5. Save the file", /*将单链表中记录保存到文件中*/
" 6. Load the file", /*从文件中读入记录*/
" 7. compute the score", /*计算所有学生的总分和均分*/
" 8. insert record to list ", /*插入记录到表中*/
" 9. copy the file to new file", /*复制文件*/
" 10. sort to make new file", /*排序*/
" 11. append record to file", /*追加记录到文件中*/
" 12. index on nomber", /*索引*/
" 13. total on nomber", /*分类合计*/
" 14. Quit"}; /*退出*/
char s[3]; /*以字符形式保存选择号*/
int c,i; /*定义整形变量*/
gotoxy(1,25); /*移动光标*/
printf("press any key enter menu......\n"); /*压任一键进入主菜单*/
getch(); /*输入任一键*/
clrscr(); /*清屏幕*/
gotoxy(1,1); /*移动光标*/
textcolor(YELLOW); /*设置文本显示颜色为黄色*/
textbackground(BLUE); /*设置背景颜色为蓝色*/
gotoxy(10,2); /*移动光标*/
putch(0xc9); /*输出左上角边框┏*/
for(i=1;i<44;i++)
putch(0xcd); /*输出上边框水平线*/
putch(0xbb); /*输出右上角边框 ┓*/
for(i=3;i<20;i++)
{
gotoxy(10,i);putch(0xba); /*输出左垂直线*/
gotoxy(54,i);putch(0xba);
} /*输出右垂直线*/
gotoxy(10,20);putch(0xc8); /*输出左上角边框┗*/
for(i=1;i<44;i++)
putch(0xcd); /*输出下边框水平线*/
putch(0xbc); /*输出右下角边框┛*/
window(11,3,53,19); /* 制作显示菜单的窗口,大小根据菜单条数设计*/
clrscr(); /*清屏*/
for(i=0;i<16;i++) /*输出主菜单数组*/
{
gotoxy(10,i+1);
cprintf("%s",menu[i]);
}
textbackground(BLACK); /*设置背景颜色为黑色*/
window(1,1,80,25); /*恢复原窗口大小*/
gotoxy(10,21); /*移动光标*/
do{
printf("\n Enter you choice(0~14):"); /*在菜单窗口外显示提示信息*/
scanf("%s",s); /*输入选择项*/
c=atoi(s); /*将输入的字符串转化为整形数*/
}while(c<0||c>14); /*选择项不在0~14之间重输*/
return c; /*返回选择项,主程序根据该数调用相应的函数*/
}
STUDENT *init()
{
return NULL;
}
/*创建链表*/
STUDENT *create()
{
int i; int s;
STUDENT *h=NULL,*info; /* STUDENT指向结构体的指针*/
for(;;)
{
info=(STUDENT *)malloc(sizeof(STUDENT)); /*申请空间*/
if(!info) /*如果指针info为空*/
{
printf("\nout of memory"); /*输出内存溢出*/
return NULL; /*返回空指针*/
}
inputs("enter no:",info->no,11); /*输入学号并校验*/
if(info->no[0]=='@') break; /*如果学号首字符为@则结束输入*/
inputs("enter name:",info->name,15); /*输入姓名,并进行校验*/
printf("please input %d score \n",N); /*提示开始输入成绩*/
s=0; /*计算每个学生的总分,初值为0*/
for(i=0;i<N;i++) /*N门课程循环N次*/
{
do{
printf("score%d:",i+1); /*提示输入第几门课程*/
scanf("%d",&info->score[i]); /*输入成绩*/
if(info->score[i]>100||info->score[i]<0) /*确保成绩在0~100之间*/
printf("bad data,repeat input\n"); /*出错提示信息*/
}while(info->score[i]>100||info->score[i]<0);
s=s+info->score[i]; /*累加各门课程成绩*/
}
温馨提示:答案为网友推荐,仅供参考