题目7:学生选课管理系统设计
功能:实现对选课信息的简单管理,选课的基本信息包括课程号、课程名、学时、学分、学号、姓名等。
基本要求:
1.设计简单的菜单,能够进行系统功能选择。
2.实现基本信息的录入功能。
3.在已有信息的基础上添加新的记录。
4.删除指定课程号的记录。
5.修改指定课程号的记录
6.实现信息的浏览功能
7.按学号进行查询功能
8.按学时排序功能
#include
#include
#include
#include
typedef struct
{
char course; //课程名
char nelenum[20]; //保存课程号
int period;//保存学时
int grade;//保存学分
char num[10]; //保存学号
char name[20]; //保存姓名
}Student;
Student select[1000];
int Input(Student t[]);
void Disp(Student t[],int n);
void Qur_info(Student t[],int n);
int Del_info(Student t[],int n);
int Insert(Student t[],int n);
void Modify_info(Student t[],int n);
int compare()
int menu_select();
int main() {
int n=0;
while(1)
{
switch(menu_select())
//开关语句
{
case 1:
printf("\t\t
输入记录\n");
n=Input(select,n);
break;
case 2:
printf("\t\t
显示记录\n");
Disp(select,n);
break;
case 3:
printf("\t\t
插入一条记录\n");
n=Insert(select,n);
printf("\t\t");
break;
case 4:
printf("\t\t
按学号及姓名找,删除一条记录\n");
n=Del_info(select,n);
printf("\t\t");
system("pause");
break;
case 5:
printf("\t\t
修改一个记录\n");
Modify_info(select,n);
printf("\t\t");
system("pause");
break;
case 6:
printf("\t\t
按学号查找并显示一个记录\n");
Qur_info(select,n);
printf("\t\t");
system("pause");
break;
case 7:
printf("\t\t 按学时排序并显示\n");
Sort_sub(Insert,n);
printf("\t\t\t
排序成功!\n");
Disp(Insert,n);
printf("\t\t");
break;
case 0: exit(0);
}
}
}
//1做主菜单,进行功能的选择
int menu_select()
{
int c;
do
{
system("cls"); //运行前清屏
printf("******************************************");
printf("\t\t 1.
输入选课信息及数据 \n");
printf("\t\t 2.
输出选课信息及数据 \n");
printf("\t\t 3.
添加选课信息及数据 \n");
printf("\t\t 4.
删除指定课程号的记录 \n");
printf("\t\t 5.
修改指定课程号的记录 \n");
printf("\t\t 6.
按学号查询选课信息 \n");
printf("\t\t 7.
按学时对选课信息进行排序 \n");
printf("\t\t 0.
结束程序 \n");
printf("******************************************"); printf("\t\t
请选择您要运行的选项按(0-7):");
scanf("%d",&c);
//读入选择
}
while(c<0||c>7);
return(c); //返回选择
}
int Input(student lesson[],int n)
{
int i=0;
char sign;
do
{
printf("\t\t 课程名:");
scanf("\t\t%d",lesson[n+i].course);
printf("\t\t 课程号:");
scanf("\t\t%s",lesson[n+i].nelenum);
printf("\t\t 学时:");
scanf("\t\t%s",&lesson[n+i].period);
printf("\t\t 学分:");
scanf("\t\t%d",&lesson[n+i].grade);
printf("\t\t 学号:");
scanf("\t\t%d",lesson[n+i].num);
printf("\t\t 姓名:");
scanf("\t\t%d",lesson[n+i].name);
printf("\t\t
是否继续输入?(Y/N)");
scanf("\t\t%s",&sign);
i++;
printf("\n");
if(sign=='N' ||
sign=='n')
{
break;
} }
while(sign=='Y' || sign=='y');
return (n+i);
}
void Disp(Student lesson[],int n)
//void代表没有返回值
{
int i=0;
printf("\t\t------------------------------------------------------\n");
printf("\t\t
课程名 课程号 学时 学分 学号 姓名 \n");
printf("\t\t------------------------------------------------------\n");
for(i=0;i
{
printf("%s %s d } %s %s \n",
lesson[n+i].course,lesson[n+i].nelenum,lesson[n+i].period,lesson[n+i].grade,lesson[n+i].num,lesson[n+i].name); //结构体
if(i>1&&i==0)
{
printf("\t\t--------------------------------------------------\n");
printf("\t\t");
system("pause");
printf("\t\t--------------------------------------------------\n");
}
}
printf("\t\t"); //空一格tab键
system("pause"); //停顿
}
int Insert(Student lesson[],int n) //插入学生信息
{
printf("\t\t 课程名:");
scanf("\t\t%d",lesson[n+i].course);
printf("\t\t 课程号:");
scanf("\t\t%s",lesson[n+i].nelenum);
printf("\t\t 学时:");
scanf("\t\t%s",&lesson[n+i].period);
printf("\t\t 学分:");
scanf("\t\t%d",&lesson[n+i].grade);
printf("\t\t 学号:");
scanf("\t\t%d",lesson[n+i].num);
printf("\t\t 姓名:");
scanf("\t\t%d",lesson[n+i].name);
n++;
printf("\t\t 插入记录成功!\n");
return n;
}
int Del_info(Student lesson[],int n) //按课程号删除信息
{
char nelenum[20];
int term;
int i=0;
printf("\t\t 输入他(她)的课程号:");
scanf("\t\t%s",&nelenum);
printf("\t\t 输入他(她)的学号:");
scanf("\t\t%s",&num);
for(i=0;i
{
if(strcmp(lesson[i].nelenum,nelenum)==0&&lesson[i].num==num)
{
lesson[i].num
= lesson[i+1].num;
strcpy(lesson[i].nelenum,lesson[i+1].nelenum);
strcpy(lesson[i].name,lesson[i+1].name);
lesson[i].clesson
= lesson[i+1].clesson;
lesson[i].mlesson
= lesson[i+1].mlesson;
lesson[i].elesson
= lesson[i+1].elesson;
printf("\t\t
删除记录成功!\n");
return(n-1);
}
else if(i==n-1)
{
printf("\t\t
对不起没找到该学生!\n");
return(n);
}
}
}
void Modify_info(Student lesson[],int n) //按课程号修改学生信息
{ char nelenum[20];
char course;
int i=0;
printf("\t\t 输入他(她)的课程号:");
scanf("\t\t%s",&nelenum);
printf("\t\t 输入他(她)的课程名:");
scanf("\t\t%d",&course);
for(i=0;i
{
if(strcmp(lesson[i].nelenum,nelenum)==0
&&strcmp(lesson[i].course,course)
{
printf("\t\t
请输入修改的姓名");
scanf("\t\t%s",&lesson[i].name);
printf("\t\t
请输入修改的学号:");
scanf("\t\t%d",&lesson[i].num);
return;
}
else if(i==n-1)
{
printf("\t\t
对不起没找到该学生!\n");
return;
}
}
}
void Qur_info(Student lesson[],int n) //按学号查找学生信息
{
char num[10];
printf("\t\t 输入他(她)的学号:");
scanf("\t\t%s",&num);
for(i=0;i
{
printf("\t\t
他(她)的姓名:%d\n",lesson[i].name);
printf("\t\t
他(她)的课程号:%s\n",lesson[i].nelenum);
printf("\t\t
他(她)的课程名:%d\n",lesson[i].course);
printf("\t\t
他(她)的学分:%d\n",lesson[i].grade);
return;
}
else if(i==n-1)
{
printf("\t\t
对不起没找到该学生!\n");
return;
}
}
int compare(const void* a, const void* b) //按学时进行降序排序
{
Student *s1 = (Student*)a;
Student *s2 = (Student*)b;
if (s1->period> s2->period)
{
return 1;
}
else
{
return 0;
}
}
--------------------Configuration: 1 - Win32
Debug--------------------
Compiling...
1.c
c:\documents and settings\administrator\桌面\1.c(29) : error C2085:
'menu_select' : not in formal parameter list
c:\documents and settings\administrator\桌面\1.c(34) : error C2085:
'main' : not in formal parameter list
c:\documents and settings\administrator\桌面\1.c(34) : error C2143:
syntax error : missing ';' before '{'
c:\documents and settings\administrator\桌面\1.c(38) : warning C4013:
'menu_select' undefined; assuming extern returning int
c:\documents and settings\administrator\桌面\1.c(42) : warning C4020:
'Input' : too many actual parameters
c:\documents and settings\administrator\桌面\1.c(73) : warning C4013:
'Sort_sub' undefined; assuming extern returning int
c:\documents and settings\administrator\桌面\1.c(75) : warning C4047:
'function' : 'struct Student *' differs in levels of indirection
from 'int (__cdecl *)(struct Student *,int )'
c:\documents and settings\administrator\桌面\1.c(75) : warning C4024:
'Disp' : different types for formal and actual parameter 1
c:\documents and settings\administrator\桌面\1.c(115) : error C2146:
syntax error : missing ')' before identifier 'lesson'
c:\documents and settings\administrator\桌面\1.c(115) : error C2061:
syntax error : identifier 'lesson'
c:\documents and settings\administrator\桌面\1.c(115) : error C2059:
syntax error : ';'
c:\documents and settings\administrator\桌面\1.c(115) : error C2059:
syntax error : '['
c:\documents and settings\administrator\桌面\1.c(115) : error C2059:
syntax error : ')'
c:\documents and settings\administrator\桌面\1.c(179) : error C2065:
'i' : undeclared identifier
c:\documents and settings\administrator\桌面\1.c(205) : error C2065:
'num' : undeclared identifier
c:\documents and settings\administrator\桌面\1.c(208) : warning
C4047: '==' : 'char [10]' differs in levels of indirection from
'int '
c:\documents and settings\administrator\桌面\1.c(210) : error C2106:
'=' : left operand must be l-value
c:\documents and settings\administrator\桌面\1.c(213) : error C2039:
'clesson' : is not a member of 'Student'
c:\documents and settings\administrator\桌面\1.c(11) : see
declaration of 'Student'
c:\documents and settings\administrator\桌面\1.c(213) : error C2039:
'clesson' : is not a member of 'Student'
c:\documents and settings\administrator\桌面\1.c(11) : see
declaration of 'Student'
c:\documents and settings\administrator\桌面\1.c(214) : error C2039:
'mlesson' : is not a member of 'Student'
c:\documents and settings\administrator\桌面\1.c(11) : see
declaration of 'Student'
c:\documents and settings\administrator\桌面\1.c(214) : error C2039:
'mlesson' : is not a member of 'Student'
c:\documents and settings\administrator\桌面\1.c(11) : see
declaration of 'Student'
c:\documents and settings\administrator\桌面\1.c(215) : error C2039:
'elesson' : is not a member of 'Student'
c:\documents and settings\administrator\桌面\1.c(11) : see
declaration of 'Student'
c:\documents and settings\administrator\桌面\1.c(215) : error C2039:
'elesson' : is not a member of 'Student'
c:\documents and settings\administrator\桌面\1.c(11) : see
declaration of 'Student'
c:\documents and settings\administrator\桌面\1.c(240) : warning
C4047: 'function' : 'const char *' differs in levels of indirection
from 'char '
c:\documents and settings\administrator\桌面\1.c(240) : warning
C4024: 'strcmp' : different types for formal and actual parameter
1
c:\documents and settings\administrator\桌面\1.c(240) : warning
C4047: 'function' : 'const char *' differs in levels of indirection
from 'char '
c:\documents and settings\administrator\桌面\1.c(240) : warning
C4024: 'strcmp' : different types for formal and actual parameter
2
c:\documents and settings\administrator\桌面\1.c(241) : error C2143:
syntax error : missing ')' before '{'
c:\documents and settings\administrator\桌面\1.c(272) : error C2181:
illegal else without matching if
c:\documents and settings\administrator\桌面\1.c(283) : error C2084:
function 'int __cdecl compare()' already has a body
c:\documents and settings\administrator\桌面\1.c(283) : warning
C4027: function declared without formal parameter list
执行 cl.exe 时出错.
1.obj - 1 error(s), 0 warning(s)