A. 學生成績管理系統
wo gang xie le ge yao jia Q
B. 一個學生成績管理系統
#include<stdio.h>
#include<string.h>
#include<math.h>
struct student_type
{
char name[8];
int num;
int Class; /*把class第一個字母大寫了,因為在中class為類關鍵字*/
float score[3];
double ave;
}stud[4];
int main()
{
void Write (); /*把write第一個字母大寫了,因為C語言中有write函數 */
void save ();
void display ();
int n=0;
while (1)
{
printf ("\n\t\t\t\t學生成績管理\n\n");
printf ("\t1:請輸入學生的成績記錄\n");
printf ("\t2:顯示成績記錄\n");
printf ("\t3:退出系統\n");
printf ("\t輸入操作選項序號:");
scanf ("%d",&n);
switch (n)
{
case 1 : Write (); break;
case 2 : display (); break;
case 3 : printf("\n\t\t\t**************謝謝使用!**************\n");break;
default : printf("\n請輸入1、2或3!!!");
}
if (n==3) break;
}
system("pause");
return 0;
}
/* *********輸入學生成績**********/
void Write()
{
int i=0, j=0;
for(i=0; i<4 ;i++)
{
printf("\n請輸入學號 姓名 班級 :");
scanf("%d%s%d",&stud[i].num, &stud[i].name, &stud[i].Class);
printf("\n請依次輸入課程成績 :"); /*這句話從循環中移了出來 */
for(j=0; j<3; j++)
{
scanf("%f", &stud[i].score[j]);
}
stud[i].ave = (stud[i].score[0] + stud[i].score[1]
+ stud[i].score[2]) / 3;
}
printf ("\n\t\t是否保存?\n\t\t\t是:1;\n\t\t\t否:2.\n");
scanf ("%d", &i); /* i前面加& */
if (i==1)
save();
else
main();
}
/**********讀出文件資料***********/
void display ()
{
int i=0;
FILE *fp;
fp = fopen ("score.txt","r");
if ((fp=fopen("score.txt","r")) == NULL)
{
printf("cannot open this score");
exit (0);
}
for (i=0; i<4; i++)
{
fscanf (fp, "%11d%s%2d%5.2f%5.2f%5.2f%5.2f\n", &stud[i].num, &stud[i].name[i],
&stud[i].Class, &stud[i].score[0], &stud[i].score[1], &stud[i].score[2],
&stud[i].ave);
printf ("%11d%s%2d%5.2f%5.2f%5.2f%5.2f\n", stud[i].num, stud[i].name[i],
stud[i].Class, stud[i].score[0], stud[i].score[1], stud[i].score[2],
stud[i].ave);
}
fclose (fp);
}
/**********資料寫入文件**********/
void save()
{
FILE *fp ; /* fp無需賦NULL */
int i=0; /* i定義在開始會好些 * /
fp = fopen ("score.txt","w");
fprintf (fp,"學號 姓名 班級 課程1 課程2 課程3 平均成績\n");
for (i=0; i<4; i++)
{
//fwrite(&stud[i], sizeof(struct student_type), 1, fp);
fprintf (fp, "%11d%s%2d%5.2f%5.2f%5.2f%5.2lf\n", stud[i].num, stud[i].name,
stud[i].Class, stud[i].score[0], stud[i].score[1], stud[i].score[2],
stud[i].ave); /*把stud[i].name[i] 改成了stud[i].name */
}
fclose (fp);
printf ("\n\n*******************恭喜,保存完成!*******************\n\n");
}
C. 揚子中學成績管理系統
如果是學籍管理員,建議使用Internet Explorer 8或更高版本的Internet Explorer瀏覽器,在地址欄輸入本省的中小學學生學籍信息管理系統網址,輸入給定的用戶名和自己設定的密碼,驗證碼登錄。 如果不是學校學籍管理員是無法登錄管理系統的。 在...
D. 學生成績管理系統
《人心不可欺》:靜靜山村,芳草依依,幾多風雨,幾多情意。莫道是,良緣本是天作成,只可嘆恩怨情仇,難斷根達地。黃泉茫茫,雖無輪迴路,天地公道,人心不可欺。
E. 班級成績管理系統
兄弟你的分太少了點吧 我還是給你 希望你一定要加分哦
#include"stdio.h"
#include"stddef.h"
#include "stdlib.h"
#include"string.h"
#define MAX 10
typedef struct student{ /*定義結構體*/
char name[MAX]; /*姓名*/
int num[MAX]; /* 學號*/
char sex[MAX]; /*性別*/
int chinese; /*語文*/
int mathematic; /* 數學*/
int english; /*英語*/
int computer; /*計算機*/
struct student *next; /*結構體指針*/
}stu;
stu *head; /*頭指針*/
void print() /*顯示或列印函數*/
{
system("cls");
printf("\t\t\t成績管理系統\n"); /*成績管理系統*/
printf("<1>輸入數據\t"); /*輸入數據*/
printf("<2>顯示\t"); /*顯示*/
printf("<3>插入數據\t"); /*插入數據*/
printf("<4>訪問數據\t"); /*訪問數據*/
printf("<5>以前數據\t"); /*以前數據*/
printf("<6>保留數據\t"); /*保留數據*/
printf("<7>更新數據\t"); /*更新數據*/
printf("<8>語文平均成績\t"); /*語文平均成績*/
printf("<9>數學平均成績\t"); /*數學平均成績*/
printf("<10>英語平均成績\t"); /*英語平均成績*/
printf("<11>計算機平均成績\t"); /*計算機平均成績*/
printf("<12>退出\t\n"); /*退出*/
}
void cin(stu *p1) /*輸入相關數據的函數*/
{ printf("姓名:\n");
scanf("%s",&p1->name);
printf("年齡:\n");
scanf("%d",&p1->num);
printf("性別:\n");
scanf("%s",&p1->sex);
printf("語文:\n");
scanf("%d",&p1->chinese);
printf("數學:\n");
scanf("%d",&p1->mathematic);
printf("英語:\n");
scanf("%d",&p1->english);
printf("計算機:\n");
scanf("%d",&p1->computer);
}
stu *cindata() /*其他數據是否繼續輸入的函數*/
{ stu *p1,*p2;
int i=1;
char ch;
p1=(stu *)malloc(sizeof(stu));
head=p1;
while(i)
{
cin(p1);
printf("是否繼續輸入數據?y/n"); /*是否繼續輸入數據*/
ch=getchar();
ch=getchar();
if(ch=='n'||ch=='N')
{ i=0;
p1->next=NULL;
}
else
{ p2=p1;
p1=(stu *)malloc(sizeof(stu));
p2->next=p1;
}
}
return(p1->next);
}
stu *lookdata(stu *p1) /*查看數據的函數*/
{
while(p1!=NULL)
{ printf("年齡:%d\t",p1->num);
printf("姓名:%s\t",p1->name);
printf("性別:%s\t",p1->sex);
printf("\n");
printf("語文:%d\t",p1->chinese);
printf("數學:%d\t",p1->mathematic);
printf("英語:%d\t",p1->english);
printf("計算機:%d\t",p1->computer);
printf("\n");
p1=p1->next;
}
return p1;
}
void insert() /*通過比較學號來插入數據的函數*/
{ stu *p1,*p3,*p2;
char ch;
p1=head;
p3=(stu *)malloc(sizeof(stu));
p3->next=NULL;
if(head==NULL){ head=p3; return;}
cin(p3);
while(p1!=NULL&&(p1->num<p3->num)) /*通過學號的比較來插入*/
{ p2=p1;p1=p1->next;}
if(p2==head) {p3->next=head; head=p3; return;}
p3->next=p1;
p2->next=p3;
}
find(stu *p2) /*通過姓名查找查看數據的函數*/
{ char name[20];
int b=0;
printf("Enter the name of the student you want to find:"); /*通過姓名查看*/
scanf("%s",name);
while(p2!=NULL)
{if(strcmp(name,p2->name)==0)
{
printf("The data you want has be found\n");
printf(" Name:%s\t",p2->name);
printf("Num:%d\t",p2->num);
printf("sex%s\t",p2->sex);
printf("\n");
printf("Chinese:%d\t",p2->chinese);
printf("Math:%d\t",p2->mathematic);
printf("English:%d\t",p2->english);
printf("Computer:%d\t",p2->computer);
printf("\n");
b=1;
}
else if(b==0)
printf("sorry not find data!");
p2=p2->next;
}
if(b==1)
{
print();
printf("Find one\n");}
else
{print();
printf("Not find\n");
}
}
void caverage() /*求各學生語文平均分、最高和最低分成績的函數*/
{ stu *p1;
int i;
float max=0.0,min=200.0;
float sum=0.0,aver=0;
p1=head;
if(p1==NULL)
printf("not data!");
else
{for(i=0;p1!=NULL;i++,p1=p1->next)
sum+=p1->chinese;
aver=sum/i;
p1=head;
for(i=0;p1!=NULL;i++,p1=p1->next)
{if(max<p1->chinese)
max=p1->chinese;
}
p1=head;
for(i=0;p1!=NULL;i++,p1=p1->next)
if(min>p1->chinese)
min=p1->chinese;
}
printf("Chinese Average:%f",aver);
printf("Chinese Max:%f",max);
printf("Chinese Min:%f",min);
}
void maverage() /*求各學生數學平均分、最高和最低分成績的函數*/
{ stu *p1;
int i;
float max=0.0,min=200.0;
float sum=0.0,aver=0;
p1=head;
if(p1==NULL)
printf("not data!");
else
{for(i=0;p1!=NULL;i++,p1=p1->next)
sum+=p1->mathematic;
aver=sum/i;
p1=head;
for(i=0;p1!=NULL;i++,p1=p1->next)
{if(max<p1->mathematic)
max=p1->mathematic;
}
p1=head;
for(i=0;p1!=NULL;i++,p1=p1->next)
if(min>p1->mathematic)
min=p1->mathematic;
}
printf("Mathe Average:%f",aver);
printf("Mathe Max:%f",max);
printf("Mathe Min:%f",min);
}
void eaverage() /*求各學生英語平均分、最高和最低分成績的函數*/
{ stu *p1;
int i;
float max=0.0,min=200.0;
float sum=0.0,aver=0;
p1=head;
if(p1==NULL)
printf("not data!");
else
{for(i=0;p1!=NULL;i++,p1=p1->next)
sum+=p1->english;
aver=sum/i;
p1=head;
for(i=0;p1!=NULL;i++,p1=p1->next)
{if(max<p1->english)
max=p1->english;
}
p1=head;
for(i=0;p1!=NULL;i++,p1=p1->next)
if(min>p1->english)
min=p1->english;
}
printf("English Average:%f",aver);
printf("English Max:%f",max);
printf("English Min:%f",min);
}
void comaverage() /*求各學生計算機平均分、最高和最低分成績的函數*/
{ stu *p1;
int i;
float max=0.0,min=200.0;
float sum=0.0,aver=0;
p1=head;
if(p1==NULL)
printf("not data!");
else
{for(i=0;p1!=NULL;i++,p1=p1->next)
sum+=p1->computer;
aver=sum/i;
p1=head;
for(i=0;p1!=NULL;i++,p1=p1->next)
{if(max<p1->computer)
max=p1->computer;
}
p1=head;
for(i=0;p1!=NULL;i++,p1=p1->next)
if(min>p1->computer)
min=p1->computer;
}
printf("Computer Average:%f",aver);
printf("Computer Max:%f",max);
printf("Computer Min:%f",min);
}
update(stu *p2) /*通過姓名查找來更新數據*/
{
char name[10]; /*p2為指向結構體struct student的指針*/
int b=0;
printf("Enter The Name"); /*輸入姓名*/
scanf("%s",name);
while(p2!=NULL)
{if(strcmp(name,p2->name)==0)
{
printf("Find you data\n");
scanf("Name:%s",p2->name);
scanf("Num:%s",p2->num);
scanf("Sex:%s",p2->sex);
scanf("Chinese:%d",p2->chinese);
scanf("Math:%d",p2->mathematic);
scanf("english:%d",p2->english);
scanf("Computer:%d",p2->computer);
printf("Success!");
b=1;}
else if(b==0)
printf("Sorry not Find data!");
p2=p2->next;}
if(b==0)
{print();
printf("Sorry not Find data!");
}
else
{
print();
printf("Finish!");
}
}
save(stu *p2) /*保留數據函數*/
{
FILE *fp;
char file[10];
printf("Enter file name"); /*輸入文件名*/
scanf("%s",file);
fp=fopen(file,"w");
while(p2!=NULL)
{
fprintf(fp,"%s",p2->name);
fprintf(fp,"%s",p2->num);
fprintf(fp,"%s",p2->sex);
fprintf(fp,"%d",p2->chinese);
fprintf(fp,"%d",p2->mathematic);
fprintf(fp,"%d",p2->english);
fprintf(fp,"%d",p2->computer);
p2=p2->next;
}
fclose(fp);
}
char password[7]="123456"; /*定義初始密碼*/
void main() /*主函數*/
{ int choice;
stu *p2;
char s[8];
int flag=0,i; /*標志項*/
int n=3;
do{ printf("你請輸入密碼:\n");
scanf("%s",s);
if(!strcmp(s,password)) /*進行密碼匹配驗證*/
{ printf("PASS\n\n\n");
flag=1;
break;
}
else{
printf("Error Enter again:\n");
n--;
}
}
while(n>0);
if(!flag)
{printf("you have Enter 3 times!"); /*輸入密碼超過了3次!!*/
exit(0); /*自動退出*/
}
/*密碼驗證成功後進入的界面*/
printf("歡迎來到重慶航天職業技術學院\n");
printf(" 歡迎來到計算機工程系\n");
printf(" 班級:軟體技術\t班號:08051051\n"); /*班級和號碼*/
printf(" 是否進入系統\n"); /*問進入系統與否*/
scanf("%d",&choice);
if(choice=='n'||choice=='N')
exit(1);
print();
while(1)
{
printf("Enter choice:");
scanf("%d",&i);
if(i<1||i>13)
{
printf("再從1-13中進行選擇:\n"); /*再從1-13中進行選擇*/
exit(1);
}
switch(i)
{ case 1:
p2=cindata(); /*其他數據是否繼續輸入的函數*/
break;
case 2:
p2=lookdata(head); /*查看數據的函數*/
break;
case 3:
insert(); /*通過比較學號來插入數據的函數*/
break;
case 4:
find(head); /*通過姓名查找查看數據的函數*/
break;
case 5:
update(head); /*通過姓名查找來更新數據*/
break;
case 6:
save(head); /*保留數據函數*/
break;
case 7:
print(); /*顯示或列印函數*/
break;
case 8:
caverage(); /*求各學生語文平均分、最高和最低分成績的函數*/
break;
case 9:
maverage(); /*求各學生數學平均分、最高和最低分成績的函數*/
break;
case 10:
eaverage(); /*求各學生英語平均分、最高和最低分成績的函數*/
break;
case 11:
comaverage(); /*求各學生計算機平均分、最高和最低分成績的函數*/
break;
case 12:
; /*空操作*/
case 13:
exit(1); /*退出*/
break;
}
scanf("%d",&i);
}
} 密碼是123456
F. 學生成績管理系統
本人有款小型的學生成績管理系統,操作簡單,EXCEL開發,如稍作修改,能滿足你的要求回。可答在以下地址下載試用:http://ishare.iask.sina.com.cn/cgi-bin/fileid.cgi?fileid=4652007
http://ewsky.qupan.com/804824.html
G. 19. 學生成績管理系統
C語言課程設計任務書
一、題目: 學生成績管理
二、目的與要求
1. 目的:
(1)基本掌握面向過程程序設計的基本思路和方法;
(2)達到熟練掌握C語言的基本知識和技能;
(3)能夠利用所學的基本知識和技能,解決簡單的程序設計問題
2. 要求
基本要求:
1. 要求利用C語言面向過程的編程思想來完成系統的設計;
2. 突出C語言的函數特徵,以多個函數實現每一個子功能;
3. 畫出功能模塊圖;
4. 進行簡單界面設計,能夠實現友好的交互;
5. 具有清晰的程序流程圖和數據結構的詳細定義;
6. 熟練掌握C語言對文件的各種操作。
創新要求:
在基本要求達到後,可進行創新設計,如系統用戶功能控制,對管理員級和一般級別的用戶系統功能操作不同
三、信息描述
輸入一個班10個學生的學號和每個學生考試三門功課(數學、英語、計算機基礎)的成績。編程計算出每個學生的總分和平均分,並按學生成績優劣排序,最後列印一張按高分到低分名次排序的成績單。要求:
1)排序用一個函數實現。
2)列印的成績單表項包括:序號,學號、數學、英語、計算機、總分、平均分。
3)按實驗報告電子模板格式填寫實驗內容。
四、功能描述
1. 學生基本信息及成績所選科目成績的錄入。
2. 基本信息的查詢(分系、班級;分科目)與修改。
3. 對每系或每班各科成績進行分析(即求單科平均成績、及格率和優秀率);
4. 對所開課程的成績分析(求其平均成績,最高分和最低分);
5. 對學生考試成績進行排名(單科按系別或班級進行排名,對每一個班級,同一學期學生總體成績進行排名,並顯示各科成績信息)
五、解決方案
1. 分析程序的功能要求,劃分程序功能模塊。
2. 畫出系統流程圖。
3. 代碼的編寫。定義數據結構和各個功能子函數。
4. 程序的功能調試。
5. 完成系統總結報告以及使用說明書
六、進度安排
此次課程設計時間為兩周,分四個階段完成:
1. 分析設計階段。指導教師應積極引導學生自主學習和鑽研問題,明確設計要求,找出實現方法,按照需求分析、總體設計、詳細設計這幾個步驟進行。
2. 編碼調試階段:根據設計分析方案編寫C代碼,然後調試該代碼,實現課題要求的功能。
3. 總結報告階段:總結設計工作,寫出課程設計說明書,要求學生寫出需求分析、總體設計、詳細設計、編碼、測試的步驟和內容。
4. 考核階段。
#include <stdio.h>
#include <stdlib.h>
#define STU_NUM 10 /*宏定義學生的數量*/
struct student /*定義一個結構體用來存放學生學號、三門課成績、總分及平均成績*/
{
char stu_id[20]; /*學生學號;*/
float score[3]; /*三門課成績;*/
float total; /*總成績;*/
float aver; /*平均成績;*/
};
/*排序用一個函數來實現*/
void SortScore(student *stu,int n)
{
student stud;
for(int i = 0; i < n-1; i++)
for(int j = i+1 ; j < n; j++)
{
if(stu[i].total < stu[j].total)
{
stud = stu[i];
stu[i] = stu[j];
stu[j] = stud;
}
}
}
int main( )
{
student stu[STU_NUM]; /*創建結構體數組中有10個元素,分別用來保存這10個人的相關信息。*/
/*輸入這十個學生的相關信息*/
for(int i = 0; i<STU_NUM; i++)
{
printf("請輸入第%d個學生的學號:",i+1);
scanf("%s",&stu[i].stu_id);
printf("輸入第%d個學生的數學成績:",i+1);
scanf("%f",&stu[i].score[0]);
printf("輸入第%d個學生的英語成績:",i+1);
scanf("%f",&stu[i].score[1]);
printf("輸入第%d個學生的計算機成績:",i+1);
scanf("%f",&stu[i].score[2]);
stu[i].total = stu[i].score[0]+stu[i].score[1]+stu[i].score[2];
stu[i].aver = stu[i].total/3;
}
printf("\n");
SortScore(stu,STU_NUM);/*調用排序函數*/
/*輸出排序後的各學生的成績*/
for(i = 0 ; i < STU_NUM; i++)
{
printf("序號: %d\t",i);
printf("學號:%s\t",stu[i].stu_id);
printf("數學:%f\t",stu[i].score[0]);
printf("英語:%f\t",stu[i].score[1]);
printf("計算機:%f\t",stu[i].score[2]);
printf("平均成績:%f\t",stu[i].aver);
printf("總分:%f\t",stu[i].total);
printf("\n\n");
}
return 0;
}
註:(源程序中主要標識符含義說明)
#define STU_NUM 10 /*宏定義學生的數量*/
struct student /*定義一個結構體用來存放學生學號、三門課成績、總分及平均成績*/
{
char stu_id[20]; /*學生學號;*/
float score[3]; /*三門課成績;*/
float total; /*總成績;*/
float aver; /*平均成績;*/
}
實驗結果:
輸入 :(只輸入後面的數字,前面的文字是自己產生的)。
請輸入第1個學生的學號:001
輸入第1個學生的數學成績:1
輸入第1個學生的英語成績:1
輸入第1個學生的計算機成績:1
請輸入第2個學生的學號:002
輸入第2個學生的數學成績:2
輸入第2個學生的英語成績:2
輸入第2個學生的計算機成績:2
請輸入第3個學生的學號:003
輸入第3個學生的數學成績:3
輸入第3個學生的英語成績:3
輸入第3個學生的計算機成績:3
請輸入第4個學生的學號:004
輸入第4個學生的數學成績:4
輸入第4個學生的英語成績:4
輸入第4個學生的計算機成績:4
請輸入第5個學生的學號:005
輸入第5個學生的數學成績:5
輸入第5個學生的英語成績:5
輸入第5個學生的計算機成績:5
請輸入第6個學生的學號:006
輸入第6個學生的數學成績:6
輸入第6個學生的英語成績:6
輸入第6個學生的計算機成績:6
請輸入第7個學生的學號:007
輸入第7個學生的數學成績:7
輸入第7個學生的英語成績:7
輸入第7個學生的計算機成績:7
請輸入第8個學生的學號:008
輸入第8個學生的數學成績:8
輸入第8個學生的英語成績:8
輸入第8個學生的計算機成績:8
請輸入第9個學生的學號:009
輸入第9個學生的數學成績:9
輸入第9個學生的英語成績:9
輸入第9個學生的計算機成績:9
請輸入第10個學生的學號:010
輸入第10個學生的數學成績:10
輸入第10個學生的英語成績:10
輸入第10個學生的計算機成績:10
輸出:
序號: 0 學號:010 數學:10.000000 英語:10.000000 計算機:10.000000
平均成績:10.000000 總分:30.000000
序號: 1 學號:009 數學:9.000000 英語:9.000000 計算機:9.000000
平均成績:9.000000 總分:27.000000
序號: 2 學號:008 數學:8.000000 英語:8.000000 計算機:8.000000
平均成績:8.000000 總分:24.000000
序號: 3 學號:007 數學:7.000000 英語:7.000000 計算機:7.000000
平均成績:7.000000 總分:21.000000
序號: 4 學號:006 數學:6.000000 英語:6.000000 計算機:6.000000
平均成績:6.000000 總分:18.000000
序號: 5 學號:005 數學:5.000000 英語:5.000000 計算機:5.000000
平均成績:5.000000 總分:15.000000
序號: 6 學號:004 數學:4.000000 英語:4.000000 計算機:4.000000
平均成績:4.000000 總分:12.000000
序號: 7 學號:003 數學:3.000000 英語:3.000000 計算機:3.000000
平均成績:3.000000 總分:9.000000
序號: 8 學號:002 數學:2.000000 英語:2.000000 計算機:2.000000
平均成績:2.000000 總分:6.000000
序號: 9 學號:001 數學:1.000000 英語:1.000000 計算機:1.000000
平均成績:1.000000 總分:3.000000
七、撰寫課程設計報告或課程設計總結
課程設計報告要求:
總結報告包括需求分析、總體設計、詳細設計、編碼(詳細寫出編程步驟)、測試的步驟和內容、課程設計總結、參考資料等,不符合以上要求者,則本次設計以不及格記。
C語言常見錯誤
書寫標識符時,忽略了大小寫字母的區別
main()
{
int a=5;
printf("%d",A);
}
編譯程序把a和A認為是兩個不同的變數名,而顯示出錯信息。C認為大寫字母和小寫字母是兩個不同的字元。習慣上,符號常量名用大寫,變數名用小寫表示,以增加可讀性。
2.忽略了變數的類型,進行了不合法的運算。
main()
{
float a,b;
printf("%d",a%b);
}
%是求余運算,得到a/b的整余數。整型變數a和b可以進行求余運算,而實型變數則不允許進行「求余」運算。
3.將字元常量與字元串常量混淆。
char c;
c="a";
在這里就混淆了字元常量與字元串常量,字元常量是由一對單引號括起來的單個字元,字元串常量是一對雙引號括起來的字元序列。C規定以「\」作字元串結束標志,它是由系統自動加上的,所以字元串「a」實際上包含兩個字元:『a'和『\',而把它賦給一個字元變數是不行的。
4.忽略了「=」與「==」的區別。
在許多高級語言中,用「=」符號作為關系運算符「等於」。如在BASIC程序中可以寫
if (a=3) then …
但C語言中,「=」是賦值運算符,「==」是關系運算符。如:
if (a==3) a=b;
前者是進行比較,a是否和3相等,後者表示如果a和3相等,把b值賦給a。由於習慣問題,初學者往往會犯這樣的錯誤。
5.忘記加分號。
分號是C語句中不可缺少的一部分,語句末尾必須有分號。
a=1
b=2
編譯時,編譯程序在「a=1」後面沒發現分號,就把下一行「b=2」也作為上一行語句的一部分,這就會出現語法錯誤。改錯時,有時在被指出有錯的一行中未發現錯誤,就需要看一下上一行是否漏掉了分號。
{ z=x+y;
t=z/100;
printf("%f",t);
}
對於復合語句來說,最後一個語句中最後的分號不能忽略不寫(這是和PASCAL不同的)。
6.多加分號。
對於一個復合語句,如:
{ z=x+y;
t=z/100;
printf("%f",t);
};
復合語句的花括弧後不應再加分號,否則將會畫蛇添足。
又如:
if (a%3==0);
I++;
本是如果3整除a,則I加1。但由於if (a%3==0)後多加了分號,則if語句到此結束,程序將執行I++語句,不論3是否整除a,I都將自動加1。
再如:
for (I=0;I<5;I++);
{scanf("%d",&x);
printf("%d",x);}
本意是先後輸入5個數,每輸入一個數後再將它輸出。由於for()後多加了一個分號,使循環體變為空語句,此時只能輸入一個數並輸出它。
7.輸入變數時忘記加地址運算符「&」。
int a,b;
scanf("%d%d",a,b);
這是不合法的。Scanf函數的作用是:按照a、b在內存的地址將a、b的值存進去。「&a」指a在內存中的地址。
8.輸入數據的方式與要求不符。①scanf("%d%d",&a,&b);
輸入時,不能用逗號作兩個數據間的分隔符,如下面輸入不合法:
3,4
輸入數據時,在兩個數據之間以一個或多個空格間隔,也可用回車鍵,跳格鍵tab。
②scanf("%d,%d",&a,&b);
C規定:如果在「格式控制」字元串中除了格式說明以外還有其它字元,則在輸入數據時應輸入與這些字元相同的字元。下面輸入是合法的:
3,4
此時不用逗號而用空格或其它字元是不對的。
3 4 3:4
又如:
scanf("a=%d,b=%d",&a,&b);
輸入應如以下形式:
a=3,b=4
9.輸入字元的格式與要求不一致。
在用「%c」格式輸入字元時,「空格字元」和「轉義字元」都作為有效字元輸入。
scanf("%c%c%c",&c1,&c2,&c3);
如輸入a b c
字元「a」送給c1,字元「 」送給c2,字元「b」送給c3,因為%c只要求讀入一個字元,後面不需要用空格作為兩個字元的間隔。
10.輸入輸出的數據類型與所用格式說明符不一致。
例如,a已定義為整型,b定義為實型
a=3;b=4.5;
printf("%f%d\n",a,b);
編譯時不給出出錯信息,但運行結果將與原意不符。這種錯誤尤其需要注意。
11.輸入數據時,企圖規定精度。
scanf("%7.2f",&a);
這樣做是不合法的,輸入數據時不能規定精度。
12.switch語句中漏寫break語句。
例如:根據考試成績的等級列印出百分制數段。
switch(grade)
{ case 'A':printf("85~100\n");
case 'B':printf("70~84\n");
case 'C':printf("60~69\n");
case 'D':printf("<60\n");
default:printf("error\n");
由於漏寫了break語句,case只起標號的作用,而不起判斷作用。因此,當grade值為A時,printf函數在執行完第一個語句後接著執行第二、三、四、五個printf函數語句。正確寫法應在每個分支後再加上「break;」。例如
case 'A':printf("85~100\n");break;
13.忽視了while和do-while語句在細節上的區別。
(1)main()
{int a=0,I;
scanf("%d",&I);
while(I<=10)
{a=a+I;
I++;
}
printf("%d",a);
}
(2)main()
{int a=0,I;
scanf("%d",&I);
do
{a=a+I;
I++;
}while(I<=10);
printf("%d",a);
}
可以看到,當輸入I的值小於或等於10時,二者得到的結果相同。而當I>10時,二者結果就不同了。因為while循環是先判斷後執行,而do-while循環是先執行後判斷。對於大於10的數while循環一次也不執行循環體,而do-while語句則要執行一次循環體。
14.定義數組時誤用變數。
int n;
scanf("%d",&n);
int a[n];
數組名後用方括弧括起來的是常量表達式,可以包括常量和符號常量。即C不允許對數組的大小作動態定義。
15.在定義數組時,將定義的「元素個數」誤認為是可使的最大下標值。
main()
;
printf("%d",a[10]);
}
C語言規定:定義時用a[10],表示a數組有10個元素。其下標值由0開始,所以數組元素a[10]是不存在的。
16.初始化數組時,未使用靜態存儲。
int a[3]=;
這樣初始化數組是不對的。C語言規定只有靜態存儲(static)數組和外部存儲(exterm)數組才能初始化。應改為:
static int a[3]=;
17.在不應加地址運算符&的位置加了地址運算符。
scanf("%s",&str);
C語言編譯系統對數組名的處理是:數組名代表該數組的起始地址,且scanf函數中的輸入項是字元數組名,不必要再加地址符&。應改為:
scanf("%s",str);
18.同時定義了形參和函數中的局部變數。
int max(x,y)
int x,y,z;
{z=x>y?x:y;
return(z);
}
形參應該在函數體外定義,而局部變數應該在函數體內定義。應改為:
int max(x,y)
int x,y;
{int z;
z=x>y?x:y;
return(z);
}
另外,虛機團上產品團購,超級便宜
H. 學生成績管理系統
學生成績管理系統C代碼
/ *頭文件* /
#包括
包括
#包括 / *其他指令* /
包括中/ *字元串函數* /
/ *內存操作函數* /
/ *字元處理函數* /
包括 / *動態地址分配函數* /
定義:LEN大小(學生)
typedef結構中,學??生/ *定義結構數組,用於緩存數據* /
{字元數[6];
字元名稱[5];
得分[3];
int總和;
>浮動平均水平;
詮釋訂單
結構STU *下;
}的學生;
/ *函數原型* /
學生的init( );/ /初始化函數* /
詮釋MENU_SELECT的(); / *菜單函數* /
學生的create(); / *創建的鏈表* /
無效列印(學生*頭); / *顯示所有記錄* /
無效搜索(學生*頭); / *找到記錄* /
學生刪除(STUDENT *頭); / *刪除記錄* / />學生排序(學生頭); / *排序* /
學生(學生*頭,新的學生*); *插入/ *插入記錄* /
無效保存(的學生頭); / *保存文件* /
學生的load(); / *讀取文件* /
/ *主函數介面* /
主()
{的學生*頭,新的;
頭的init(); / *初始化鏈表頭的值是NULL * /
(;) / *循環無限* /
{開關(menu??_select())
{
案例1:頭= create()方法的突破;
案例2:列印(頭);休息;
案例3:搜索(頭);突破;
情況下,4頭=刪除(頭);突破;
情況下5頭排序(頭);突破;
案例6:頭插入(頭,與新的);打破; / *新的返回地址* /
案例7:保存(頭);
案例8:頭=負載(
案例9:退出);突破;(0)/ *如果菜單,返回值是年底的9個項目* /
}
}
}
/ *初始化函數* /
學生的init()
{
返回NULL; / *返回一個空指針* /
}
a>
/ *菜單選擇功能* /
menu_select
{N;
結構日期d / *定義的時間結構* / /> GETDATE(&D)/ *讀取系統日期,並把它在結構上D * /
printf的(「按任意鍵進入菜單......」); / *按任意鍵進入主菜單* /
的getch(); / *讀取從鍵盤輸入一個字元,但不顯示在屏幕上* /
clrscr(); / *清屏* / /> printf(「請********************************************* *********************************** \ n「);
printf(」請\ T \噸的\ n「);
printf(」請\ n \ t \ t學生成績管理系統\ n「);
printf(」請************ ************************* MENU ************************ *************** \ n「);
printf的(」\ t \ t \ T1輸入記錄\ n「); / *輸入學生記錄* / BR /> printf的(「\ t \ t \ T2列印記錄\ n」); / *顯示* /
printf的(「\ t \ t \ T3的搜索記錄名稱\ n」); / * * /
printf的(「\ t \ t \ T4。刪除記錄\ n」); / *刪除* /
printf的(「\ t \ t \ T5。排序,使新的文件\ n「); / *排序* / <br /輸出(」\ t \ t \ T6插入記錄到列表\ n「); / *插入* /
printf的(」\ t \ t \ T7保存的文件\ n「); / *保存* /
printf的(」\ t \ t \ T8負載的文件\ n「); / *讀* /
printf的(」\ t \ T \ T9退出\ n「); / *退出* /
printf的(」\ n \ t \ t胡嘿黌\ n「);
printf的(」****** ************************************************** ************************ \ n「);
printf的(」\ t \ t \ t \ t%d \ \%d的\ \%e\「,d.da_year,d.da_mon,d.da_day); / *顯示當前系統日期* /
做{
printf的(」\ n \ t \ t \拉幅機的選擇(1?9):「);
scanf的(」%d「,&N);
}(N 9)/ *如果該選項是不減肥9 * /
回報率(N); / *返回選項的數量,主要功能調用相應的函數* /
}
/ *輸入函數* /
學生創??建()
{I,S
學生頭= NULL,* P / *定義函數這個函數返回一個指針表頭指針* /
Clrscr();
(;)
{P =(學生)的malloc(LEN); / *打開了一個新的單元* / BR />(P)/ *如果指針p是空* /
{printf的(「\ Nout的記憶。」); / *輸出內存溢出* /
回報(頭); / *返回頭指針,下同* /
}
printf的(「請輸入NUM(0:列表結束):」);
scanf的(「%s」,P-> NUM);
(P->數[0] == '0')打破; / *如果第一個字元的學生數0輸入* /
printf(「請結束輸入姓名:「);
scanf的(」%s「,P->名稱);
printf(」請輸入%D分數\ n「); / *迅速啟動分型結果* /
= 0; / *計算每個學生的總成績,初始值為0 * /
(i = 0; I <3; i + +)/ * 3個療程周期的3倍* /
{
做{
printf的(「得分%D:」,i +1);
scanf的(「%d」的,普 - >得分[I]);
(P->得分[I] 得分[I]> 100)/ *確保得分在0至100之間* /
printf的(「數據錯誤,請重新輸入\ n」);
}而(P>得分[I] [I]> 100分);
= S + P->得分[I] / *堆積門的成績* /
}
P->總和= S / *節省的總成績* /
對平均= (浮)/ 3; / *首先轉換類型轉換s轉換為float類型,然後尋求的平均* /
P->訂單= 0; / *在此之前的值排序為0 * / BR /> P> =頭; / *頭節點作為一個新的輸入節點的後繼節點* /
頭= P / *新的輸入節點作為新的頭節點* /
}
a>回報(頭);
}
/ *顯示所有記錄函數* / >無效列印(學生頭)
{i = 0; / *統計記錄數* /
學生* P / *移動指針* /
Clrscr();
P =頭; / *初始的頭指針* / /> printf(「請\ n ************************************學生****** ****************************** \ n「);
printf(」請---- -------------------------------------------------- --------------------- \ n「); <br /輸出(」|記錄|編號|名稱| SC1 SC2 SC3 |森|大道|訂單| \ n「);
printf的(」------------------------------------ ------------------------------------------- \ n「); ...... />而(p! = NULL)
{
+ +;
printf的(「|%3D |%4 |%|%-4S 3D | 3D | 3D | %的3d |%4.2f |%-5d的| \「,
,對 - >數,對 - >名稱,對 - >分數[0],對 - >分數[1],對 - > [2分],P->總之,對平均,P->訂單);
P = P->下;
}
printf的(「------ -------------------------------------------------- ----------------------- \ n「);
printf的(」*************** *********************** END ************************** ************ \ n「);
}
/ *查找錄音功能* /
無效搜索(學生*頭) BR /> {STUDENT * p; / *移動指針* /
個char [5]; / *商店的名稱的字元數組* /
Clrscr();
scanf函數
printf的(「請輸入您的名字進行搜索。\ n」);(%S「,S);
P =頭; / *分配的頭指針P * /
而(STRCMP(P->名稱,s)&& P = NULL)/ *的名稱的記錄時不看,或指針的時空* /
P = P-> / *移動指針指向下一個節點* /
(p! = NULL)/ *如果指針不為空* /
{printf(「請\ n ******** ***************************** FOUND ******************** **************** \ n「);
printf(」請---------------------- -------------------------------------------------- ------- \ n「);
printf的(」|編號|名稱| SC1 SC2 | SC3 |森|大道|訂購| \ n「);
printf的(」 - -------------------------------------------------- --------------------------- \ n「);
printf的(」| 4 |%4S |%3D |%三維|%的3d |%的3d |%4.2f |%-5d的| \ N「,
對 - >數,對 - >名稱,對 - >分數[0],對 - >分數[1],對 - >分數[2],對 - >總和,對 - >平均,對 - >順序);
printf(「請------------------- -------------------------------------------------- --------- \ n「);
printf的(」***************************** ********** END ************************************** \ N「);
}
其他
printf的(」\ n該網頁的沒有NUM%的學生在名單上。\ n「); / *學生* /
}
/ *刪除記錄的函數* /
學生*頭*刪除(學生)
學生{N; * P1 * P2 / * P1是找到要刪除一個節點的指針,P2及其前體的指針* /
字元c的s [6] / [6]用來存儲學生數,c是用於輸入字母* / </ clrscr();
printf的(「請輸入刪除的民:」);
scanf的(「%s」);
P1 = P2 =頭; / * P1和P2富最初的頭指針* /
(STRCMP(P1-NUM)&& P1 = NULL)/ *當記錄數的學校不看,或指針不為空* / /> {P2 = P1 / * P1指針的值分配給P2 P1前體指針* /
P1 = P1->; / *點p1指針到下一條記錄* /
} BR />(STRCMP(P1->民)== 0)/ *學生ID * /
{printf的(「***************** ********************* FOUND **************************** ******** \ n「);
printf(」請------------------------------ ------------------------------------------------- \ N「);
printf的(」|編號|名稱| SC1 SC2 | SC3 |森|大道|在線訂單| \ n「);
printf的(」--------- -------------------------------------------------- -------------------- \ n「);
printf的(」| 4 |%4S |%3D | 3D | 3D | 3D |%4.2f%5D | \ n「,
P1->民,P1->名稱,P1->得分[0],P1 - > [1分],P1->得分[2] ,P1->總之,P1->平均,P1->訂單);
printf的(「-------------------------- -------------------------------------------------- --- \ n「);
printf(」請*********************************** **** END ************************************** \ n「); ...... /> printf的(「你確定要刪除的學生Y / N?」); / *提示你是否要刪除,輸入y刪除n退出* /
(;)
/> {scanf函數(「%C」,&C);
(C =='N'| | C =='N'); / *如果你不刪除,然後跳出循環* /
(C =='Y'| | C =='Y')
{
(P1 ==頭)/ * P1 ==頭,被刪除節點是第一個節點* /
頭= P1->下; / *第二個節點的地址給頭* /
其他
P2->下一個= P1-> /否則,請單擊節點地址被分配到前一個節點的地址* /
N = N-1; <br /輸出(「\ nNum%的學生已被刪除。\ n」,S); /> printf的(「不要忘記保存。\ n」); / *循環後已被刪除* /
}
}
} 其他
printf的(「\ n該網頁的沒有NUM%的學生在名單上。\ n」); /,找不到節點* /
回報(頭);
}
/ *排序函數* /
學生排序(學生頭)
{INT I = 0; / *保存排名* /
學生* P1, * P2 * T,*溫度; / *定義一個臨時指針* /
溫度=頭下; / *原來的下一個節點的指針表頭的頭指針* /
頭> = NULL; / *頭節點的新表的第一個節點* /
(temp! = NULL)/ *當原表不為空,進行排??序* /
{
T =溫度; / *取前表節點* /
TEMP =溫度 - >; / *原來的頭節點的指針向後* /
P1 =頭/頭*移動指針P1指針從頭開始* /
P2 =頭; / *移動指針P2為的P1前驅體的頭指針的初始值* /
而(平均平均&& P1 = NULL)/ *成績平均比??較* /
{
P2 = P1 / *點值小進行排序,新表指針落後* /
P1 = P1->下;
}
(P1 == P2)/ * P1 == P2,點值進行排序,應該排在第一個* / BR /> {
T-> = P1;進行排序的繼任者的p * /
頭= T / * / *新的頭節點進行排序點* /
}
的else / *進行排序點應插入在中間的位置p2和p1的,例如為p的空尾之間* /
{
叔 - >下一個= p1的; / * t的後繼是p1 * /
P2-> = T / * P2的繼任噸* /
}
}
P1 =頭; / *排序頭指針被分配到P1准備填寫的排名* /
(p1! = NULL)/ * p1是不是空的,下面的操作* /
{
+ +; / *節點數量* /
P1->訂單; / *分配的節點數量的排名* /
P1 = P1->; / *指針後移* /
}
printf的(「的排序是SUCESSFUL。\ n」排序;} / *成功* /
回報(頭);
}
/ *插入記錄功能* /
學生插入(學生頭STUDENT *新)
{STUDENT * P0,P1,P2;
整數N,SUM1;
P1 =頭/ * P1點的第一個節點* /
P0 =新/ * P0點要插入節點* /
printf的(「\ n請輸入一個新的記錄。\ n」) / *提示信息記錄* /
printf的(「請輸入數量:」);
scanf函數(「%s」的新數);
printf(「輸入的名稱:「);
scanf的(」%s「的新名);
printf的(」請輸入%d的分數。\ n「);
SUM1 = 0; / *保存新的得分紀錄,初始值為0 * /
為(i = 0; I <3; i + +)
{
做{
printf的(「得分%D:「,i +1);
scanf的(」%d「的,與新>得分[]);
(新 - >得分[I]> 100 | |新 - >得分[I] <0)
printf(「請數據錯誤,請重新輸入。\ n」);
}而(新 - >評分[我]> 100 | |新 - >評分[I] <0);
SUM1 = SUM1 +新 - >得分[I] / *累計門成績* /
}
新 - >金額= SUM1; /存款總額新的記錄* /
新的平均=()SUM1 / 3;
新訂單= 0;
(頭== NULL)/ *原鏈表為空表* /
{頭= P0,P0-> = NULL;} / *節點指出P0口作為頭節點* /
其他
{((P0->平均平均)&&(P1->!= NULL))
{P2 = P1 / P2點只是P1結點* /
P1 = P1->; / * P1落後節點* /
}
(P0->平均> = P1->平均)
{如果(頭== P1)頭= P0 / *插入到原來的第一個節點* / />其他P2-> = P0 / *在插入節點* /
P0-> = P1;}
其他
{P1->下一個= P0到P2點P0-> = NULL;} / *上的最後一個節點* /
}
N = N +1; / *節點數目加1 * /
頭排序(頭); / *調用sort函數的學生的成績重新排序* /
printf的(「,已插入\ nStudent%s的。\ n」,新名);
printf的(「不要忘記保存新的文件。\ n「);
回報(頭);
}
/ *將數據保存到文件函數* /
無效保存(學生*頭)
{FILE * FP; / *定義點文件指針* /
STUDENT * p; / *定義移動指針* /
字元,OUTFILE [10];
輸出(「請輸入OUTFILE名稱,例如C:\ \成績\ n」);
scanf的(「%s」,OUTFILE);
((FP =打開(OUTFILE,「WB」) )== NULL)/ *為輸出打開一個二進制文件,只寫* /
{
printf的(「無法打開文件\ n」);
回報; / *如果您無法打開返回菜單* /
}
printf的(「\ nSaving的文件... \ n」);
P =頭; / *移動指針從頭開始* /
而(p! = NULL)/ * p不為空* /
{
FWRITE(P,LEN,1,FP); / *寫的指針記錄* /
P = P->下; / *指針後移* /
}
FCLOSE(FP); / *關閉文件* /
printf的(「將文件保存成功!\ n「);
}
/ *從文件功能* /
學生中讀取數據負載()
{STUDENT * P1 * P2 *頭= NULL; / *定義記錄指針變數* /
FILE * FP / *定義指向文件的指針* /
字元的infile [10];
printf的(「輸入INFILE名稱,例如c:\ \成績\ n「);
scanf的(」%s「,infile中);
((FP =的FOPEN(INFILE,」包「))= = NULL)/ *打開一個二進制文件只讀* /
{
printf的(「無法打開文件\ n」);
回報(頭);
}
printf的(「\ n載入的文件!\ n」);
P1 =(學生)的malloc(LEN); / *開辟了一條新的單位* /
(P1 )
{
printf的(「內存不足!\ n」);
回報(頭);
}
頭= P1 / *適用於空間,作為頭指針* /
同時(!的feof(FP))/ *循環讀取數據,直到年底結束的文件* / {
(FREAD(P1,LEN,1,FP)= 1)打破; / *如果你不讀出的數據的循環* /
P1-> =(學生)的malloc(LEN); / *下一個結點打開空間* /
(P1->)
{
printf的(「內存不足!\ n」);
回報(頭); BR />}
P2 = P1 / P2點只是P1結點* /
P1 = P1->; / *指針回新讀入數據鏈當前的表* /
}
P2-> = NULL; / *最後一個節點的繼任指針為空* /
FCLOSE(FP);
輸出( 「你已經成功從文件中讀取數據!\ n」);
回報(頭);
}
I. 成績管理系統
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#define N 3
struct student{
int id;
char name[30];
char cla[10];
float scores[N];
struct student *next;
};
typedef struct student Student;
Student *s=0;
void add(int id,char name[],char cla[],float scores[]){
if(s==0){
s=(Student *)malloc(sizeof(Student));
s->id=id;
strcpy(s->name,name);
strcpy(s->cla,cla);
int i;
for(i=0;i<N;i++)
s->scores[i]=scores[i];
s->next=0;
}
else{
Student *p=s;
while(p->next!=0){
if(p->id==id){
printf("Same id existing in the record.\n");
return;
}
p=p->next;
}
Student *t=(Student *)malloc(sizeof(Student));
t->id=id;
strcpy(t->name,name);
strcpy(t->cla,cla);
int i;
for(i=0;i<N;i++)
t->scores[i]=scores[i];
t->next=0;
p->next=t;
}
}
void display(){
Student *p=s;
int i;
printf("ID Name Class Chinese Mathematics English\n");
while(p!=0){
printf("%2d %s %s ",p->id,p->name,p->cla);
for(i=0;i<N;i++)
printf("%10.2f",p->scores[i]);
printf("\n");
p=p->next;
}
}
void search(int id){
Student *p=s;
int i;
while(p!=0){
if((p->id)==id) {
printf("ID Name Class Chinese Mathematics English\n");
printf("%2d %s %s ",p->id,p->name,p->cla);
for(i=0;i<N;i++)
printf("%10.2f",p->scores[i]);
printf("\n");
return;
}
else p=p->next;
}
printf("No such record.\n");
}
Student *del(int id){
Student *p1=s;
Student *p2=p1;
if(s->id==id){s=s->next;free(p1);return s;}
else{
while(p1!=0){
p2=p1;
p1=p1->next;
if(p1->id==id){
p2->next=p1->next;
free(p1);
return s;
}
}
printf("No such id exists.\n");
return s;
}
}
Student *insert(Student *n,int index){
if(index<0) return 0;
else if(index==0) {n->next=s;return n;}
else{
Student *p2=s;
while(index>1){
p2=p2->next;
index--;
}
n->next=p2->next;
p2->next=n;
return s;
}
}
void modify(int id){
Student *p=s;
while(p!=0){
if(p->id==id) break;
else p=p->next;
}
if(p==0){
printf("No such record exists.\n");
return;
}
int i;
printf("ID Name Class Chinese Mathematics English\n");
printf("%2d %s %s ",p->id,p->name,p->cla);
for(i=0;i<N;i++)
printf("%10.2f",p->scores[i]);
printf("\n");
int c;
printf("What do you want to change?\n");
printf("1.ID 2.Name 3.Class 4.Scores\n");
scanf("%d",&c);
if(c==1){
int i;
printf("Enter the new ID: ");
scanf("%d",&i);
p->id=i;
}
else if(c==2){
char n[20];
printf("Enter the new name: ");
scanf("%s",n);
strcpy(p->name,n);
}
else if(c==3){
char n[20];
printf("Enter the new class: ");
scanf("%s",n);
strcpy(p->cla,n);
}
else if(c==4){
int i;
float f;
printf("Which score do you want to change?\n");
printf("1.Chinese 2.Mathematics 3.English\n");
scanf("%d",&i);
printf("Enter the new score: ");
scanf("%f",&f);
p->scores[i-1]=f;
}
printf("%5d %s %s ",p->id,p->name,p->cla);
for(i=0;i<N;i++)
printf("%10.2f",p->scores[i]);
printf("\n");
}
void sort(){
Student *p=s;
int i,j,m,l,c;
printf("How are you going to sort the records?\n");
printf("1.By ID 2.By name 3.By class 4.By score\n");
scanf("%d",&c);
for(i=0;p!=0;i++)
p=p->next;
l=i;
Student **arr=(Student **)calloc(l,sizeof(Student *));
p=s;
for(i=0;i<l;i++){
arr[i]=p;
p=p->next;
}
if(c==1){
int mid;
for(i=0;i<l-1;i++){
m=i;
mid=arr[i]->id;
for(j=i+1;j<l;j++)
if(arr[j]->id<mid){
m=j;
mid=arr[j]->id;
}
Student *t=arr[i];
arr[i]=arr[m];
arr[m]=t;
}
}
else if(c==2){
char mname[30];
for(i=0;i<l-1;i++){
m=i;
strcpy(mname,arr[i]->name);
for(j=i+1;j<l;j++)
if(strcmp(mname,arr[j]->name)>0){
m=j;
strcpy(mname,arr[j]->name);
}
Student *t=arr[i];
arr[i]=arr[m];
arr[m]=t;
}
}
else if(c==3){
char mclass[10];
for(i=0;i<l-1;i++){
m=i;
strcpy(mclass,arr[i]->cla);
for(j=i+1;j<l;j++)
if(strcmp(mclass,arr[j]->cla)>0){
m=j;
strcpy(mclass,arr[j]->cla);
}
Student *t=arr[i];
arr[i]=arr[m];
arr[m]=t;
}
}
else if(c==4){
int a;
printf("By which subject do you want to sort?\n");
printf("1.Chinese 2.Mathematics 3.English\n");
scanf("%d",&a);
float score;
for(i=0;i<l-1;i++){
m=i;
score=arr[i]->scores[a-1];
for(j=i+1;j<l;j++)
if(score>arr[j]->scores[a-1]){
m=j;
score=arr[j]->scores[a-1];
}
Student *t=arr[i];
arr[i]=arr[m];
arr[m]=t;
}
}
arr[l-1]->next=0;
s=arr[0];
p=s;
for(i=1;i<l;i++){
p->next=arr[i];
p=p->next;
}
}
void statistics(){
float total_scores[N]={0,0,0};
Student *p=s;
int i,j;
for(i=0;p!=0;i++){
for(j=0;j<N;j++)
total_scores[j]+=p->scores[j];
p=p->next;
}
printf("The number of students are %d.\n",i);
printf("The average scores for each subjects are:\n");
printf("Chinese Mathematics English\n");
for(j=0;j<N;j++)
printf("%8.2f",total_scores[j]/i);
printf("\n");
}
int main(){
int i;
do{
printf("Enter the function you want:\n");
printf("1. Add 2.Insert 3.Delete 4.Search 5.Display 6.Modify 7.Sort 8.Statistics 9.Quit\n");
scanf("%d",&i);
if(i==1){
int id;
printf("Enter the id: ");
scanf("%d",&id);
char name[30];
printf("Enter the name: ");
scanf("%s",name);
char cla[10];
printf("Enter the class: ");
scanf("%s",cla);
float scores[N];
printf("Enter the score for Chinese: ");
scanf("%f",&scores[0]);
printf("Enter the score for Mathematics: ");
scanf("%f",&scores[1]);
printf("Enter the score for English: ");
scanf("%f",&scores[2]);
add(id,name,cla,scores);
}
else if(i==2){
Student *n=(Student *)malloc(sizeof(Student));
printf("Enter the id: ");
scanf("%d",&(n->id));
printf("Enter the name: ");
scanf("%s",n->name);
printf("Enter the class: ");
scanf("%s",n->cla);
printf("Enter the score for Chinese: ");
scanf("%f",&(n->scores[0]));
printf("Enter the score for Mathematics: ");
scanf("%f",&(n->scores[1]));
printf("Enter the score for English: ");
scanf("%f",&(n->scores[2]));
n->next=0;
int index;
printf("Enter the index: ");
scanf("%d",&index);
s=insert(n,index);
}
else if(i==3){
int id;
printf("Enter the id: ");
scanf("%d",&id);
s=del(id);
}
else if(i==4){
int id;
printf("Enter the id: ");
scanf("%d",&id);
search(id);
}
else if(i==5){
display();
}
else if(i==6){
int c;
printf("Enter the ID of the record you want to change: ");
scanf("%d",&c);
modify(c);
}
else if(i==7){
sort();
}
else if(i==8){
statistics();
}
else if(i==9){
Student *p;
while(s!=0){
p=s->next;
free(s);
s=p;
}
break;
}
}while(1);
return 0;
}
覺得需要的話自己修改就可以了。
J. 1;學生成績管理系統.
工作量太大了
有點報酬可能還會有人幫
而且你也沒說明白用什麼語言來寫