c語言設計學生管理系統
『壹』 c語言學生信息管理系統代碼
代碼如下:
#include<stdio.h>
#include<malloc.h>
#include<stdlib.h>
#include<string.h>
#include<conio.h>
typedef struct examinee //考生信息結構
{ char examno[20]; //准考證號
char name[10]; //姓名
char sex[4]; //性別
short age; //年齡
char examtype[10]; //報考科目
}ElemType;
typedef struct Node //定義鏈表結點
{
ElemType data; //數據域
struct Node *next; //指針域
}Node,*List,*position;
List make_empty( List L ); //創建一個帶頭結點的空表
int is_empty( List L ); //測試鏈表是否是空表
int is_last( position p, List L ); //測試當前位置是否是表尾
position make_node( position p,int n ); //創建結點並輸入考生信息
void put_information( position p ); //是否輸出該考生信息
void put_name_information( List L ); //輸出姓名為xx的考生信息
int put_pos_information( position p ); //輸出該地址考生信息
void link_to_tail( List L, position p ); //將結點連接到表尾
int ciculation_make(); //循環創建考生信息
int judge_put_all(); //是否輸出所有考生信息
void put_all(List L); //輸出所有考生信息。
position find( List L ); //查找第一個姓名為xx的元素並返回位置
position find_previous( List L ); //查找第一個姓名為xx的元素並返回該元素直接前驅的位置
//int judge_delete_val(); //詢問是否刪除考生數據
int delete_val( List L ); //刪除指定考生信息並輸出其信息
void menu(List L); //菜單函數
List L;
//position p;
int
main( void )
{
List L = NULL; //定義頭結點指針
position p = NULL; //定義表工作指針
L = make_empty( L ); //創建空表
printf(" ★★考生報名管理程序★★
----------------------------------------
");
menu(L);
return 0;
}
//創建一個帶頭結點的空表
List
make_empty( List L)
{
L = ( List ) malloc (sizeof( Node ));
if(NULL == L)
{
printf("內存分配失敗");
exit( 1 );
}
L->next = NULL;
//printf("空表創建成功。
");
return L;
}
//創建結點並輸入考生信息
position
make_node( position p ,int n)
{
if(n) //n為1是創建結點並輸入,n為0是修改
{
p = ( position ) malloc ( sizeof ( Node ));
p->next = NULL ;
}
printf("請輸入考生准考證號:");
gets(p->data.examno);
printf("請輸入考生姓名:");
gets(p->data.name);
do
{
printf("請輸入考生性別,只能輸入「男」或者「女」:");
gets(p->data.sex);
}
while( 0 != strcmp( p->data.sex, "男" ) && 0 != strcmp( p->data.sex, "女" )); //判斷性別是否有誤
printf("請輸入考生年齡:");
scanf("%hd",&p->data.age);
getchar(); //如果把這句刪掉,就「無法執行」下面的報考類別
/*下面的do while用來判斷報考類別是否輸入有誤*/
do
{
printf("請輸入報考類別,只能輸入「數學」或「英語」或者「數據結構」:");
gets(p->data.examtype);
}
while( 0 != strcmp( "英語", p->data.examtype ) && 0 != strcmp( "數學", p->data.examtype ) && 0 != strcmp( "數據結構", p->data.examtype ));
if(n)
{
printf("報名成功
");
}
else
{
printf("修改成功
");
}
return p;
}
//前插法;
void
link_to_tail( List L, position p)
{
p->next = L->next;
L->next = p;
}
//查找第一個姓名為xx的元素並返回位置
position
find( List L )
{
position p = L->next;
char name[10];
printf("請輸入你要查找的考生姓名:");
gets(name);
while( p != NULL && 0 != strcmp( p->data.name , name))
{
p=p->next;
}
return p;
}
//測試鏈表是否是空表
int
is_empty( List L )
{
return L->next == NULL;
}
//測試當前位置是否是表尾
int
is_last( position p, List L )
{
return p->next == NULL;
}
//輸出姓名為xx的考生信息
void
put_name_information( List L )
{
position p = find(L);
if(p!=NULL)
{
printf("您要查找的考生信息:
");
printf("准考證號:%s 姓名:%s 性別:%s 年齡:%hd 報考科目:%s
",p->data.examno,p->data.name,p->data.sex,p->data.age,p->data.examtype);
}
else
{
printf("沒有您要找的學生。
");
}
}
//循環創建考生信息
int
ciculation_make()
{
int n = 2;
do
{
printf("是否繼續創建考生信息?是請輸入「1」,不是請輸入「0」:");
scanf("%d",&n);
getchar();
}
while( n != 0 && n != 1);
return n;
}
//是否輸出考生信息
void
put_information( position p )
{
int n=2;
do
{
printf("是否輸出該考生信息?是請輸入「1」,不是請輸入「0」:");
scanf("%d",&n);
getchar();
}
while( n != 0 && n != 1);
if(n)
{
printf("准考證號:%s 姓名:%s 性別:%s 年齡:%hd 報考科目:%s
",p->data.examno,p->data.name,p->data.sex,p->data.age,p->data.examtype);
}
}
//是否輸出所有考生信息
int
judge_put_all()
{
int n = 2;
do
{
printf("是否輸出所有考生信息?是請輸入「1」,不是請輸入「0」:");
scanf("%d",&n);
getchar();
}
while( n != 0 && n != 1);
return n;
}
//輸出所有考生信息
void
put_all(List L)
{
if(L->next == NULL)
{
printf("現無考生報名!
");
}
else
{
position p=L->next;
while( p != NULL )
{
printf("准考證號:%s 姓名:%s 性別:%s 年齡:%hd 報考科目:%s
",p->data.examno,p->data.name,p->data.sex,p->data.age,p->data.examtype);
p=p->next;
}
}
//getchar();
}
//詢問是否刪除考生數據
int
judge_delete_val()
{
int n = 2;
do
{
printf("是否要刪除某個考生數據?是請輸入「1」,不是輸入「0」:");
scanf("%d",&n);
getchar();
}
while( n != 0 && n != 1);
return n;
}
//查找第一個姓名為xx的元素並返回其直接前驅的位置
position
find_previous( List L )
{
position q = L;
position p = L->next;
char name[10];
printf("請輸入你要查找的考生姓名:");
gets(name);
while( p != NULL && 0 != strcmp( p->data.name , name))
{
q=p;
p=p->next;
}
if( p != NULL )
{
return q;
}
else
return p;
}
//刪除指定考生信息並輸出其信息
int
delete_val(List L)
{
int n=2;
position q=NULL;
position p=find_previous( L ); //返回考生信息地址
if( NULL == p )
{
printf("你要刪除的考生不存在
");
return 0;
}
else
{
q = p->next;
p->next = q->next;
printf("刪除成功。
刪除的考生信息為:
");
printf("准考證號:%s 姓名:%s 性別:%s 年齡:%hd 報考科目:%s
",q->data.examno,q->data.name,q->data.sex,q->data.age,q->data.examtype);
free(q);
return 1;
}
}
//輸出該地址考試信息
int
put_pos_information( position p )
{
if(p != NULL )
{
printf("准考證號:%s 姓名:%s 性別:%s 年齡:%hd 報考科目:%s
",p->data.examno,p->data.name,p->data.sex,p->data.age,p->data.examtype);
return 1;
}
else
{
printf("沒有您要查找的學生。");
return 0;
}
}
//菜單函數
void
menu(List L)
{
printf(" a. 考生報名入口
");
printf(" b. 查詢考生信息
");
printf(" c. 修改考生信息
");
printf(" d. 刪除考生信息
");
printf(" e. 全部考生信息
");
printf(" f. 程序作者信息
");
printf(" g. 退出程序
");
char n='h';
while(n != 'g')
{
do //確定正確輸入
{
printf("請通過字母序號選擇功能:");
n = getchar();
getchar();
putchar('
');
if( n < 'a' || n > 'g')
{
printf("錯誤的字母序號。
");
}
}
while( n < 'a' || n > 'g' );
switch (n)
{
case 'a':
{
printf("請輸入報名考生信息:
");
position p = make_node( p, 1 ); //創建新結點
link_to_tail( L, p ); //將新結點連接到表上
put_information( p ); //是否輸出該考生信息
putchar('
');
}
break;
case 'b':
{
put_name_information( L );
putchar('
');
}
break;
case 'c':
{
int n=0;
position p = NULL;
printf("您正在進行修改操作。
");
p = find(L);
n = put_pos_information( p );
if(n)
{
make_node( p , 0 );
put_information( p ); //是否輸出該考生信息
}
putchar('
');
}
break;
case 'd':
{
printf("您正在進行刪除操作。
");
delete_val( L );
putchar('
');
}
break;
case 'e':
{
put_all( L );
putchar('
');
}
break;
case 'f':
{
printf(" 修改日期 版本號 修改人 修改內容
");
printf(" --------------------------------------------------------
");
printf(" 2018.6.19 v2.0 陳百川 增加主菜單
");
printf(" 2018.6.23 v3.0 陳百川 增加生成文件功能
");
printf(" 該版本號為v2.0
");
putchar('
');
}
break;
default:
break;
}
}
printf(" 感謝本次使用,祝您生活愉快。");
getch();
}
(1)c語言設計學生管理系統擴展閱讀:
C語言是一門通用計算機編程語言,廣泛應用於底層開發。C語言的設計目標是提供一種能以簡易的方式編譯、處理低級存儲器、產生少量的機器碼以及不需要任何運行環境支持便能運行的編程語言。
盡管C語言提供了許多低級處理的功能,但仍然保持著良好跨平台的特性,以一個標准規格寫出的C語言程序可在許多電腦平台上進行編譯,甚至包含一些嵌入式處理器(單片機或稱MCU)以及超級電腦等作業平台。
二十世紀八十年代,為了避免各開發廠商用的C語言語法產生差異,由美國國家標准局為C語言制定了一套完整的美國國家標准語法,稱為ANSI C,作為C語言最初的標准。[1]目前2011年12月8日,國際標准化組織(ISO)和國際電工委員會(IEC)發布的C11標準是C語言的第三個官方標准,也是C語言的最新標准,該標准更好的支持了漢字函數名和漢字標識符,一定程度上實現了漢字編程。
C語言是一門面向過程的計算機編程語言,與C++,Java等面向對象的編程語言有所不同。
其編譯器主要有Clang、GCC、WIN-TC、SUBLIME、MSVC、Turbo C等。
參考資料:
網路——C語言
『貳』 C語言設計一個學生學籍管理系統,要求文件形式保存,且用到鏈表
#include<stdio.h>
#include<stdlib.h>
#include<string.h>
//鏈表結點結構體聲明
typedefstructsubjects
{
charname[20];
floatscore;
}sub;
typedefstructstudent
{
intnum;
charname[20];
subsubject[3];
structstudent*next;
}stu,*pstu;
#defineSIZEsizeof(stu)
//函數申明
pstuLoadInfo();
voidPrintMenu();
pstuAddStu(pstu);
pstuDeleStu(pstu);
pstuRwrStu(pstu);
voidFindStu(pstu,char);
voidCount(pstu,char*,float,float);
voidRank(pstu,char*);
voidSaveQuit(pstu);
//主函數
intmain()
{
floatscore1,score2;
charn,j;
charsubname[20];
pstuhead,ptr;
head=LoadInfo();
ptr=head->next;
//創建菜單,進入選擇循環
while(1)
{
PrintMenu();
printf("請輸入您的選擇編號:");
scanf("%d",&n);
getchar();
switch(n)
{
case1:
{
system("cls");
j=0;
while(4!=j)
{
printf("歡迎進入信息管理版塊! ");
printf("