回复 4楼 炎天
我没把这题的功能写完,你凑合看吧
#include<stdio.h>
#include<stdlib.h>
#include<process.h>
struct Course{
int no;//课程编号
char name[50];//课程名称
char major[50];//课程性质(专业)
int time;//学时
int stime;//授课学时
int ttime;//实验学时
int score;//学分
char ktime[50];//开课学期
}course[100];
struct Student{
int num;//学号
char name[50];//姓名
char major[50];//专业
char grade[50];//年级
}student[1000];
void menu();
void menu1();
void menu2();
void menu()//主菜单
{
int i;
for(i=1;i<=3;i++)
printf("\n");
printf("
********************学生选课系统*********************\n");
printf("
*
*\n");
printf("
*
请选择人员身份
*\n");
printf("
*
*\n");
printf("
*
1、管理员
*\n");
printf("
*
*\n");
printf("
*
2、学生
*\n");
printf("
*
*\n");
printf("
*****************************************************\n");
}
void menu1()//管理员菜单
{
int i;
for(i=1;i<=3;i++)
printf("\n");
printf("
*********************管理员界面**********************\n");
printf("
*
*\n");
printf("
*
1、初始化课程信息
2、初始化学生信息
*\n");
printf("
*
*\n");
printf("
*
3、课程信息浏览
4、课程信息查询
*\n");
printf("
*
*\n");
printf("
*
5、选修情况查询
0、退出界面
*\n");
printf("
*
*\n");
printf("
*****************************************************\n");
}
void menu2()//学生菜单
{
printf("
**********************学生界面***********************\n");
printf("
*
*\n");
printf("
*
*\n");
printf("
*
*\n");
printf("
*
1、课程信息浏览
2、课程选择
*\n");
printf("
*
*\n");
printf("
*
*\n");
printf("
*
*\n");
printf("
*****************************************************\n");
}
void csave(int n)//课程信息录入
{
FILE *fp;
int i;
if((fp=fopen("E:\\cdata.txt","wb"))==NULL)
{
printf("cannot open file\n");
exit(0);
}
for(i=0;i<n;i++)
if(fwrite(&course[i],sizeof(struct Course),1,fp)!=1);
printf("file write error\n");
fclose(fp);
}
void ssave(int n)//学生信息录入
{
FILE *fp;
int i;
if((fp=fopen("E:\\sdata.txt","wb"))==NULL)
{
printf("cannot open file\n");
exit(0);
}
for(i=0;i<n;i++)
if(fwrite(&student[i],sizeof(struct Student),1,fp)!=1);
printf("file write error\n");
fclose(fp);
}
void cshow(int n)//课程信息查询
{
FILE *fp;
int i;
if((fp=fopen("E:\\cdata.txt","rb"))==NULL)
{
printf("cannot open file\n");
exit(0);
}
for(i=0;i<n;i++)
{
fread(&course[i],sizeof(struct Course),1,fp);
printf("5%d%20s%20s%20d%20d%20d%20d%20s",course[i].no,course[i].name,course[i].major,course[i].time,course[i].stime,course[i].ttime,course[i].score,course[i].ktime);
}
fclose(fp);
}
void sshow(int n)//学生信息查询
{
FILE *fp;
int i;
if((fp=fopen("E:\\sdata.txt","rb"))==NULL)
{
printf("cannot open file\n");
exit(0);
}
for(i=0;i<n;i++)
{
fread(&student[i],sizeof(struct Student),1,fp);
printf("%d%20s%20s%20s",student[i].num,student[i].name,student[i].major,student[i].grade);
}
fclose(fp);
}
void main()
{
int i,j=1,m,n,p;
menu();
printf("
请输入您的选择:");
scanf("%d",&i);
while(j)
{
switch(i)
{
case 1:
system("cls");
menu1();
while(j)
{
printf("
请输入您的选择:");
scanf("%d",&m);
switch(m)
{
case 1:
system("cls");
printf("请管理员初始化课程信息:\n");
printf("请输入课程数量:");
scanf("%d",&n);
for(p=0;p<n;p++)
{
printf("\n请输入课程编号:");
scanf("%d",&course[p].no);
printf("请输入课程名称:");
scanf("%s",course[p].name);
printf("请输入课程性质:");
scanf("%s",course[p].major);
printf("请输入学时:");
scanf("%d",&course[p].time);
printf("请输入授课学时:");
scanf("%d",&course[p].stime);
printf("请输入实验学时:");
scanf("%d",&course[p].ttime);
printf("请输入学分:");
scanf("%d",&course[p].score);
printf("请输入开课学期:");
scanf("%s",course[p].ktime);
csave(n);
}
break;
system("pause");
system("cls");
menu1();
case 2:
system("cls");
printf("请管理员初始化学生信息:\n");
for(p=0;p<5;p++)
{
printf("\n请输入课程编号:");
scanf("%d",&course[p].no);
printf("请输入课程名称:");
scanf("%s",course[p].name);
printf("请输入课程性质:");
scanf("%s",course[p].major);
printf("请输入学时:");
scanf("%d",&course[p].time);
printf("请输入授课学时:");
scanf("%d",&course[p].stime);
printf("请输入实验学时:");
scanf("%d",&course[p].ttime);
printf("请输入学分:");
scanf("%d",&course[p].score);
printf("请输入开课学期:");
scanf("%s",course[p].ktime);
csave(n);
}
break;
}
}
j=0;
break;
case 2:
system("cls");
menu2();
j=0;
break;
default:
printf("
您的输入有误,请重新输入:");
scanf("%d",&i);
j=1;
break;
}
}
}