只添加了一个功能,如果你上线的话给我留言 我不太理解题目的意思
#include
#include
#include
#include
int count = 0;
int cou = 0;
int choose = 0; //用于统计数组个数
/*================定义函数===============*/
void allput(); //把数组整体排序输出
void insert(); //插入新课程
void search(); //搜索指定课程
void search_();//按学分查询
void delete_(); //删除指定课程
void select(); //选课
void change(); //修改指定课程
void baocun(); //保存,把修改后的数组重新装入文件
void into(); //验证密码
struct subject_list{
char num[15]; //装课程编号
char name[30]; //装课程名称
char xingzhi[10]; //装课程性质
int xueshi;
float xuefen; //分别装学时、学分
}sub[100];
/*================================主函数================================*/
void main()
{
int i=0;
system("color df");
printf("\n\n\n\n\n\n\n\n\n\n\t 正在启动系统>>>> >>>> >>>>\t\n\n\n\n\n\n\n\n\n\n");
for(i=0;i<100000000;i++);
system("cls");
system("color 1f");
/*———————————————————主体框架——系统操作———————————————————————*/
do{
system("cls");
printf("\n\n");
printf("==============================欢迎进入学生选课系统==============================\n");
printf(" __________________学生选课系统功能选项:__________________ \n");
printf(" | 1. 看所有课程信息 |\n");
printf(" | 2. 搜索指定课程信息 |\n");
printf(" | 3. 添加课程信息 |\n");
printf(" | 4. 删除课程信息 |\n");
printf(" | 5. 修改课程信息 |\n");
printf(" | 6. 选课 |\n");
printf(" | 8.按学分查询 |\n");
printf(" |________________________7. 退出___________________________|\n");
printf("*******************************************************************************\n");
printf("请选择功能:");
scanf("%d",&choose);
printf("--------------------------------------\n");
/* 建立分支选择功能选项 */
switch(choose){
case 1: allput(); break; //=================〉引用函数排序输出
case 2: search(); break; //=================〉引用搜索函数
case 3: insert(); break; //=================〉引用插入函数
case 4: delete_(); break; //=================〉引用删除函数
case 5: change(); break; //=================〉引用函数修改内容
case 6: select(); break; //=================〉引用选课函数
case 8: search_(); break;
case 7: printf("谢谢使用!再见!\n"); exit(0); //=================〉退出
default: printf("请重新输入\n"); break;
}
printf("--------------------------------------------------------------------------------\n");
printf(" 按任意键返回首层\n");
getch();
}while(choose != 7);
}
/*=============把数组整体排序输出================*/
void allput()
{
int i,j,xueshi;
char num[15],name[15],xingzhi[10];
float xuefen;
/* 冒泡排序 */
for(i=1;i
{
strcpy(num,sub[i].num);
strcpy(name,sub[i].name);
strcpy(xingzhi,sub[i].xingzhi);
xueshi = sub[i].xueshi;
xuefen = sub[i].xuefen;
strcpy(sub[i].num,sub[i+1].num);
strcpy(sub[i].name,sub[i+1].name);
strcpy(sub[i].xingzhi,sub[i+1].xingzhi);
sub[i].xueshi = sub[i+1].xueshi;
sub[i].xuefen = sub[i+1].xuefen;
strcpy(sub[i+1].num,num);
strcpy(sub[i+1].name,name);
strcpy(sub[i+1].xingzhi,xingzhi);
sub[i+1].xueshi = xueshi;
sub[i+1].xuefen = xuefen;
}
/* 输出查找到的信息 */
printf("课程编号\t课程名称\t课程性质\t学时\t学分\n");
for(i=0;i
baocun(); //把排序后的数组重新写入文件
}
/*========================================查看指定课程信息=====================================*/
void search()
{
char num[15];
int i,flag=0;
do{
printf("请输入课程编号:");
scanf("%s",num);
for(i=0;i
flag = 1;
break;
}
}
/* 输出查找到的信息 */
if(flag){
printf("课程编号\t课程名称\t课程性质\t学时\t学分\n");
printf("%s\t %s\t %s\t %d\t%.1f\n",sub[i].num,sub[i].name,sub[i].xingzhi,sub[i].xueshi,sub[i].xuefen);
}
else{
printf("无此课程!1:重新输入;2.返回\n");
printf("~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~\n");
printf("请输入:");
scanf("%d",&choose);
printf("~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~\n");
}
if(choose!=1) return;
}while(flag==0);
}
/*=============================================按学分查询===========================================*/
void search_()
{
float f;
int i,flag=0,j=0;
do{
printf("请输入课程学分数:");
scanf("%f",&f);
for(i=0;i
if(j==0)printf("课程编号\t课程名称\t课程性质\t学时\t学分\n");
printf("%s\t %s\t %s\t %d\t%.1f\n",sub[i].num,sub[i].name,sub[i].xingzhi,sub[i].xueshi,sub[i].xuefen);
flag = 1;
j++;
}
}
/* 输出查找到的信息 */
if(flag==0){
printf("无此课程!1:重新输入;2.返回\n");
printf("~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~\n");
printf("请输入:");
scanf("%d",&choose);
printf("~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~\n");
}
if(choose!=1) return;
}while(flag==0);
}
/*=============================================选课===========================================*/
void select()
{
char stu[15],num_[15];
int i,flag=0;
FILE *fp_;
fp_=fopen("d:\\SelectInfo.txt","a");
if(fp_== NULL){
printf("File open error!\n");
exit(0);
}
do{
printf("请输入课程编号:");
scanf("%s",num_);
/* 判断要选课程是否存在 */
for(i=0;i
//strcpy(name,sub[i].name)
flag = 1;
break;
}
}
if(flag){
fprintf(fp_,"%s %s %s %d %1.f\n",sub[i].num,sub[i].name,sub[i].xingzhi,sub[i].xueshi,sub[i].xuefen);
printf("选课成功!\n");
/* 关闭文件 */
if(fclose(fp_)){
printf("Can not close the file!\n");
exit(0);
}
}
else{
printf("无此课程!1:重新输入;2.返回\n");
printf("~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~\n");
printf("请输入:");
scanf("%d",&choose);
printf("~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~\n");
}
if(choose!=1) return;
}while(flag==0);
}
/*=======================================添加课程=============================================*/
void insert()
{
int i,j,flag=0;
char num[15];
do{
flag = 0;
printf("请输入课程编号:");
scanf("%s",num);
/* 判断要添加课程是否存在 */
for(i=0;i
flag = 1;
break;
}
}
if(flag){
printf("此课程已存在!1:重新输入;2.返回\n");
printf("~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~\n");
printf("请输入:");
scanf("%d",&choose);
printf("~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~\n");
if(choose!=1) return;
}
else{
j=count;
for(i=0;i
strcpy(sub[j].num,sub[j-1].num); //后一项覆盖前一项
strcpy(sub[j].name,sub[j-1].name);
strcpy(sub[j].xingzhi,sub[j-1].xingzhi);
sub[j].xueshi = sub[j-1].xueshi;
sub[j].xuefen = sub[j-1].xuefen;
j--;
}
/* 输入要添加的信息 */
strcpy(sub[j].num,num);
printf("请输入课程名称:");
scanf("%s",sub[j].name);
printf("请输入课程性质:");
scanf("%s",sub[j].xingzhi);
printf("请输入学时:");
scanf("%d",&sub[j].xueshi);
printf("请输入学分:");
scanf("%f",&sub[j].xuefen);
count++;
baocun();
printf("添加成功!\n");
}
}while(flag==1);
}
/*=======================================删除课程===============================================*/
void delete_()
{
char num[15];
int i,j,flag=0;
do{
printf("请输入课程编号:");
scanf("%s",num);
for(i=0;i
flag = 1;
break;
}
if(flag){
for(j=i;j
strcpy(sub[j].name,sub[j+1].name);
strcpy(sub[j].xingzhi,sub[j+1].xingzhi);
sub[j].xueshi = sub[j+1].xueshi;
sub[j].xuefen = sub[j+1].xuefen;
}
count--;
baocun(); //引用保存函数
printf("删除成功!\n");
}
else{
printf("无此课程!1:重新输入;2:返回\n");
printf("~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~\n");
printf("请输入:");
scanf("%d",&choose);
printf("~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~\n");
}
if(choose!=1) return;
}while(flag==0);
}
/*===========================================修改课程==========================================*/
void change()
{
char num[15];
int i,flag=0;
do{
printf("请输入课程编号:");
scanf("%s",num);
/* 判断要修改课程是否存在 */
for(i=0;i
flag = 1;
break;
}
if(flag){
printf("请输入修改后的课程名称:");
scanf("%s",sub[i].name);
printf("请输课程性质:");
scanf("%s",sub[i].xingzhi);
printf("请输入学时:");
scanf("%d",&sub[i].xueshi);
printf("请输入学分:");
scanf("%f",&sub[i].xuefen);
baocun(); //引用排序函数,重新写入文件
printf("修改成功!\n");
}
else{
printf("无此课程!1:重新输入;2.返回\n");
printf("~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~\n");
printf("请输入:");
scanf("%d",&choose);
printf("~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~\n");
}
if(choose!=1) return;
}while(flag==0);
}
/*============================================保存=============================================*/
void baocun()
{
int i;
FILE *fpp;
fpp = fopen("d:\\LessonInfo.txt","w");//这里这样改更好
/* 把数组装入文件 */
for(i=0;i
sub[i].num,sub[i].name,sub[i].xingzhi,sub[i].xueshi,sub[i].xuefen);
/* 关闭文件 */
if(fclose(fpp)){
printf("Can not close the file!\n");
exit(0);
}
}