You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
This file contains ambiguous Unicode characters that may be confused with others in your current locale. If your use case is intentional and legitimate, you can safely ignore this warning. Use the Escape button to highlight these characters.
# include <stdio.h>
# include <malloc.h>
# include <stdlib.h>
# include <string.h>
# define SIZE_STU 10
# define SIZE_COU 10
# define SIZE_SEL 10
//////////////函数声明部分
void home ( void ) ;
void stu_operate ( void ) ;
void cou_operate ( void ) ;
void statistic ( void ) ;
void choose ( void ) ;
void delete_sel ( int ) ;
//--学生信息部分:
void input_stu ( void ) ;
void search_stu ( void ) ;
void search_stu_id ( void ) ;
void search_stu_name ( void ) ;
void show_stu ( void ) ;
void edit_stu ( void ) ;
void renew_stu ( void ) ;
void delete_stu ( void ) ;
//--课程信息部分:
void input_cou ( void ) ;
void search_cou ( void ) ;
void search_cou_id ( void ) ;
void search_cou_name ( void ) ;
void show_cou ( void ) ;
void edit_cou ( void ) ;
void renew_cou ( void ) ;
void delete_cou ( void ) ;
/*学生信息结构体*/
struct student_info {
char stu_ID [ 9 ] ;
char stu_name [ 5 ] ;
char sex [ 9 ] ;
char age [ 9 ] ;
char collage [ 9 ] ;
char grade [ 9 ] ;
char contact [ 9 ] ;
} stu [ SIZE_STU ] ;
/*课程信息结构体*/
struct course_info {
char course_ID [ 9 ] ;
char course_name [ 9 ] ;
char property [ 9 ] ;
char period [ 9 ] ;
char credit [ 9 ] ;
char time [ 9 ] ;
int people ;
} cou [ SIZE_COU ] ;
/*选课记录结构体*/
struct select {
int s ; //存放学生信息的数组下标
int c ; //存放课程信息的数组下标
} sel [ SIZE_SEL ] ;
//全局变量i,j,x分别是学生,课程,选课信息数组下标
int i = - 1 ;
int j = - 1 ;
int x = - 1 ;
int main ( void ) {
//进入欢迎界面
home ( ) ;
return 0 ;
}
//欢迎界面
void home ( void ) {
printf ( " \n ------------------------欢迎进入湖南工业大学学生选课系统!---------------------- " ) ;
int h ;
printf ( " \n \n 请选择你要进行的操作: " ) ;
printf ( " \n \n 1.学生操作 " ) ;
printf ( " \n 2.课程操作 " ) ;
printf ( " \n 3.开始选课 " ) ;
printf ( " \n 4.选课统计 " ) ;
printf ( " \n 5.退出系统 " ) ;
printf ( " \n " ) ;
printf ( " \n 请输入: " ) ;
scanf ( " %d " , & h ) ;
system ( " cls " ) ;
switch ( h ) {
case 1 :
stu_operate ( ) ;
break ;
case 2 :
cou_operate ( ) ;
break ;
case 3 :
choose ( ) ;
break ;
case 4 :
statistic ( ) ;
break ;
default :
system ( " cls " ) ;
printf ( " BYE! " ) ;
break ;
}
}
/*开始选课*/
void choose ( void ) {
char stu_id [ 10 ] , cou_id [ 10 ] ;
printf ( " \n ------------------------欢迎进入湖南工业大学学生选课系统!---------------------- " ) ;
//输入选课学生信息
printf ( " \n \n 请输入选课人学号: " ) ;
fflush ( stdin ) ;
scanf ( " %s " , stu_id ) ;
int h , flag = 0 ;
for ( h = 0 ; h < = i ; h + + ) {
if ( strcmp ( stu [ h ] . stu_ID , stu_id ) = = 0 ) {
flag = 0 ;
break ;
} else {
flag = 1 ;
}
}
if ( flag | | i = = - 1 ) {
printf ( " \n 不存在此学号 \n " ) ;
system ( " pause " ) ;
system ( " cls " ) ;
home ( ) ;
}
//录入姓名信息
x + + ;
sel [ x ] . s = h ;
//输入课程信息
printf ( " \n \n 请输入选修课程号: " ) ;
fflush ( stdin ) ;
scanf ( " %s " , cou_id ) ;
flag = 0 ;
for ( h = 0 ; h < = j ; h + + ) {
if ( strcmp ( cou [ h ] . course_ID , cou_id ) = = 0 ) {
flag = 0 ;
break ;
} else {
flag = 1 ;
}
}
if ( flag | | j = = - 1 ) {
printf ( " \n 不存在此课程号 \n " ) ;
x - - ;
system ( " pause " ) ;
system ( " cls " ) ;
home ( ) ;
}
//录入课程信息
sel [ x ] . c = h ;
cou [ h ] . people + + ;
printf ( " \n 录入成功! \n " ) ;
system ( " pause " ) ;
system ( " cls " ) ;
home ( ) ;
}
/*删除选课记录*/
void delete_sel ( int q ) { //删除第q+1条记录
/*注意! 本函数没有将x减1, 请在函数外手动减1( 考虑外层函数循环的需要) */
int h ;
cou [ sel [ q ] . c ] . people - - ;
for ( h = q ; q < x ; h + + ) {
q + + ;
sel [ h ] . c = sel [ q ] . c ;
sel [ h ] . s = sel [ q ] . s ;
}
}
//对学生记录进行操作
void stu_operate ( void ) {
printf ( " \n ------------------------欢迎进入湖南工业大学学生选课系统!---------------------- " ) ;
printf ( " \n \n 请选择你要对学生记录进行的操作: " ) ;
printf ( " \n \n 1.添加 " ) ;
printf ( " \n 2.查询 " ) ;
printf ( " \n 3.显示 " ) ;
printf ( " \n 4.返回主页面 " ) ;
printf ( " \n " ) ;
printf ( " \n 请输入: " ) ;
int i ;
scanf ( " %d " , & i ) ;
system ( " cls " ) ;
switch ( i ) {
case 1 : //添加学生信息
input_stu ( ) ;
break ;
case 2 : //查询学生信息
search_stu ( ) ;
break ;
case 3 : //显示所有学生信息
show_stu ( ) ;
break ;
case 4 :
home ( ) ;
break ;
}
}