當前位置:首頁 » 編程語言 » c語言設計學生管理系統

c語言設計學生管理系統

發布時間: 2025-04-15 20:32:07

『壹』 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("251、添加學生 ");
printf("252、刪除學生 ");
printf("253、修改學生信息 ");
printf("254、返回 ");
printf("請輸入您的選擇編號: ");
scanf("%d",&j);
getchar();

if(1==j)head=AddStu(head);
elseif(2==j)head=DeleStu(head);
elseif(3==j)head=RwrStu(head);
elseif(4==j);
elseprintf("輸入有誤,請重新輸入! ");

}
printf("請輸入回車鍵返回主菜單!");//此處本意按任意鍵返回,但是任意鍵的話,需要按鍵A,再按回車確定
getchar(); //則會連續收到兩個按鍵,造成錯誤讀入,可以改進scanf接收字元串,
system("cls"); //以下所有getchar()、system("cls")同理
break;
}
case2:
{
//信息查詢
system("cls");
printf("歡迎進入信息查詢版塊! ");
printf("請輸入要查詢的學生編號:");
scanf("%d",&j);
getchar();
//printf("%d ",j); //檢測輸入是否成功,調試程序用
FindStu(head,j); //查詢並輸出
printf(" 請輸入回車鍵返回主菜單!");
getchar();
system("cls");
break;
}
case3:
{
//成績統計
system("cls");
printf("歡迎進入成績統計版塊! ");
printf("請輸入科目:");
scanf("%s",&subname);
getchar();
printf("請輸入分數范圍(score1,score2):");
scanf("%f,%f",&score1,&score2);
getchar();
/*printf("%s%5.2f%5.2f ",subname,
score1,score2);*///檢測輸入是否成功,調試程序用
Count(head,subname,score1,score2); //統計並輸出
printf("請輸入回車鍵返回主菜單!");
getchar();
system("cls");
break;
}
case4:
{
//成績排序
system("cls");
printf("歡迎進入成績排序版塊,請輸入科目:");
scanf("%s",&subname);
getchar();
Rank(head,subname); //排序並輸出
printf(" 請輸入回車鍵返回主菜單! ");
getchar();
system("cls");
break;
}
case5:
{
//保存退出
SaveQuit(head); //文件操作,保存並退出
free(head);
return0;
}
default:
{
printf("輸入有誤,按回車鍵重新選擇! "); //主菜單錯誤輸出檢測
getchar();
system("cls");
}
}
}


}

//載入data數據,文件操作
pstuLoadInfo()
{
intnum;
charname[20];
charsub1[20];
charsub2[20];
charsub3[20];
floatscore1;
floatscore2;
floatscore3;

charfilename[]="D:\編程學習\編程實踐\c語言課程設計1學生信息管理\data.txt";//文件名,此處為簡化編程,採用固定地址名稱,未作輸入
FILE*fp;
pstuhead,ptr;

//創建帶表頭結點的空單鏈表head,用來存放載入信息
head=(pstu)malloc(SIZE);
ptr=head;
ptr->next=NULL;


//載入data文件,存入head鏈表
if(NULL==(fp=fopen(filename,"r"))) //判斷文件是否存在及可讀
{
printf("error!");
exit(0);
}

while(!feof(fp))
{
fscanf(fp,"%d%s%s%f%s%f%s%f ",&num,&name,
&sub1,&score1,&sub2,&score2,&sub3,&score3);//讀取一行,採用格式化讀取,避免了其他各種讀取方法的數據處理問題
//該方法缺點明顯,對數據格式要求教研,故data文件規定數據格式
ptr->next=(pstu)malloc(SIZE);
ptr=ptr->next;
ptr->next=NULL;

ptr->num=num;
strcpy(ptr->name,name);
strcpy(ptr->subject[0].name,sub1);
ptr->subject[0].score=score1;
strcpy(ptr->subject[1].name,sub2);
ptr->subject[1].score=score2;
strcpy(ptr->subject[2].name,sub3);
ptr->subject[2].score=score3;

}

fclose(fp); //關閉文件,已得到保存data信息的鏈表head

returnhead;
}


//列印主菜單
voidPrintMenu()
{
printf("*************************************** ");
printf("楓楓學生信息管理系統 ");
printf("*************************************** ");
putchar(' ');
printf("菜單 ");
printf("251、信息管理 ");
printf("252、信息查詢 ");
printf("253、成績統計 ");
printf("254、成績排序 ");
printf("255、保存退出 ");
}

