源代码
# include <stdio.h>
# include <string.h>
# include <stdlib.h>
# include <malloc.h>
# include <conio.h>
typedef struct Score
{
char name[ 12 ] ;
long num;
int Chinese;
int Math;
int English;
int sum;
struct Score * next;
} Stu;
int count = 1 ;
void Welcome ( )
{
void Password ( ) ;
system ( "title C语言课程设计" ) ;
system ( "color E0" ) ;
printf ( "\t--------------------------------------\n" ) ;
printf ( "\t|*********【欢迎使用】***************| \n" ) ;
printf ( "\t|*******《C语言程序设计》课程设计****| \n" ) ;
printf ( "\t|*************学生成绩管理系统*******| \n" ) ;
printf ( "\t|************************************| \n" ) ;
printf ( "\t|************************************|\n" ) ;
printf ( "\t|************************************| \n" ) ;
printf ( "\t|程序设计; |\n" ) ;
printf ( "\t|专业; |\n" ) ;
printf ( "\t|班级; |\n" ) ;
printf ( "\t|姓名; |\n" ) ;
printf ( "\t|学号; |\n" ) ;
printf ( "\t--------------------------------------\n" ) ;
system ( "\t\tdate/t" ) ;
Password ( ) ;
}
void Password ( )
{
char password1[ 12 ] ;
char password2[ 12 ] = "39" ;
while ( 1 )
{
printf ( "请输入登入密码:" ) ;
scanf ( "%s" , password1) ;
if ( strcmp ( password1, password2) == 0 ) {
printf ( "登入成功!" ) ;
system ( "time/t\n" ) ;
system ( "cls" ) ;
break ;
} else {
printf ( "密码错误,请重新登入!" ) ;
system ( "time/t\n" ) ;
}
}
}
int Count ( Stu * head)
{
Stu * p = head;
int count = 1 ;
while ( p!= NULL )
{
count++ ;
p = p-> next;
}
return count;
}
void PrintMessage ( Stu * head)
{
Stu * p = head;
printf ( "\t号数\t姓名\t\t语文成绩\t数学成绩\t英语成绩\t总分\n" ) ;
while ( p != NULL )
{
printf ( "\t%ld\t%s\t\t%d\t\t%d\t\t%d\t\t%d\n" , p-> num, p-> name, p-> Chinese, p-> Math, p-> English, p-> sum) ;
p = p-> next;
}
}
Stu * AddNode ( Stu * head, Stu * newNode)
{
Stu * p = head;
if ( p == NULL )
{
head = newNode;
printf ( "------------------\n" ) ;
return head;
}
while ( p-> next != NULL )
{
p = p-> next;
}
p-> next = newNode;
printf ( "===================\n" ) ;
return head;
}
int CheckNum ( Stu * head, long num)
{
Stu * p = head;
int mark = 0 ;
while ( p != NULL )
{
if ( num == p-> num ) {
printf ( "学号重复,请重新输入!\n" ) ;
mark = 1 ;
}
p = p-> next;
}
return mark;
}
Stu * InputMessage ( Stu * head)
{
int mark = 0 ;
while ( 1 )
{
Stu * newNode = ( Stu * ) malloc ( sizeof ( Stu) ) ;
count = Count ( head) ;
printf ( "请输入第%d个学生信息:\n" , count) ;
printf ( "请输入学号(结束请输入0):" ) ;
scanf ( "%ld" , & newNode-> num) ;
mark = CheckNum ( head, newNode-> num) ;
if ( mark == 0 ) {
if ( newNode-> num == 0 ) {
printf ( "总人数:%d\n" , count- 1 ) ;
free ( newNode) ;
PrintMessage ( head) ;
system ( "pause" ) ;
return head;
}
printf ( "请输入姓名:" ) ;
scanf ( "%s" , newNode-> name) ;
printf ( "请输入语文成绩:" ) ;
scanf ( "%d" , & newNode-> Chinese) ;
printf ( "请输入数学成绩:" ) ;
scanf ( "%d" , & newNode-> Math) ;
printf ( "请输入英语成绩:" ) ;
scanf ( "%d" , & newNode-> English) ;
newNode-> sum = newNode-> Chinese+ newNode-> Math+ newNode-> English;
newNode-> next = NULL ;
head = AddNode ( head, newNode) ;
}
}
}
void * Search_Name ( Stu * head)
{
int mark = 0 ;
Stu * p = head;
char name[ 12 ] ;
printf ( "请输入要查找的学生姓名:" ) ;
scanf ( "%s" , name) ;
while ( p!= NULL )
{
if ( strcmp ( p-> name, name) == 0 ) {
printf ( "\t号数\t姓名\t\t语文成绩\t数学成绩\t英语成绩\t总分\n" ) ;
printf ( "\t%ld\t%s\t\t%d\t\t%d\t\t%d\t\t%d\n" , p-> num, p-> name, p-> Chinese, p-> Math, p-> English, p-> sum) ;
mark = 1 ;
}
p = p-> next;
}
if ( mark == 1 ) {
char c;
printf ( "是否继续查找(Y(y)/N(n)):" ) ;
c = getche ( ) ;
printf ( "\n" ) ;
if ( c == 'Y' || c == 'y' ) {
Search_Name ( head) ;
}
}
if ( mark == 0 ) {
printf ( "没有该学生信息,请重新查找!\n" ) ;
Search_Name ( head) ;
}
}
void * Search_Num ( Stu * head)
{
int mark = 0 ;
char c;
Stu * p = head;
long num;
printf ( "请输入要查找的学生学号:" ) ;
scanf ( "%ld" , & num) ;
while ( p!= NULL )
{
if ( p-> num == num) {
printf ( "\t号数\t姓名\t\t语文成绩\t数学成绩\t英语成绩\t总分\n" ) ;
printf ( "\t%ld\t%s\t\t%d\t\t%d\t\t%d\t\t%d\n" , p-> num, p-> name, p-> Chinese, p-> Math, p-> English, p-> sum) ;
mark = 1 ;
printf ( "是否继续查找(Y(y)/N(n)):" ) ;
c = getche ( ) ;
printf ( "\n" ) ;
if ( c == 'Y' || c == 'y' ) {
Search_Num ( head) ;
}
}
p = p-> next;
}
if ( mark == 0 ) {
printf ( "没有该学生信息,请重新查找\n" ) ;
Search_Num ( head) ;
}
}
void SearchMessage ( Stu * head)
{
void Menu ( Stu * head) ;
Stu * p = head;
printf ( "\t1.按姓名查找 \n" ) ;
printf ( "\t2.按学号查找 \n" ) ;
printf ( "\t3.返回主菜单\n" ) ;
printf ( "请选择菜单选项(1~3):" ) ;
switch ( getche ( ) )
{
case '1' :
system ( "cls" ) ;
Search_Name ( head) ;
system ( "pause" ) ;
system ( "cls" ) ;
SearchMessage ( head) ;
system ( "pause" ) ;
break ;
case '2' :
system ( "cls" ) ;
Search_Num ( head) ;
system ( "pause" ) ;
system ( "cls" ) ;
SearchMessage ( head) ;
system ( "pause" ) ;
break ;
case '3' :
system ( "cls" ) ;
Menu ( head) ;
break ;
default :
system ( "cls" ) ;
SearchMessage ( head) ;
}
}
void OutputAll ( Stu * head)
{
Stu * p = head;
printf ( "\t号数\t姓名\t\t语文成绩\t数学成绩\t英语成绩\t总分\n" ) ;
while ( p!= NULL )
{
printf ( "\t%ld\t%s\t\t%d\t\t%d\t\t%d\t\t%d\n" , p-> num, p-> name, p-> Chinese, p-> Math, p-> English, p-> sum) ;
p = p-> next;
}
}
void OutputA ( Stu * head)
{
Stu * p = head;
printf ( "\t号数\t姓名\t\t语文成绩\t数学成绩\t英语成绩\t总分\n" ) ;
while ( p!= NULL )
{
if ( p-> Chinese >= 90 ) {
printf ( "\t%ld\t%s\t\t%d\n" , p-> num, p-> name, p-> Chinese) ;
}
if ( p-> Math >= 90 )