Ⅰ 用c語言設計一個學生成績管理系統
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#defineMAX1000
/*定義學生成績信息結構*/
struct stu
{
char id[8];
char name[8];
(1)班級c語言成績管理系統擴展閱讀:
short:修飾int,短整型數據,可省略被修飾的int。(K&R時期引入)
long:修飾int,長整型數據,可省略被修飾的int。(K&R時期引入)
long long:修飾int,超長整型數據,可省略被修高桐飾的int。(C99標准新增)
signed:修飾整型數據,有符號數據類型。(C89標准新增)
unsigned:修飾整型數據,無符號數據類型。(K&R時期引入)
restrict:用於限定和約束指針,並表明指針是訪問一戚圓坦個數據對象的唯一且初始的方式。(C99標准新增)
復雜類型關鍵字
struct:結構體聲明。(K&R時期引入)
union:聯合體聲明。(K&R時期引入)
enum:枚舉聲明。(C89標准新增)
typedef:聲明類型別名。(K&R時期引入)
sizeof:得到特定類型或特定類型變數的大小。(K&R時期引入)
inline:內聯函數用於取代宏定義腔渣,會在任何調用它的地方展開。(C99標准新增)
Ⅱ c語言成績管理系統
代碼如下:
#include<stdio.h>
#include<string.h>
#define MAX 100 //學生最大數量
#defineCOURSE_N 3 //課程數
structStudent
{
unsignedint id; //學號
char name[20]; //姓名
int scores[COURSE_N]; //課程分數:語文、數學、英語
int sum; //總分
float average; //平均分
};
structStudentList{
structStudentstudents[MAX]; //學生慧念禪列表
intsize; //實際學生人數
};
structStudentListstudentList;
voidPrintStudents(structStudentList*pList)
{
inti;
printf("學號 姓名 語文 數學 英語 總分 平均分 ");
for(i=0;i<pList->size;i++){
printf("%d %s %d %d %d %d %.2f ",
pList->students[i].id,
pList->students[i].name,
pList->students[i].scores[0],
pList->students[i].scores[1],
pList->students[i].scores[2],
pList->students[i].sum,
pList->students[i].average);
}
printf(" ");
}
voidPrintStudent(structStudent*pStu)
{
inti;
printf("學號 姓名 語文 數學 英語 總分 平均分 ");
printf("%d %s %d %d %d %d %.2f ",
pStu->id,
pStu->name,
pStu->scores[0],
pStu->scores[1],
pStu->scores[2],
pStu->sum,
pStu->average);
printf(" ");
}
//通過學號查找學生
structStudent*FindStudentById(structStudentList*pList,unsignedintid)
{
inti;
for(i=0;i<pList->size;i++){
if(pList->students[i].id==id){
return&pList->students[i];
}
}
returnNULL;
}
//通過姓名查找學生
structStudent*FindStudentByName(structStudentList*pList,constchar*name)
{
inti;
for(i=0;i<pList->size;i++){
if(strcmpi((constchar*)pList->students[i].name,name)==0){
return&pList->students[i];
}
}
returnNULL;
}
//高禪添加學生
voidAddStudent(structStudentList*pList)
{
intok=0;
do{
printf("請輸入學號:");
scanf("%d",&pList->students[pList->size].id);
if(FindStudentById(pList,pList->students[pList->size].id)!=NULL){
printf("學號重復! ");
}
else{
ok=1;
}
}while(!ok);
printf("請輸入姓名:");
scanf("%s",pList->students[pList->size].name);
printf("請輸入語文分數:");
scanf("%d",&pList->students[pList->size].scores[0]);
printf("請輸入數學分前塵數:");
scanf("%d",&pList->students[pList->size].scores[1]);
printf("請輸入英語分數:");
scanf("%d",&pList->students[pList->size].scores[2]);
pList->students[pList->size].sum=pList->students[pList->size].scores[0];
pList->students[pList->size].sum+=pList->students[pList->size].scores[1];
pList->students[pList->size].sum+=pList->students[pList->size].scores[2];
pList->students[pList->size].average=(float)pList->students[pList->size].sum/COURSE_N;
pList->size++;
printf("學生添加成功! ");
}
//修改學生信息
voidModifyStudent(structStudentList*pList)
{
intid;
structStudent*p=NULL;
printf("請輸入學號:");
scanf("%d",&id);
p=FindStudentById(pList,id);
if(p!=NULL){
printf("請輸入姓名:");
scanf("%s",p->name);
printf("請輸入語文分數:");
scanf("%d",&p->scores[0]);
printf("請輸入數學分數:");
scanf("%d",&p->scores[1]);
printf("請輸入英語分數:");
scanf("%d",&p->scores[2]);
p->sum=p->scores[0];
p->sum+=p->scores[1];
p->sum+=p->scores[2];
p->average=(float)p->sum/COURSE_N;
printf("修改學生信息成功。 ");
}
else{
printf("沒有找到學號為[%u]的學生。 ",id);
}
}
voidDeleteStudent(structStudentList*pList)
{
intid,index=-1,i;
printf("請輸入學號:");
scanf("%d",&id);
for(i=0;i<pList->size;i++){
if(pList->students[i].id==id){
index=i;
break;
}
}
if(index!=-1){
for(i=index;i<pList->size-1;i++){
memcpy(&pList->students[i],&pList->students[i+1],sizeof(structStudent));
}
pList->size--;
printf("成功刪除學號為[%d]的學生。 ",id);
}
else{
printf("沒有找到學號為[%u]的學生。 ",id);
}
}
voidFindStudent(structStudentList*pList)
{
structStudent*p;
charname[20];
printf("請輸入學生姓名:");
scanf("%s",name);
p=FindStudentByName(pList,name);
if(p!=NULL){
PrintStudent(p);
}
else{
printf("沒有找到姓名為[%s]的學生。 ",name);
}
}
//按平均分排序
voidSortByAverage(structStudentList*pList)
{
inti,j;
structStudenttemp;
for(i=0;i<pList->size-1;i++){
for(j=i+1;j<pList->size;j++){
if(pList->students[i].average<pList->students[j].average){
memcpy(&temp,&pList->students[i],sizeof(structStudent));
memcpy(&pList->students[i],&pList->students[j],sizeof(structStudent));
memcpy(&pList->students[j],&temp,sizeof(structStudent));
}
}
}
}
intmain()
{
intexit=0;
intchoose=0;
while(!exit){
printf("------學生成績管理系統------ ");
printf("1.增加學生記錄 ");
printf("2.修改學生記錄 ");
printf("3.刪除學生記錄 ");
printf("4.按姓名查詢學生記錄 ");
printf("5.按平均成績排序 ");
printf("6.退出 ");
printf("請選擇(1-6):");
scanf("%d",&choose);
switch(choose){
case1:
AddStudent(&studentList);
break;
case2:
ModifyStudent(&studentList);
break;
case3:
DeleteStudent(&studentList);
break;
case4:
FindStudent(&studentList);
break;
case5:
SortByAverage(&studentList);
PrintStudents(&studentList);
break;
case6:
exit=1;
break;
default:
printf("無效的選項。 ");
break;
}
}
printf("已退出系統! ");
return0;
}
運行結果:
Ⅲ 用C語言製作一個班級成績管理系統
給你部分代碼參考
/* 1。根據學生信息定義一個結構體類型,再說明扒凳一個該結構體類型的數組。*/
struct stu_info{
char stuNo[10];/* No */
char stuName[30];/* Name */
float stuScore[3];/* the three scores */
float aveScore; /* average score */
float totalScore; /* total score */
}stu[10];
/* 2。用input函數從鍵盤上輸入10個學生的數據。 */
void input()
{ int i = 0;
printf("Input the students' infomation(FORMAT LIKE:No Name score1 score2 score3):\n");
while(i < 10)
{ printf("Input %d:",i + 1);
scanf("%s%s%f%f%f",stu[i].stuNo,stu[i].stuName,&stu[i].stuScore[0],&stu[i].stuScore[1],&stu[i].stuScore[2]);
i++;
}
}
/* 3。用average函數求出每個學生總尺塌成績、春困旅平均成績和所有學生的總平均成績。 */
float average()
{ int i = 0;
float totalAve_score = 0;
while(i < 10)
{ stu[i].totalScore = stu[i].stuScore[0]+stu[i].stuScore[1]+stu[i].stuScore[2];
stu[i].aveScore = stu[i].totalScore/3;
totalAve_score += stu[i].aveScore;
i++; }
totalAve_score /= 10;
return totalAve_score; }
Ⅳ 用C編寫班級成績管理系統
C語言課程設計報告—班級成績管理系統
需要分析:
學生成績管理系統有13種功能。把這13個功能做成13個子函數。在主函當數中設計一個菜單對這13個子數進行管理。來實現對整個系統的操作。
根據課題的要求。每一個學生的包括姓名(char)、學號(char)、M門課程的成績(float).再加上系統功能上的要求每一學生的信息還要總分和名次等。所以自然的想到要用結構體來定義每一個學生的信息結構。然後用鏈表把它們組成一個有序的整體。用對鏈表的操作來實現對所有學生信息的統一管理(成績顯示、成績排序、成績修改等)。最後為了以後按照處理後的順序保存到文件中。
. 各函數的功能:
概要設計:
程序的模塊組成:
主 函 數: int main()
新建函數:STUDENT *init()
輸入函數 :STUDENT *create()
顯示函數: void print(STUDENT *head)
刪除函數: STUDENT *delete(STUDENT *head)
按名字尋找函數: void lookup(STUDENT *head)
保存函數: void save(STUDENT *head)
按總分排序函數: STUDENT *sort(STUDENT *head)
計算總分和均分函數: void computer(STUDENT *h)
修改函數: STUDENT *Modify(STUDENT *head,STUDENT *new)
按學號排序函數: STUDENT *index(STUDENT *h)
菜單函數:int menu_select()
各個函數的主要功能:
輸入函數: 隨時輸入數據。
菜單函數:顯示系統主菜單。
顯示函數: 顯示所有學生的信息。
尋找函數: 方便學生查找自己的成績。
刪除函數: 刪除某學生的信息。
排序函數: 按總成績排序。
按學號排序函數: 按學號排序。
插入函數: 可以插入新的信息。
保存函數: 保存好學生成績,以免丟失。
統計函數:
l 顯示每門課程成績最高的學生的基本信息。
l 顯示每門課程的平均成績。
l 顯示超過某門課程平均成績的學生人數。
課題的功能模塊的劃分:
開始
菜單界面
功能選擇
初始化函數
輸入學生信息
刪除學生信息
顯示學生信息
查找學生信息
按成績排序
保存到文件
從文件讀數據
插入學生成績
分類合計
退出彎芹系統
結束
詳細設計: 整個系統除了主函數外,另外還有14個函數,實現八大功能:輸入功能、顯示功能、查找功能、排序功能、插入功能、保存功能、讀取功能。各個函數的詳細設計說明分別如下:
主函數 main()
利用無限次循環for(;;)和swithch()實現各函數的調用,系統根據輸入的數字選項來調用相應的函數。
菜單選擇函數 int menu_select()
這是一個無參函數,主要實現「功能選擇」的界面,在這個界面里有顯示系統的九大功能,根據每個功能前面的序號進行選擇。等執行完每一個函數功能後,返回菜單。
代碼設計: 初始化函數 STUDENT *init()
這是一個無參函數,裡面只有兩個語句,它的作用是使鏈表初始化,使head的值為NULL和一個清屏語句。比如:沒有這個函數的話,在你沒有輸入任何數據的情況下,去執行顯示功能的時候會顯示一些亂碼!
輸入記錄函數 STUDENT *create() 這是一個無參函數,用來執行學生成績記錄的輸入,當學生為@時停止輸入,函數結束後,帶回一個鏈表頭的指針指向一下個學生的信息插在表頭。
N-S流程圖如下:
head=NULL無條件循環
指針p指向新開辟的單元
指針p是否為空
是 否
輸入學號p->num
輸出 p->num是否為@
內存 是 否
溢出 輸入姓名p->name
停止 for(i=0;i<3;i++)
輸入 輸入成績
返回 p->sum=s;
菜單 p->average=(float)s/3;
顯示記錄函數 void print(STUDENT *head)
這是一個不返回值的有參函數,形參為「鏈表頭的指針」,負責對全部學生成績慎鬧碰記錄的輸出,不足之處寬談就是不能對學生成績進行分頁顯示。
演算法:先將p結點的指針指向第一個結點,將p結點(即第一個結點)的數據輸出。然後再將p結點的指針指向p指針的的指針(即下一結點),將p結點(即第一結點)的數據輸出。重復執行此步聚直到p指針指向NULL為止。
N-S流程圖如下:
p=head,使指向第一個結點
輸出p所指向的結點
p指向一下個結點
當p指的不是表尾
程序調試:
由於本課題中的許多知識點都沒有學過都要靠自己到課外的資料中去查找。在用的時候難免出現這樣那樣的錯誤。如開始設計出來的菜單不是預想的那樣,而是總個窗中出現混亂。解決的這個問題的辦法是調整。最後還是老師幫我幫我們找到了問題的所在——for 循環的次超過了鏈表中結點的數量。再就是自定義函數時由於課本的概念不清楚,多寫了空格鍵,以至函數調用不出來。又如:在設計修改學生信息時的密密碼時。當用戶發現輸入密碼錯誤按了退格鍵後,因為「*」並沒有消去。導致用戶再次按退格鍵,又出現前面的情況。最終導致輸入密碼錯誤。所以用了兩次退格鍵:
在對鏈表操作時,要特別鏈表指針的移動(p=p->next)和鏈表尾的判斷 (p= =NULL)。沒有指針的移動,就很容易出現死循環。而在運行過程中不能控制。所以你就會認為是死機。如果沒有鏈表尾的判斷。就會在運行過程出現想不到的錯誤。如:在顯示鏈表信息時,後面就會出現亂碼。
一個系統的菜單和提示信息非常重要。如果沒有這些用戶根本不知道怎麼用你設計的這個系統。在設計的調試過程中也無法順利的完成調試工作。有了一個清晰簡單的菜單和一些提示信息這後,調試過程完成的非常順利。
予我耐心解答的老師和同學,是他們為我小程序的成功起到了關鍵性的作用,那麼多個日夜,如此多的困難,同學們勤懇塌實,從開始到結束,沒有顯出一點倦意,始終熱情高漲,我感謝這種氛圍,感謝學校提供的良好條件。
回顧起此次課程設計,至今我仍感慨頗多,的確,從拿到題目到完成整個編程,從理論到實踐,在整整半個學期的日子裡,可以學到很多很多的東西,同時不僅可以鞏固了以前所學過的知識,而且學到了很多在書本上所沒有學到過的知識。通過這次課程設計使我懂得了理論與實際相結合是很重要的,只有理論知識是遠遠不夠的,只有把所學的理論知識與實踐相結合起來,從理論中得出結論,才能真正為社會服務,從而提高自己的實際動手能力和獨立思考的能力。在設計的過程中遇到問題,可以說得是困難重重,這畢竟第一次做的,難免會遇到過各種各樣的問題,同時在設計的過程中發現了自己的不足之處,對以前所學過的知識理解得不夠深刻,掌握得不夠牢固,比如說結構體……通過這次課程設計之後,一定把以前所學過的知識重新溫故。
本次課程設計結束了,對於我的影響很大。我通過這次實踐學到了許多知識。學到了設計一個簡單的系統。要注意哪些方面。也使我知道自己哪些方面做得還不夠。
但我出總結出了一點點的經驗如下:
1、要對系統的功能和要求做出詳細的分析,並合理分解任務。
2、把分解出來的子任務,做給一個相對獨立的模塊。
3、在設計一個模塊之前,要簡單構想一下總界面的顯視情況。
4、針對構想出來的界面進行程序的編寫。
最後,感謝老師您對我的指導和從百忙中抽空看我的設計,謝謝!
附件:
源程序:
#include "stdio.h" /*I/O函數*/
#include "stdlib.h" /*其它說明*/
#include "string.h" /*字元串函數*/
#include "conio.h" /*屏幕操作函數*/
#include "mem.h" /*內存操作函數*/
#include "ctype.h" /*字元操作函數*/
#include "alloc.h" /*動態地址分配函數*/
#include "dos.h"
#define N 4 /*定義常數*/
typedef struct z1 /*定義數據結構*/
{
char no[12];
char name[20];
int score[N];
float sum;
float average;
int order;
struct z1 *next;
}STUDENT;
/*以下是函數原型*/
STUDENT *init(); /*初始化函數*/
STUDENT *create(); /*創建鏈表*/
STUDENT *delete(STUDENT *h); /*刪除記錄*/
void print(STUDENT *h); /* 顯示所有記錄*/
void lookup(STUDENT *h); /*查找*/
void save(STUDENT *h); /*保存*/
STUDENT *load(); /*讀入記錄*/
void computer(STUDENT *h); /*計算總分和均分*/
STUDENT *Modify(STUDENT *h); /*修改記錄*/
void append(); /*追加記錄*/
STUDENT *sort(STUDENT *h); /*按總分排序*/
STUDENT *index(STUDENT *h); /*按學號排序*/
int menu_select(); /*菜單函數*/
/******主函數開始*******/
main()
{
int i;
STUDENT *head; /*鏈表定義頭指針*/
printf("\n\n\n\n\n\n\n\n\n");
printf(" * * ******* * ***** ***** * * ******* \n");
printf(" * * * * * * * ** * * * \n");
printf(" * * * * ******* * * * * * *** * ******* \n" );
printf(" * * * * * * * * * * * * * \n");
printf(" * * ******* ******* ***** * *** * * * ******* \n");
printf("\n");
printf("\n");
printf("\n");
sleep(2);
head=init(); /*初始化鏈表*/
clrscr(); /*清屏*/
for(;;) /*無限循環*/
{
switch(menu_select()) /*調用主菜單函數,返回值整數作開關語句的條件*/
{ /*值不同,執行的函數不同,break 不能省略*/
case 0:head=init();break; /*執行初始化*/
case 1:head=create();break; /*創建鏈表*/
case 2:print(head);break; /*顯示全部記錄*/
case 3:head=delete(head);break; /*刪除記錄*/
case 4:lookup(head);break; /*按名字查找記錄*/
case 5:save(head);break; /*保存文件*/
case 6:head=load(); break; /*讀文件*/
case 7:computer(head);break; /*計算總分和均分*/
case 8:head=Modify(head); break; /*修改記錄,一般會插在表尾*/
case 9:head=sort(head);break; /*按部分排序*/
case 10:append();break; /*追加記錄*/
case 11:head=index(head);break; /*按學號排序*/
case 12: exit(0); /*如菜單返回值為14程序結束*/
}
}
}
/*菜單函數,返回值為整數*/
menu_select()
{
char *menu[]={"***************MENU***************", /*定義菜單字元串數組*/
" 00. init list", /*初始化*/
" 01. Enter list", /*輸入記錄*/
" 02. print list ", /*顯示單鏈表中所有記錄*/
" 03. Delete a record from list", /*從表中刪除記錄*/
" 04. Search record on name", /*按照姓名查找記錄*/
" 05. Save the file", /*將單鏈表中記錄保存到文件中*/
" 06. Load the file", /*從文件中讀入記錄*/
" 07. compute the score", /*計算所有學生的總分和均分*/
" 08. Modify an information ", /*修改某學號的信息*/
" 09. sort to make new file", /*排序*/
" 10. append record to file", /*追加記錄到文件中*/
" 11. index on nomber", /*按學號排序*/
" 12. Quit"}; /*退出*/
char s[3]; /*以字元形式保存選擇號*/
int c,i; /*定義整形變數*/
gotoxy(1,1); /*移動游標*/
textcolor(YELLOW); /*設置文本顯示顏色為黃色*/
textbackground(BLUE); /*設置背景顏色為藍色*/
gotoxy(10,2); /*移動游標*/
putch(0xc9); /*輸出左上角邊框┏*/
for(i=1;i<44;i++)
putch(0xcd); /*輸出上邊框水平線*/
putch(0xbb); /*輸出右上角邊框 ┓*/
for(i=3;i<20;i++)
{
gotoxy(10,i);putch(0xba); /*輸出左垂直線*/
gotoxy(54,i);putch(0xba);
} /*輸出右垂直線*/
gotoxy(10,20);putch(0xc8); /*輸出左上角邊框┗*/
for(i=1;i<44;i++)
putch(0xcd); /*輸出下邊框水平線*/
putch(0xbc); /*輸出右下角邊框┛*/
window(11,3,53,19); /* 製作顯示菜單的窗口,大小根據菜單條數設計*/
clrscr(); /*清屏*/
for(i=0;i<16;i++) /*輸出主菜單數組*/
{
gotoxy(10,i+1);
cprintf("%s",menu[i]);
}
textbackground(BLACK); /*設置背景顏色為黑色*/
window(1,1,80,25); /*恢復原窗口大小*/
gotoxy(10,21); /*移動游標*/
do{printf("\n make by wenwei");
printf("\n Enter you choice(0~13):"); /*在菜單窗口外顯示提示信息*/
scanf("%s",s); /*輸入選擇項*/
c=atoi(s); /*將輸入的字元串轉化為整形數*/
}while(c<0||c>14); /*選擇項不在0~14之間重輸*/
return c; /*返回選擇項,主程序根據該數調用相應的函數*/
}
STUDENT *init()
{ clrscr();
return NULL;
}
/*創建鏈表*/
STUDENT *create()
{
int i; int s;
STUDENT *h=NULL,*info; /* STUDENT指向結構體的指針*/
clrscr();
for(;;)
{
info=(STUDENT *)malloc(sizeof(STUDENT)); /*申請空間*/
if(!info) /*如果指針info為空*/
{
printf("\nout of memory"); /*輸出內存溢出*/
return NULL; /*返回空指針*/
}
inputs("enter no:",info->no,11); /*輸入學號並校驗*/
if(info->no[0]=='@') { clrscr();break; } /*如果學號首字元為@則結束輸入,清屏後返回*/
inputs("enter name:",info->name,15); /*輸入姓名,並進行校驗*/
printf("please input %d score \n",N); /*提示開始輸入成績*/
s=0; /*計算每個學生的總分,初值為0*/
for(i=0;i<N;i++) /*N門課程循環N次*/
{
do{
printf("score%d:",i+1); /*提示輸入第幾門課程*/
scanf("%d",&info->score[i]); /*輸入成績*/
if(info->score[i]>100||info->score[i]<0) /*確保成績在0~100之間*/
printf("bad data,repeat input\n"); /*出錯提示信息*/
}while(info->score[i]>100||info->score[i]<0);
s=s+info->score[i]; /*累加各門課程成績*/
}
info->sum=s; /*將總分保存*/
info->average=(float)s/N; /*求出平均值*/
info->order=0; /*未排序前此值為0*/
info->next=h; /*將頭結點做為新輸入結點的後繼結點*/
h=info; /*新輸入結點為新的頭結點*/
clrscr();
}
return(h); /*返回頭指針*/
}
/*輸入字元串,並進行長度驗證*/
inputs(char *prompt, char *s, int count)
{
char p[255];
do{
printf(prompt); /*顯示提示信息*/
scanf("%s",p); /*輸入字元串*/
if(strlen(p)>count)printf("\n too long! \n"); /*進行長度校驗,超過count值重輸入*/
}while(strlen(p)>count);
strcpy(s,p); /*將輸入的字元串拷貝到字元串s中*/
}
/*輸出鏈表中結點信息*/
void print(STUDENT *h)
{
int i=0; /* 統計記錄條數*/
STUDENT *p; /*移動指針*/
clrscr(); /*清屏*/
p=h; /*初值為頭指針*/
printf("\n\n\n*********************************STUDENT************************************\n");
printf("|rec|nO | name | sc1| sc2| sc3| sc4| sum | ave |order|\n");
printf("|---|----------|---------------|----|----|----|----|--------|--------|-----|\n");
while(p!=NULL) /*只要p不是尾結點,就輸出記錄*/
{
i++;
printf("|%3d|%-10s|%-15s|%4d|%4d|%4d|%4d| %6.2f | %6.2f | %3d |\n", i, p->no,p->name,p->score[0],p->score[1],p->score[2],p->score[3],p->sum,p->average,p->order);
p=p->next;
}
printf("***********************************end**************************************\n");
getch(); /*輸入任一鍵返回主菜單*/
clrscr(); /*清屏*/
}
/*刪除記錄*/
STUDENT *delete(STUDENT *h)
{
STUDENT *p,*q; /*p為查找到要刪除的結點指針,q為其前驅指針*/
char s[12]; /*存放學號*/
char *pass="wenwei28";
char a[20],b=NULL;
int i=0;
clrscr();
printf("Input your password:");
while((i<20)&&(b!='\r'))
{ b=getch(); /*無回顯輸入*/
if(b==8)
{ if(i>0)
{a[--i]=NULL;
putchar(8); /*退格鍵*/
putchar(' '); /*以空格代替*/
putchar(8);
}
else putchar(7); /*沒有任何字元的退格,響鈴警告*/
}
else if(b!='\r')
{ a[i++]=b; /*只要不是退格和回車就接受*/
putchar('*');
}
else
{a[i]=NULL; break; /*密碼輸入完了,記得加個NULL到後面*/
}
}
if(strcmp(a,pass)!=0)
{clrscr();
printf("Password is mistake Tow seconds to return!");
sleep(2);clrscr();return h;
}
else {printf("Password is OK! Welcome to come!"); sleep(3);
}
clrscr(); /*清屏*/
printf("please deleted no\n"); /*顯示提示信息*/
scanf("%s",s); /*輸入要刪除記錄的學號*/
q=p=h; /*給q和p賦初值頭指針*/
while(strcmp(p->no,s)&&p!=NULL) /*當記錄的學號不是要找的,或指針不為空時*/
{
q=p; /*將p指針值賦給q作為p的前驅指針*/
p=p->next; /*將p指針指向下一條記錄*/
}
if(p==NULL) /*如果p為空,說明鏈表中沒有該結點*/
{ printf("\nlist no %s student\n",s);sleep(2);clrscr();return h;}
else /*p不為空,顯示找到的記錄信息*/
{
printf("*********************************have found********************************\n");
printf("|no | name | sc1| sc2| sc3| sc4| sum | ave |order|\n");
printf("|------------|---------------|----|----|----|----|--------|--------|-----|\n");
printf("|%-12s|%-15s|%4d|%4d|%4d|%4d| %6.2f | %6-5.2f | %3d |\n", p->no,
p->name,p->score[0],p->score[1],p->score[ q=p; /*保存當前結點的指針,作為下一結點的前驅*/
p=p->next; /*指針後移,新讀入數據鏈到當前表尾*/
}
q->next=NULL; /*最後一個結點的後繼指針為空*/
fclose(fp); /*關閉文件*/
printf("---You have success read data from file!!!---\n");
getch(); /*按任意鍵返回主菜單*/
clrscr();
return h; /*返回頭指針*/
}
/*成績統計*/
void computer(STUDENT *h)
{
STUDENT *p,*t,*q; /*定義移動指針*/
float saverage[N]={0}; /*均分初值為0*/
int i;
clrscr();
for (i=0;i<N;i++)
{ int n=0,j=0; /*保存記錄條數初值為0*/
long s=0; /*總分初值為0*/
p=h; /*從頭指針開始*/
while(p!=NULL) /*當p不為空時處理*/
{
s+=p->score[i]; /*累加總分*/
j++; /*統計記錄條數*/
p=p->next; /*指針後移*/
h; /*返回頭指針
Ⅳ C語言成績管理系統
#include"stdio.h"
structstu{
intsid,score;
charg;
};
voidscorein(structstu*p,intn){
inti,t;
for(i=0;i<n;i++){
scanf("%d%d",&p[i].sid,&p[i].score);
p[i].g=(t=p[i].score)>89&&t<101?'A':t>79&&t<90?'B':t>69&&t<80?'C':t>59&&t<70?'D':'E';
}
}
intsum(structstu*p,intn){
ints=0;
while(n--)
s+=p++->score;
returns;
}
voiddssort(structstu*p,intn){
inti,j,k;
structstut;
printf(" STUID SCORE CLASS ===================== ");
for(i=0;i<n;i++){
for(k=i,j=k+1;j<n;j++)
if(p[k].score<p[j].score)
k=j;
if(k!=i)
t=p[k],p[k]=p[i],p[i]=t;
printf("%d %d %c ",p[i].sid,p[i].score,p[i].g);
}
}
voididsort(structstu*p,intn){
inti,j,k;
structstut;
printf(" STUID SCORE CLASS ===================== ");
for(i=0;i<n;i++){
for(k=i,j=k+1;j<n;j++)
if(p[k].sid>p[j].sid)
k=j;
if(k!=i)
t=p[k],p[k]=p[i],p[i]=t;
printf("%d %d %c ",p[i].sid,p[i].score,p[i].g);
}
}
voidquery(structstu*p,intn){
intid;
printf(" PleaseenterID(int)... ");
scanf("%d",&id);
while(id-p->sid&&n)
p++,n--;
if(n>=0){
printf("STUID SCORE CLASS ===================== ");
printf("%d %d %c ",p->sid,p->score,p->g);
}
else
printf("Nofind! ");
}
voidlevel(structstu*p,intn){
intd[5],i;
chars[5][7]={"優秀","良好","中等","及格","不及格"};
printf("統計信息如下: ");
for(i=0;i<5;d[i++]=0);
for(i=0;i<n;i++,d[p++->g-'A']++);
for(i=0;i<5;i++)
printf("%6s: %d %.2f%% ",s[i],d[i],d[i]/(n+0.0)*100);
}
voidoutinfo(structstu*p,intn){
inti;
printf(" STUID SCORE ============= ");
for(i=0;i<n;i++)
printf("%d %d ",p[i].sid,p[i].score);
}
intmain(intargc,char*argv[]){
intn,s;
structstua[30];
printf("Pleaseentern(int0<n<31)... ");
if(scanf("%d",&n)!=1||n<1||n>30){
printf("Inputerror,exit... ");
return0;
}
scorein(a,n);//輸入
dssort(a,n);//分數降序
idsort(a,n);//學號升序
query(a,n);//查詢
level(a,n);//等級和百分比
outinfo(a,n);//輸出各位學生信息
printf("總分:%d",s=sum(a,n));
printf("平均分:%.2f ",s/(n+0.0));
return0;
}
運行樣例:
Ⅵ 用C語言編一個班級成績管理系統
// test4.cpp : Defines the entry point for the console application.
//
#include "stdafx.h"
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <malloc.h>
struct Student //學生結構體
{
char name[20]; //名字
char sex[10]; //性別
char zuanye[20]; //專業
char code[13]; //學號
char department[20]; //學院
char degree[20]; //稿緩學歷
};
struct node
{
struct Student data;
struct node *next;
};
//---------------------------------------------------------------------------------
void print_menu(void) // 列印總菜單
{
printf(" |--------------------------------------------------|\n");
printf(" | 總 菜 單 : |\n");
printf(" |--------------------------------------------------|\n");
printf(" | 1--增加一個學生信息 | 5--刪除一個學生信息 |\n");
printf(" | 2--顯示一個學生信息 | 6--統計功能 |\n");
printf(" | 3--顯示一個班級信息 | 7--結束 |\n"羨則);
printf(" | 4--修改一個學生信息 | \3 \3 \3 \3 \3 \3 \3 \3 \3 \3 \3 |\n");
printf(" |--------------------------------------------------|\n");
}
void print_menu4(void ) //列印修改功能
{
printf(" |--------------------------------------------------|\n");
printf(" | 修 改 功 能 : |\n");
printf(" |--------------------------------------------------|\n");
printf(" | 1--修改名字 | 5--修改學院 |\n");
printf(" | 2--修改性別 | 6--修改專業 |\n");
printf(" | 3--修改學號 | 7--不作修改 |\n");
printf(" | 4--修改學歷 | \3 \3 \兄敬棚3 \3 \3 \3 \3 \3 \3 \3 \3 |\n");
printf(" |--------------------------------------------------|\n");
printf("再次選擇選項 :");
}
void print_static_function_menu(void) //列印統計功能
{
printf(" |--------------------------------------------------|\n");
printf(" | 統 計 功 能 : |\n");
printf(" |--------------------------------------------------|\n");
printf(" | 1.男/女人數 | 3.一個專業人數 |\n");
printf(" | 2.一個班級人數 | 4.結束 |\n");
printf(" |--------------------------------------------------|\n");
printf("請選擇選項:\n");
}
int compareCode(char a[],char b[]) //比較 判斷是否是同一個班級
{
for(int i=0;i<9;i++)
if(a[i]!=b[i]) break;
if(i==9) return 1;
else return 0;
}
//-------------------------------------------------------------------------------------
void main() //主函數從這里開始
{
system("color 3");
printf("\n\n\n");
printf(" \3\3\3\3\3\3\3\3\3\3\3\3\3\3\3\3\3\3\3\3\3\3\3\3\3\3\3\3\3\3\3\3\3\3\3\3\3\3\3\3\3\3\3\3\3\3\3\3\3\3\3\3\n");
printf(" \3\3\3\3\3\3\3\3\3\3 學 生 證 管 理 程 序 \3\3\3\3\3\3\3\3\n");
printf(" \3\3\3\3\3\3\3\3\3\3\3\3\3\3\3\3\3\3\3\3\3\3\3\3\3\3\3\3\3\3\3\3\3\3\3\3\3\3\3\3\3\3\3\3\3\3\3\3\3\3\3\3\n");
printf(" \3\3\3\3\3\3 作者: \3\3\3\3\3\3\3\n");
printf(" \3\3\3\3\3\3\3\3\3\3\3\3\3\3\3\3\3\3\3\3\3\3\3\3\3\3\3\3\3\3\3\3\3\3\3\3\3\3\3\3\3\3\3\3\3\3\3\3\3\3\3\3\n");
int choice;
struct node *studentlist=(struct node*)malloc(sizeof(struct node)); //學生鏈表頭 //////////////////////////////////////////////////////////
studentlist->next=NULL;
struct node *temp=NULL;
struct node *p=(struct node*)malloc(sizeof(struct node));
char tempcode[13]; //臨時學號
char tempclass[11]; //臨時班級
char tempzuanye[20];//臨時專業
int count=0;
int choice6,count_male,count_female;
const int sizeStu=sizeof(struct Student);
struct Student data;
FILE *fp;
if((fp=fopen("d:\\學生證管理程序.dat","rb"))==NULL)
{
fp=fopen("d:\\學生證管理程序.dat","wb");
}
fclose(fp);
fp=fopen("d:\\學生證管理程序.dat","rb");
while(fread(&data,sizeStu,1,fp)==1)
{
p->data=data;
p->next=NULL;
if(studentlist==NULL)
studentlist=p;
else
{ temp=studentlist;
while(temp->next!=NULL){temp=temp->next;}
temp->next=p;
}
p=(struct node*)malloc(sizeof(struct node));
}
fclose(fp);
print_menu(); //列印菜單
scanf("%d",&choice); //讀進選項
while(choice!=7) //未遇到結束鍵
{
switch(choice)
{
//----------------------------------------------------------------
//選項1,增加學生學生證信息
case 1: //輸入一個學生信息
p=(node*) malloc(sizeof(node));
printf("\n請輸入姓名:");
scanf("%s",p->data.name);
printf("\n請輸入性別(男/女):");
scanf("%s",p->data.sex);
printf("\n請輸入學號(12位):");
scanf("%s",p->data.code);
printf("\n請輸入學制(本科生/研究生):");
scanf("%s",p->data.degree);
printf("\n請輸入學院:");
scanf("%s",p->data.department);
printf("\n請輸入專業:");
scanf("%s",p->data.zuanye);
p->next=NULL;
//----------------------------------------------------------鏈表連接
if(studentlist==NULL) { studentlist=p; studentlist->next=NULL;}
else {
temp=studentlist;
while(temp->next!=NULL) ////////////////////
{
temp=temp->next;
}
temp->next=p;
p->next=NULL;
}
break;
//---------------------------------------------------------------------
//選項2,顯示給定學生學生證信息
case 2: printf("\n請輸入學生學號(12位數):");
scanf("%s",tempcode);
temp=studentlist;
while(temp!=NULL) //尋找響應的學生
{
if(strcmp(tempcode,temp->data.code)==0) break;
temp=temp->next;
}
if(temp==NULL) printf("\n不能找到該學生信息.\n");
else {
printf("------------------------------------------------\n");
printf("姓名: %s\n",temp->data.name);
printf("性別: %s\n",temp->data.sex);
printf("學號: %s\n",temp->data.code);
printf("學歷: %s\n",temp->data.degree);
printf("學院: %s\n",temp->data.department);
printf("專業: %s\n",temp->data.zuanye);
printf("------------------------------------------------\n\n");
}
break;
//-----------------------------------------------------------------
//選項3,顯示給定班級的學生信息
case 3:printf("\n請輸入班級號 :"); //輸入班級號
scanf("%s",tempclass);
while(strlen(tempclass)<10) //班級號位數小於10時,重新輸入
{
printf("錯誤的班級號,請重新輸入:");
scanf("%s",tempclass);
}
count=0; //班級學生數
temp=studentlist;
while(temp!=NULL) //檢索鏈表,並列印相應學生的學生證信息
{
if(compareCode(tempclass,temp->data.code)) {//列印屬於這個班級的學生
printf("-----------------------------------------------\n");
printf("姓名: %s\n",temp->data.name);
printf("性別: %s\n",temp->data.sex);
printf("學號: %s\n",temp->data.code);
printf("學歷: %s\n",temp->data.degree);
printf("學院: %s\n",temp->data.department);
printf("專業: %s\n",temp->data.zuanye);
printf("-----------------------------------------------\n");
count++;
}
temp=temp->next;
}
if(count==0) printf("該班級還未有成員.\n");
break;
//-------------------------------------------------------------------
//選項4,修改給定學生的信息
case 4: printf("請輸入要作修改的學生證號:");
scanf("%s",tempcode);
temp=studentlist;
while(temp!=NULL) //尋找響應的學生
{
if(strcmp(tempcode,temp->data.code)==0) break;
temp=temp->next;
}
if(temp==NULL) printf("\n找不到相應學生的信息.\n");//找不到相應的學生
else {
int choice2;
print_menu4();
scanf("%d",&choice2);
while(choice2!=7)
{
switch(choice2)
{
case 1:printf("修改名字:"); //修改名字
scanf("%s",temp->data.name);
break;
case 2:printf("修改性別:");//修改性別
scanf("%s",temp->data.sex);
break;
case 3:printf("修改學號:");//修改學號
scanf("%s",temp->data.code);
break;
case 4:printf("修改學歷 :"); //修改學歷
scanf("%s",temp->data.degree);
break;
case 5:printf("修改學院:"); //修改學院
scanf("%s",temp->data.department);
case 6:printf("修改專業:");//修改專業
scanf("%s",temp->data.zuanye);
break;
default: break;
}
printf("請選擇選項:");
scanf("%d",&choice2); //再次選擇菜單選項
}
}
break;
//----------------------------------------------------------------
//選項5,刪除給定學號的學生
case 5: printf("\n輸入學號 :"); //輸入學號
scanf("%s", tempcode);
temp=studentlist;
p=temp;
while(temp!=NULL) //尋找相應的學生
{
if(strcmp(tempcode,temp->data.code)==0) break;
p=temp;
temp=temp->next;
}
if(temp==NULL) printf("\n找不到該學生信息.\n"); //找不到
else if(temp==studentlist) {studentlist=temp->next; free(temp);}
else {
p->next=temp->next;//找到時刪除
free(temp);
}
break;
//------------------------------------------------------------------
//選項6,統計功能
case 6: print_static_function_menu();
scanf("%d",&choice6);//選擇菜單選項
while(choice6!=4)
{
switch(choice6)
{
//選項1,統計男女個數
case 1:temp=studentlist;
count_male=0; //男生數
count_female=0; //女生數
while(temp!=NULL) //檢索鏈表查找
{
if(strcmp(temp->data.sex,"男")==0) count_male++;
if(strcmp(temp->data.sex,"女")==0) count_female++;
temp=temp->next;
}
printf("男: %d\n",count_male);
printf("女: %d\n",count_female);
break;
//選項2,統計給定班級的人數
case 2:printf("請輸入班級號:");
scanf("%s",tempclass); //給定班級
temp=studentlist;
count=0;
while(temp!=NULL) //檢索鏈表查找
{
if(compareCode(temp->data.code,tempclass)==1) count++;
temp=temp->next;
}
printf("%s班級總人數為: %d\n",tempclass,count);
break;
case 3:printf("請輸入專業:");
scanf("%s",tempzuanye); //給定專業
temp=studentlist;
count=0;
while(temp!=NULL) //檢索鏈表查找
{
if(strcmp(temp->data.zuanye,tempzuanye)==0) count++;
temp=temp->next;
}
printf("%s專業總人數為: %d\n",tempzuanye,count);
break;
//預設項
default: break;
}
printf("請選擇選項:");
scanf("%d",&choice6);
}
break;
//-----------------------------------------------------------------
default:free(p); break;
}
if((fp=fopen("d:\\學生證管理程序.dat","wb"))==NULL)
{
printf("文件無法打開!");
return;
}
p=studentlist;
while(p)
{
fwrite(&p->data,sizeStu,1,fp);
p=p->next;
}
fclose(fp);
print_menu( );//列印菜單 進入循環
scanf("%d",&choice);
}
}
Ⅶ C語言怎麼編一個簡單的成績管理系統
一個簡單的成績管理系統通常包括以下功能:
添加學生信息和成績;
顯示所有學生的信息和成績;
根據學號或姓名查詢學生信息和成績;
根據學號或姓名修改學生信息和成績;
根據學號或姓名刪除學生信息和成績。
下面是一個基於控制台的C語言實現的示例代碼,演示了如何實現上述功能:
c
Copy code
#include <侍臘stdio.h>
#include <stdlib.h>
#include <string.h>
#define MAX_STUDENTS 100 // 最多可管理的學生數
#define MAX_NAME_LEN 20 // 姓名最大長度
// 學生信息結構體
typedef struct {
int id; // 學號
char name[MAX_NAME_LEN];// 姓名
int score; // 成績
} Student;
Student students[MAX_STUDENTS]; // 學生信息數組
int num_students = 0; // 當前學生數量
// 添加學生信息和成績
void add_student() {
if (num_students >= MAX_STUDENTS) {
printf("已達到最大可管理的學生數!\n");
return;
}
printf("請輸入學生的學號:");
scanf("%d", &students[num_students].id);
printf("請搏談枯輸入學生的姓名:");
scanf("%s", students[num_students].name);
printf("請輸入學生的成績:");
scanf("%d", &students[num_students].score);
num_students++;
printf("添加成功!\n");
}
// 顯示所有學生的信基洞息和成績
void show_all_students() {
if (num_students == 0) {
printf("暫無學生信息!\n");
return;
}
printf("%-10s %-20s %-10s\n", "學號", "姓名", "成績");
for (int i = 0; i < num_students; i++) {
printf("%-10d %-20s %-10d\n", students[i].id, students[i].name, students[i].score);
}
}
Ⅷ 用C語言設計一個班級成績管理系統
我幫你
c/c++編程有需求的可以到網路貼吧 codeblocks吧找我
Ⅸ 怎樣用C語言寫學生成績管理系統
程序如下: #include