//添加學生
pstuAddStu(pstux)
{
charnamestu[20];
char*p;
charsubname1[20],subname2[20],subname3[20];
pstuhead,ptr;

head=x;
ptr=head;

while(NULL!=ptr->next) //遍歷鏈表,找到鏈尾結點
{
ptr=ptr->next;
}

ptr->next=(pstu)malloc(SIZE); //默認在鏈表末追加添加信息
ptr=ptr->next;
ptr->next=NULL;

printf("請輸入添加學生的信息: ");

printf("請輸入添加學生的學號:");
scanf("%d",&ptr->num);
getchar();

printf("請輸入添加學生的姓名:");
scanf("%s",namestu);
getchar();
p=namestu;
strcpy(ptr->name,p);

printf("請輸入添加學生的科目1名稱:");
scanf("%s",&subname1);
getchar();
p=subname1;
strcpy(ptr->subject[0].name,p);

printf("請輸入添加學生的科目1成績:");
scanf("%f",&ptr->subject[0].score);
getchar();

printf("請輸入添加學生的科目2名稱:");
scanf("%s",&subname2);
getchar();
p=subname2;
strcpy(ptr->subject[1].name,p);

printf("請輸入添加學生的科目2成績:");
scanf("%f",&ptr->subject[1].score);
getchar();

printf("請輸入添加學生的科目3名稱:");
scanf("%s",&subname3);
getchar();
p=subname3;
strcpy(ptr->subject[2].name,p);

printf("請輸入添加學生的科目3成績:");
scanf("%f",&ptr->subject[2].score);
getchar();

putchar(' ');
returnhead;
}

//刪除學生
pstuDeleStu(pstux)
{
intnum;
pstuhead,ptr,qtr;

head=x;
ptr=head->next;
qtr=head;

printf("請輸入要刪除的學生的學號:");
scanf("%d",&num);
getchar();

while(ptr!=NULL)
{
if(ptr->num!=num) //遍歷查找鏈表結點,未找到跳過該結點
{
ptr=ptr->next;
qtr=qtr->next;
}
else //找到則刪除結點
{
ptr=ptr->next;
qtr->next=ptr;
break;
}
}

printf("該學生信息已刪除! ");
returnhead;
}

//修改學生信息
pstuRwrStu(pstux)
{
charnamestu[20];
char*p;
charsubname1[20],subname2[20],subname3[20];
intnum;
pstuhead,ptr;

head=x;
ptr=head->next;

printf("請輸入要修改的學生的學號:");
scanf("%d",&num);
getchar();

while(ptr!=NULL)
{
if(ptr->num==num)
{
printf("已找到該學生信息,請填入修改項目:");

printf("請輸入修改學生的姓名:");
scanf("%s",namestu);
getchar();
p=namestu;
strcpy(ptr->name,p);

printf("請輸入修改學生的科目1名稱:");
scanf("%s",subname1);
getchar();
p=subname1;
strcpy(ptr->subject[0].name,p);

printf("請輸入修改學生的科目1成績:");
scanf("%f",&ptr->subject[0].score);
getchar();

printf("請輸入修改學生的科目2名稱:");
scanf("%s",subname2);
getchar();
p=subname2;
strcpy(ptr->subject[1].name,p);

printf("請輸入修改學生的科目2成績:");
scanf("%f",&ptr->subject[1].score);
getchar();

printf("請輸入修改學生的科目3名稱:");
scanf("%s",subname3);
getchar();
p=subname3;
strcpy(ptr->subject[2].name,p);

printf("請輸入修改學生的科目3成績:");
scanf("%f",&ptr->subject[2].score);
getchar();

printf("該學生信息已修改! ");
break;
}
else
{
ptr=ptr->next;
}
}

returnhead;
}

