展开全部
#include
#include
#include
#define N 20
#define M 100
struct Information
{
char bianhao[N];
char mingcheng[N];
int zongxueshi;
float xuefen;
int kaikexueqi;
}lesson[M];
int n;
FILE *fp;
void add() /*定义录入功能函数*/
{
int i;
printf("\n请输入录入课程信息的总数:");
scanf("%d",&n);
fp=fopen("e:\\111.txt","wb+");
for (i=1;i<=n;i++)
{
printf("\n\t请输入第%d个课程的32313133353236313431303231363533e4b893e5b19e31333337383336编号(10s):",i);
scanf("%s",lesson[i-1].bianhao);
printf("\n\t请输入第%d个课程的名称(10s):",i);
scanf("%10s",lesson[i-1].mingcheng);
printf("\n\t请输入第%d个课程的总学时(d):",i);
scanf("%5d",&lesson[i-1].zongxueshi);
printf("\n\t请输入第%d个课程的学分(f):",i);
scanf("%f",&lesson[i-1].xuefen);
printf("\n\t请输入第%d个课程的开课学期(d):",i);
scanf("%d",&lesson[i-1].kaikexueqi);
printf("\n\t提示:您已成功录入第%d条信息\n",i);
fwrite(&lesson[i-1],sizeof(struct Information),1,fp);
}
}
void scan() /*定义浏览功能函数*/
{
int i;
printf("\n\t 显示所有浏览设备信息:");
printf("\n编号\t名称\t总学时\t学分\t开课学期");
fp=fopen("e:\\111.txt","rb");
for (i=0;i
{
fread(&lesson[i],sizeof(struct Information),1,fp);
printf("\n%s,%8s,%5d,\t%.2f,%8d",lesson[i].bianhao,
lesson[i].mingcheng,lesson[i].zongxueshi,lesson[i].xuefen,lesson[i].kaikexueqi);
}
rewind(fp);
fclose(fp);
printf("\n");
}
void search() /*定义查询功能函数*/
{
int i,b,c;
do
{
float search;
char find[20];
fp=fopen("e:\\111.txt","rb");
printf("\n\t请选择查询方式:1.根据学分;2.根据课程编号;3.根据课程名称");
scanf("%d",&b);
switch (b)
{
case 1:
printf("\n**请输入课程的学分:");
scanf("%f",&search);
printf("\n编号\t名称\t总学时\t学分\t开课学期");
for(i=0;i
{
if (lesson[i].xuefen==search)
{
printf("\n%s,%8s,%5d,\t%.2f,%8d",lesson[i].bianhao,
lesson[i].mingcheng,lesson[i].zongxueshi,lesson[i].xuefen,lesson[i].kaikexueqi);
}
}goto B;
case 2:
printf("\n**请输入课程的编号:");
scanf("%s",find);
printf("\n编号\t名称\t总学时\t学分\t开课学期");
for(i=0;i
{
if (!strcmp(lesson[i].bianhao,find))
{
printf("\n%s,%8s,%5d,\t%.2f,%8d",lesson[i].bianhao,
lesson[i].mingcheng,lesson[i].zongxueshi,lesson[i].xuefen,lesson[i].kaikexueqi);
}
}goto B;
case 3:
printf("\n**请输入课程的名称:");
scanf("%s",find);
printf("\n编号\t名称\t总学时\t学分\t开课学期");
for(i=0;i
{
if (!strcmp(lesson[i].mingcheng,find))
{
printf("\n%s,%8s,%5d,\t%.2f,%8d",lesson[i].bianhao,
lesson[i].mingcheng,lesson[i].zongxueshi,lesson[i].xuefen,lesson[i].kaikexueqi);
}
}goto B;
default:printf("输入错误,请重新输入:\n");
}
B:fclose(fp);
printf("\n\t**1.继续\n\t**0.返回主菜单");
printf("\n\t 请输入您的选择:");
scanf("%d",&c);
}while (c);
}
void correct() /*定义修改功能函数*/
{
int i;
char find[20];
printf("\n**请输入您修改课程的名称:");
scanf("%s",find);
for(i=0;i
if (strcmp(lesson[i].mingcheng,find)==0)
{
char news[20];
printf("\n**请输入您要修改的课程信息:\n");
printf("\n\t请重新输入第%d个课程编号(10s):",i+1);
scanf("%s",news);strcpy(lesson[i].bianhao,news);
printf("\n\t请重新输入第%d个课程名称(10s):",i+1);
scanf("%s",news);strcpy(lesson[i].mingcheng,news);
printf("\n\t请重新输入第%d个课程总学时(d):",i+1);
scanf("%d",&lesson[i].zongxueshi);
printf("\n\t请重新输入第%d个课程学分(f):",i+1);
scanf("%f",&lesson[i].xuefen);
printf("\n\t请重新输入第%d个课程开课学期(d):",i+1);
scanf("%d",&lesson[i].kaikexueqi);
printf("\n\t提示:您已成功修改信息\n");
fp=fopen("e:\\steven.txt","a+");
rewind(fp);
fwrite(&lesson[i-1],sizeof(struct Information),1,fp);
}
}
void del() /*定义删除功能函数*/
{
char find[20];
int i;
printf("\n**请输入您删除课程的名称:");
scanf("%s",find);
for(i=0;i
if (strcmp(lesson[i].mingcheng,find)==0)
{
strcpy(lesson[i].bianhao,lesson[i+1].bianhao);
strcpy(lesson[i].mingcheng,lesson[i+1].mingcheng);
lesson[i].zongxueshi=lesson[i+1].zongxueshi;
lesson[i].xuefen=lesson[i+1].xuefen;
lesson[i].kaikexueqi=lesson[i+1].kaikexueqi;
}
printf("\n***提示:您已成功删除该设备信息!");
n=n-1;
}
void menu() /*定义主菜单功能*/
{
printf("\n\t\t *********欢迎进入课程管理系统!*******");
printf("\n\t\t***1.录入功能");
printf("\t\t\t2.浏览功能");
printf("\n\t\t***3.查询功能");
printf("\t\t\t4.修改功能");
printf("\n\t\t***5.删除功能");
printf("\t\t\t0.*-EXIT-*");
printf("\n\n\t 请输入您的选择:");
}
void main()
{
int a;
C:menu();
scanf("%d",&a);
switch(a)
{
case 0:printf("***正在退出**谢谢使用本系统,再见");break;
case 1:add();goto C; /*录入功能*/
case 2:scan();goto C; /*浏览功能*/
case 3:search();goto C; /*查询功能*/
case 4:correct();goto C; /*修改功能*/
case 5:del();goto C; /*删除功能*/
}
}