学生课程管理程序(C语言)

更新时间:2024-06-09 18:54:01 阅读量: 综合文库 文档下载

说明:文章内容仅供预览,部分内容可能不全。下载后的文档,内容与下面显示的完全一致。下载之前请确认下面内容是否您想要的,是否完整无缺。

#include /*引用库函数*/ #include #include #include typedef struct

{ char name[20]; char num[10]; char time[10]; char quality[20]; char date[2]; char no[2]; }Student;

Student stud1[1000]; char s[10];

int menu_select() {char c; do{ system(\ printf(\★★★★★★学生课程管理系统★★★★★★\\n\ printf(\录入添加课程\\n\ printf(\浏览课程\\n\ printf(\按课程查找并删除\\n\ printf(\按课程性质查找课程\\n\ printf(\按课程学分查找课程\\n\ printf(\选课\\n\ printf(\浏览已选课程\\n\

printf(\从文件中读入数据\\n\ printf(\循环写入数据\\n\ printf(\退出程序\\n\

printf(\★★★★★★★★★★★★★★★★★★★★\\n\ printf(\请选择您要运行的选项按(0-9):\ c=getchar();

}while(c<'0'||c>'10'); return(c-'0'); }

int Input(Student stud[],int n=0) {int i=0;

char sign,x[10];

while(sign!='n'&&sign!='N') {printf(\课程编号:\ scanf(\ printf(\课程:\

scanf(\ printf(\课程性质:\

scanf(\ printf(\学分:\

scanf(\ printf(\学时:\

scanf(\ printf(\开课日期:\

scanf(\ gets(x);

printf(\是否继续输入?(Y/N)\ scanf(\

i++; n=n+i; }

return(n+i); }

int Input(char s[],int m=0) {int i=0;

char sign,x[10];

while(sign!='n'&&sign!='N')

{printf(\请输入你要选的课程编号:\ scanf(\ gets(x);

printf(\是否继续选课?(Y/N)\ scanf(\ i++; m=m+i; }

return(m+i); }

void Display_2(Student stud[],int n) {int i;

printf(\ /*格式头*/

printf(\课程编号 课程 课程性质 学分 学时 开学日期 \\n\printf(\for(i=1;i

{printf(\tud[i-1].num,stud[i-1].time,stud[i-1].date);

if(i>1&&i==0) /*每十个暂停*/

{printf(\ /*格式*/ printf(\ system(\

printf(\

} }

printf(\system(\}

void Display_1(Student stud[],int m ) {int i; int w;

printf(\ /*格式头*/

printf(\课程编号 课程 课程性质 学分 学时 开学日期 \\n\ printf(\ for(i=0;i

if(i>1&&i==0) /*每十个暂停*/

{printf(\ /*格式*/ printf(\ system(\

printf(\ } }

printf(\system(\}

int Delete_a_record(Student stud[],int n) {char s[20]; int i=0,j;

printf(\请输入要删除的课程\ scanf(\

while(strcmp(stud[i].name,s)!=0&&i

strcpy(stud[j].quality,stud[j+1].quality); strcpy(stud[j].num,stud[j+1].num); strcpy(stud[j].time,stud[j+1].time);

} printf(\删除课程成功!\\n\ return(n-1); }

void Query_a_record(Student stud[],int n) {char s[20]; int i=0;

printf(\请输入课程性质:\ scanf(\

loop:while(strcmp(stud[i].quality,s)!=0&&i

return; }

printf(\开课日期%s\\n\ printf(\课程%s\\n\ printf(\课程编号%s\\n\ printf(\学分%s\\n\

printf(\课程性质%s\\n\ printf(\学时%s\\n\

printf(\ i++;

goto loop; }

void Query_a_record1(Student stud[],int n) {char s[20]; int i=0;

printf(\请输入课程学分:\ scanf(\

loop:while(strcmp(stud[i].num,s)!=0&&i

return; }

printf(\开课日期%s\\n\ printf(\课程%s\\n\ printf(\课程编号%s\\n\ printf(\学分%s\\n\

printf(\课程性质%s\\n\ printf(\学时%s\\n\

printf(\ i++;

goto loop; }

int AddfromText(Student stud[],int n) /*从文件中读入数据*/ {

int i=0,num;

FILE *fp; /*定义文件指针*/ char filename[20]; /*定义文件名*/ printf(\输入文件名:\

scanf(\ /*输入文件名*/ if((fp=fopen(filename,\ /*打开文件*/ {

printf(\无法打开该文件\\n\ /*打开失败信息*/ printf(\ system(\ return(n); }

fscanf(fp,\ /*读入总记录量*/ while(i

fscanf(fp,\+i].date,stud[n+i].time); i++; }

n+=num;

fclose(fp); /*关闭文件*/ printf(\读入成功!\\n\ printf(\ system(\ return(n); }

void WritetoText(Student stud[],int n) /*将所有记录写入文件*/ {

int i=0;

FILE *fp; /*定义文件指针*/

char filename[100]; /*定义文件名*/ printf(\循环写入数据\\n\ /*输入文件名*/ printf(\输入文件名:\ scanf(\

if((fp=fopen(filename,\ /*打开文件*/ {

printf(\无法打开该文件\\n\ system(\ return;

}

fprintf(fp,\ /*循环写入数据*/ while(i

fprintf(fp,\ i++; }

fclose(fp); /*关闭文件*/

printf(\写入成功!\\n\ /*返回成功信息*/ }

void main() { int n=0; int m=0; for(;;) {switch(menu_select()) {case 1: printf(\录入添加课程\\n\ n=Input(stud1,n); break; case 2: printf(\浏览课程\\n\ Display_2(stud1,n); break; case 3:

printf(\按课程查找并删除\\n\

n=Delete_a_record(stud1,n); printf(\ system(\ break; case 4:

printf(\按课程性质查找课程\\n\ Query_a_record(stud1,n); printf(\ system(\ break; case 5:

printf(\按课程学分查找课程\\n\ Query_a_record1(stud1,n); printf(\ system(\ break;

/*按姓名查找,删除一条记录*/ case 6: printf(\选课\\n\ m=Input(s,m); break; case 7: printf(\浏览已选课程\\n\ Display_1(stud1,m); break; case 8:

printf(\从文件中读入数据\\n\

AddfromText(stud1,n); printf(\ system(\ break;

case 9:

printf(\循环写入数据\\n\

WritetoText(stud1,n); printf(\ system(\ break; case 0: printf(\欢迎使用\\n\ system(\ exit(0); } } }

/*从文件中读入数据*/ /*循环写入数据*/

本文来源:https://www.bwwdw.com/article/9lw6.html

Top