//查找學生,參數為鏈表指針,和學生學號
//不好,應該將學號輸入放進子函數,簡化主函數結構,減少子函數參數
voidFindStu(pstux,chary)
{
pstuhead,ptr;

head=x;
ptr=head->next;

while(ptr!=NULL)
{
if(ptr->num==(int)y) //因主函數中為節省空間,學號輸入採用char數據,故強行准換
{
printf("已找到該學生信息! 如下:");
printf("%03d%s%s%5.2f%s%5.2f%s%5.2f ",
ptr->num,ptr->name,ptr->subject[0].name,ptr->subject[0].score,ptr->subject[1].name,ptr->subject[1].score,ptr->subject[2].name,ptr->subject[2].score); break; //注意此處找到並輸出信息後要手動退出循環
}
else
{
ptr=ptr->next;
}
}
if(ptr==NULL) //查詢成功檢測,while循環中若找到,則ptr停留在當前學生的結點上
{
printf("未能找到該學生信息! ");
}
}


//統計科目分數區間段的學生,參數為鏈表指針,科目名稱,分數區間上下限
//同理,參數的錄入應放入子函數,簡化結構和編程
voidCount(pstux,char*y,floatq,floatp)
{
pstuhead,ptr;
charname[20];
charflag=0; //手動設置的查找結果flag

head=x;
ptr=head->next;
strcpy(name,y);

//printf("%s%5.2f%5.2f ",name,q,p); //檢測輸入參數的傳遞,調試程序用

while(ptr!=NULL) //開始查找統計,科目查找用strcmp函數比較科目字元串,返回值0為字元串相等
{ //此處while循環體中,重復的查找步驟太多,應設置科目匹配flag,參照rank()函數
if(strcmp(name,ptr->subject[0].name)==0) //通過flag將科目確認放在while之外,循環體內只做分數區間的掃描和輸出
{
if(q<=ptr->subject[0].score&&ptr->subject[0].score<=p)
{
printf("%03d%s%s%5.2f ",ptr->num,ptr->name,ptr->subject[0].name,ptr->subject[0].score);
flag++;
}
}
if(strcmp(name,ptr->subject[1].name)==0)
{
if(q<=ptr->subject[1].score&&ptr->subject[1].score<=p)
{
printf("%03d%s%s%5.2f ",ptr->num,ptr->name,ptr->subject[1].name,ptr->subject[1].score);
flag++;
}
}
if(strcmp(name,ptr->subject[2].name)==0)
{
if(q<=ptr->subject[2].score&&ptr->subject[2].score<=p)
{
printf("%03d%s%s%5.2f ",ptr->num,ptr->name,ptr->subject[2].name,ptr->subject[2].score);
flag++;
}
}

ptr=ptr->next;
}

if(flag==0)
{
printf("未能找到該課程該區間分數段的學生! ");
}
}


//學科成績排名,採用交換數據的方法,參數為鏈表指針,科目名稱
//同理參數問題
//鏈表排序問題,此處用交換結點數據方法,還有其他多種排序方法
//如,交換結點,輔助指針數組排序(未實現,過程繁雜),插入法排序等
voidRank(pstux,char*y)
{
pstuhead,ptr,qtr;
charname[20];
charlen=0;
charflag=0; //簡化演算法,設置科目查找結果判斷值,flag=0表示科目輸入為未知科目,不存在
inti=0; //i、j循環次數控制參數
intj=0;
chartemp_name[20]; //數據交換時的暫存信息變數
floattemp0,temp1,temp2;
inttemp_num;

strcpy(name,y);
head=x;

ptr=head->next;
while(ptr!=NULL) //測鏈表長度,不包括表頭結點
{
ptr=ptr->next;
len++;
}
ptr=head->next; //指針ptr用過之後記得回原位


//開始查找科目
if(strcmp(name,ptr->subject[0].name)==0) flag=1;
if(strcmp(name,ptr->subject[1].name)==0) flag=2;
if(strcmp(name,ptr->subject[2].name)==0) flag=3;
if(flag==0)
{
printf("未找到該科目!");
return;
}

//開始排序,冒泡法比較各結點數據
//此處3個並列的if用switchcase更清晰結構
if(n==1)
{
for(i=0;i<len;i++)
{
ptr=head->next->next; //每一次內循環之後,ptr、qtr必然在最後兩個節點上
qtr=head->next; //故在進行內循環之前,要重新復位ptr、qtr
for(j=0;j<len-i-1;j++)
{
if(qtr->subject[0].score<ptr->subject[0].score)
{
temp_num=qtr->num; //交換數據,因數據格式(科目順序)明確規定,故不再做科目名稱的替換
strcpy(temp_name,qtr->name);
temp0=qtr->subject[0].score;
temp1=qtr->subject[1].score;
temp2=qtr->subject[2].score;

qtr->num=ptr->num;
strcpy(qtr->name,ptr->name);
qtr->subject[0].score=ptr->subject[0].score;
qtr->subject[1].score=ptr->subject[1].score;
qtr->subject[2].score=ptr->subject[2].score;

ptr->num=temp_num;
strcpy(ptr->name,temp_name);
ptr->subject[0].score=temp0;
ptr->subject[1].score=temp1;
ptr->subject[2].score=temp2;
}
qtr=qtr->next;
ptr=ptr->next;
}
}
}

if(n==2)
{
for(i=0;i<len;i++)
{
ptr=head->next->next;
qtr=head->next;
for(j=0;j<len-i-1;j++)
{
if(qtr->subject[1].score<ptr->subject[1].score)
{
temp_num=qtr->num;
strcpy(temp_name,qtr->name);
temp0=qtr->subject[0].score;
temp1=qtr->subject[1].score;
temp2=qtr->subject[2].score;

qtr->num=ptr->num;
strcpy(qtr->name,ptr->name);
qtr->subject[0].score=ptr->subject[0].score;
qtr->subject[1].score=ptr->subject[1].score;
qtr->subject[2].score=ptr->subject[2].score;

ptr->num=temp_num;
strcpy(ptr->name,temp_name);
ptr->subject[0].score=temp0;
ptr->subject[1].score=temp1;
ptr->subject[2].score=temp2;
}
qtr=qtr->next;
ptr=ptr->next;
}
}
}

if(n==3)
{
for(i=0;i<len;i++)
{
ptr=head->next->next;
qtr=head->next;
for(j=0;j<len-i-1;j++)
{
if(qtr->subject[2].score<ptr->subject[2].score)
{
temp_num=qtr->num;
strcpy(temp_name,qtr->name);
temp0=qtr->subject[0].score;
temp1=qtr->subject[1].score;
temp2=qtr->subject[2].score;

qtr->num=ptr->num;
strcpy(qtr->name,ptr->name);
qtr->subject[0].score=ptr->subject[0].score;
qtr->subject[1].score=ptr->subject[1].score;
qtr->subject[2].score=ptr->subject[2].score;

ptr->num=temp_num;
strcpy(ptr->name,temp_name);
ptr->subject[0].score=temp0;
ptr->subject[1].score=temp1;
ptr->subject[2].score=temp2;
}
qtr=qtr->next;
ptr=ptr->next;
}
}
}

//輸出排序過後的鏈表
ptr=head->next;
while(ptr!=NULL)
{
printf("%03d%s%s%5.2f%s%5.2f%s%5.2f ",
ptr->num,ptr->name,ptr->subject[0].name,ptr->subject[0].score,
ptr->subject[1].name,ptr->subject[1].score,
ptr->subject[2].name,ptr->subject[2].score);
ptr=ptr->next;
}
}


//保存文件並退出,文件操作
voidSaveQuit(pstux)
{
pstuhead,ptr;
FILE*fp;
charfilename[]="D:\編程學習\編程實踐\c語言課程設計1學生信息管理\data.txt";
head=x;
ptr=head->next;

if(NULL==(fp=fopen(filename,"w"))) //判斷文件是否存在及可讀
{
printf("error!");
exit(0);
}

while(ptr!=NULL) //遍歷鏈表結點,按data約定格式輸出數據
{
fprintf(fp,"%03d%s%s%5.2f%s%5.2f%s%5.2f ",
ptr->num,ptr->name,ptr->subject[0].name,ptr->subject[0].score,

熱點內容
將電腦的文件上傳到伺服器 發布:2025-04-16 08:10:05 瀏覽:333
sql中between 發布:2025-04-16 07:56:28 瀏覽:769
安卓手機多功能鍵在哪裡 發布:2025-04-16 07:56:27 瀏覽:55
pythondict中文 發布:2025-04-16 07:55:42 瀏覽:465
存儲管理常見問題 發布:2025-04-16 07:53:36 瀏覽:348
python內存大小 發布:2025-04-16 07:37:51 瀏覽:283
安卓還有什麼登錄器 發布:2025-04-16 07:37:49 瀏覽:790
linux怎麼知道root密碼 發布:2025-04-16 07:34:17 瀏覽:70
vb中md5加密資料庫 發布:2025-04-16 07:25:22 瀏覽:1001
androidroot許可權設置 發布:2025-04-16 07:23:09 瀏覽:384