




版權(quán)說明:本文檔由用戶提供并上傳,收益歸屬內(nèi)容提供方,若內(nèi)容存在侵權(quán),請(qǐng)進(jìn)行舉報(bào)或認(rèn)領(lǐng)
文檔簡(jiǎn)介
1、最新c語言實(shí)訓(xùn)報(bào)告C課程設(shè)計(jì)一、課程設(shè)計(jì)目的?C語言課程設(shè)計(jì)?是信息類專業(yè)的重要實(shí)踐性課程。目的在于學(xué)習(xí)完?C語言程序設(shè)計(jì)?課程后進(jìn)行的一次全面的綜合練習(xí)。通過課程設(shè)計(jì),一方面可以結(jié)合課程的教學(xué)內(nèi)容循序漸進(jìn)地進(jìn)行設(shè)計(jì)方面的實(shí)踐訓(xùn)練,另一方面,在參與一系列子工程的實(shí)踐過程中,還能提高如何綜合運(yùn)用所學(xué)知識(shí)解決實(shí)際問題的能力,以及獲得相關(guān)工程管理和團(tuán)隊(duì)合作等眾多方面的具體經(jīng)驗(yàn)。為后續(xù)課程:面向?qū)ο蟪绦蛟O(shè)計(jì)、Visual C+,數(shù)據(jù)結(jié)構(gòu),軟件工程,軟件技術(shù)根底等奠定必要的實(shí)踐根底。設(shè)計(jì)目的如下:1、進(jìn)一步培養(yǎng)學(xué)生結(jié)構(gòu)化程序設(shè)計(jì)的思想,加深對(duì)高級(jí)語言根本語言要素和控制結(jié)構(gòu)的理解。2、針對(duì)C語言中的重點(diǎn)和
2、難點(diǎn)內(nèi)容進(jìn)行訓(xùn)練,獨(dú)立完成有一定工作量的程序設(shè)計(jì)任務(wù),同時(shí)強(qiáng)調(diào)好的程序設(shè)計(jì)風(fēng)格。3、掌握C語言的編程技巧和上機(jī)調(diào)試程序的方法。4、掌握程序設(shè)計(jì)中的常用算法。二、課程設(shè)計(jì)題目及要求1、根底訓(xùn)練題目1.1根底寫出下面程序的輸出結(jié)果。1#include main( ) int x; x=-3+4*5-6;printf(“%dn,x); x=3+4%5-6; printf(“%dn,x); x=-3*4%4-6/5; printf(“%dn,x); x=(7+6)%5/2; printf(“%dn,x);2) # includemain() int x=5; int y=6; int z=7; pri
3、ntf( %dn %dn %dn %dn %dn %dn %dn,xy,yx,x!=y,x=z-2,x=x-2,x=z,x=z);3 ) #include main() int x=0,y=-1,z=1; printf(%d,%d,%d,%d,%d,%d,x&y,x|y,y&z,y|z,x&y,x|y);1.2順序結(jié)構(gòu)1三角形的底和高,求三角形的面積法一、 #include main()float a,b;scanf(a=%f,b=%f,&a,&b);printf(MJ=%.2f,(a*b)/2.0);法二、 #include main()float a,b,s;scanf(a=%f,b=%f
4、,&a,&b);s=a*b/2;printf(s=%.1f,s);2假設(shè)某銀行一年定期的存款年利率,輸入存款額,計(jì)算三年后本利之和并輸出。年利率rate,存款期n,存款本金capital,本利之和deposit。#include #include main() int n=3; double rate=0.02; double capital; double deposit; printf(Please ente capital:); scanf(%lf,&capital); deposit=capital*pow(1+rate,n); printf(deposit=%.2fn,deposit
5、);#define N 3 改4#define RATE 0.02 改0.01#include #include main() double capital; double deposit; printf(Please ente capital:); scanf(%lf,&capital); deposit=capital*pow(1+RATE,N); printf(deposit=%.2fn,deposit); 改 1.3選擇結(jié)構(gòu)1輸入四個(gè)整數(shù),要求按大小順序輸出# includemain()int a,b,c,d,t; printf(please input 四個(gè)整數(shù)n); scanf(%
6、d%d%d%dn,&a,&b,&c,&d); if(ab) t=a;a=b;b=t; if(ac) t=a;a=c;c=t; if(ad) t=a;a=d;d=t; if(bc) t=b;b=c;c=t; if(bd) t=b;b=d;d=t; if(cd) t=c;c=d;d=t; printf(%d %d %d %dn,a,b,c,d);# includemain()int a,b,c,d,t; printf(please input 四個(gè)整數(shù)n); scanf(%d%d%d%dn,&a,&b,&c,&d); if(ab) t=a;a=b;b=t; if(ac) t=a;a=c;c=t;
7、if(ad) t=a;a=d;d=t; if(bc) t=b;b=c;c=t; if(bd) t=b;b=d;d=t; if(cd) t=c;c=d;d=t; printf(%d %d %d %dn,a,b,c,d); getch();2編寫程序?qū)崿F(xiàn):輸入一個(gè)百分制成績(jī)。要求書出成績(jī)的等級(jí)A B C D E,90分以上為 A,8189分為 B,7079為 C,6069為 D,60分一下為 E。#include main() int x; printf(Please chengji:n); scanf(%d,&x); if(x=90) printf(An); else if(x=80) prin
8、tf(Bn); else if(x=70) printf(Cn); else if(x=60) printf(Dn); else printf(En); 3編寫程序?qū)崿F(xiàn):給出一個(gè)不多于5位的正整數(shù),要求: 1.求出它是幾位數(shù) 2.分別打印出每一位數(shù)3.按逆序打印出各位數(shù)字,例如原數(shù)為321,應(yīng)輸出123# includemain() int x,a,b,c,d,e; printf(please input 一個(gè)不超于五位的整數(shù)n); scanf(%dn,&x); if(x/10000=1) a=x/10000; b=(x-a*10000)/1000; c=(x-a*10000-b*1000)/
9、100; d=(x-a*10000-b*1000-c*100)/10; e=(x-a*10000-b*1000-c*100-d*10); printf(每一位數(shù)是t%dt%dt%dt%dt%dn,a,b,c,d,e); printf(逆序是t%d%d%d%d%dn,e,d,c,b,a); printf(該數(shù)是五位數(shù)n); else if(x/1000=1) a=x/1000; b=(x-a*1000)/100; c=(x-a*1000-b*100)/10; d=(x-a*1000-b*100-c*10); printf(每一位數(shù)是t%dt%dt%dt%dn,a,b,c,d); printf(逆
10、序是t%d%d%d%dn,d,c,b,a); printf(該數(shù)是四位數(shù)n); else if(x/100=1) a=x/100; b=(x-a*100)/10; c=(x-a*100-b*10); printf(每一位數(shù)是t%dt%dt%dn,a,b,c); printf(逆序是t%d%d%dn,c,b,a); printf(該數(shù)是三位數(shù)n); else if(x/10=1) a=x/10; b=(x-a*10); printf(每一位數(shù)是t%dt%dn,a,b); printf(逆序是t%d%dn,b,a); printf(該數(shù)是兩位數(shù)n); else printf(每一位數(shù)是t%dn,x
11、); printf(逆序是t%dn,x); printf(該數(shù)是一位數(shù)n); 1.4循環(huán)1xyz + yzz = 532,其中x、y、z都是數(shù)字09,編寫一個(gè)程序求出x、y、z分別代表什么數(shù)字。#include main()int x,y,z;for(x=0;x=9;x+) for(y=0;y=9;y+) for(z=0;z=9;z+) if(x*100+y*10+z*1+y*100+z*10+z*1=532) printf(x=%d,y=%d,z=%dn,x,y,z); 2編寫一個(gè)程序打印如下對(duì)稱圖形行數(shù)由鍵盤輸入19范圍的值,例如下面是輸入的數(shù)字4時(shí)的情形: 4444444 33333 2
12、22 1 222 33333 4444444#includemain() int i,j,k,n; scanf(%d,&n); for(i=n;i=1;i-) for(j=1;j=n-i;j+) printf( ); for(k=1;k=2*i-1;k+)printf(%d,i);printf(n); for (i=2;i=n;i+) for(j=1;j=n-i;j+) printf( ); for (k=1;k=2*i-1;k+) printf(%d,i); printf(n); 3學(xué)校有近千名學(xué)生,在操場(chǎng)上排隊(duì),5人一行余2人,7人一行余3人,3人一行余1人,編寫一個(gè)程序求該校的學(xué)生人數(shù)。
13、#includemain()int n;for(n=800;n=1000;n+)if(n%7=3&n%5=2&n%3=1)printf(n=%dn,n);4猴子吃桃問題,猴子第一天摘下假設(shè)干個(gè)桃子,當(dāng)即吃了一半,還不過癮,有多吃了一個(gè),第二天早上又將剩下的桃子吃掉一半,有多吃了一個(gè),以后每天早上都吃了前一天剩下的一半零一個(gè),到第10天早上想在吃時(shí),見只剩下一個(gè)桃子了。求第一天共摘了多少桃子。# includemain() int m,t,x; for(t=9,m=1;t0;t-) x=(m+1)*2; m=x; printf(共摘了:%dn,m);1.5數(shù)組1、輸入一個(gè)字符串,統(tǒng)計(jì)其中字母、數(shù)
14、字、空格和其他字符各多少個(gè)。#include main() char s30; int i,c1=0,c2=0,c3=0,c4=0; printf(please input a zi fu chuan: ); gets(s); i=0; while(si!=0) if(si=97) & (si=65) & (si=0 &si=9) c3+; else c4+; i+; printf(其他字符=%dn字母=%dn空格=%dn數(shù)字=%dn,c4,c1,c2,c3);2輸出楊輝三角形。# includemain() int i,j,a77; for(i=0;i7;i+) aii=1; ai0=1;
15、for(i=2;i7;i+) for(j=1;ji;j+) aij=ai-1j-1+ai-1j; for(i=0;i7;i+) for(j=0;j=i;j+) printf(%dt,aij); printf(n);3將一個(gè)數(shù)插入到一個(gè)有序的數(shù)列中,要求插入后仍有序。# includemain() int a6,i,b; printf(please input 五位由小到大的數(shù)列:n); for(i=0;ib) 5=a0;a0=b;b=a5; if(a1b) a5=a1;a1=b;b=a5; if(a2b) a5=a2;a2=b;b=a5; if(a3b) a5=a3;a3=b;b=a5; if
16、(a4b) a5=a4;a4=b;b=a5; for(i=0;i=5;i+) printf(%dt,ai); printf(n);4輸入一個(gè)4行4列的矩陣分別求出主對(duì)角元素之和以及上三角元素之和。# includemain()int a44,i,j,s,w; printf(please input 四行四列數(shù):n); for(i=0;i4;i+) for(j=0;j4;j+) scanf(%dn,&aij); for(i=0;i4;i+) for(j=0;j4;j+) printf(%dt,aij); printf(n); for(i=0,s=0;i4;i+) s=s+aii; printf(
17、主對(duì)角元素和:%dn,s); for(j=0,w=0;j4;j+) for(i=0;i=j;i+) w=w+aij; printf(上三角之和:%dn,w);2.1函數(shù)1一個(gè)數(shù)如果恰好等于它的所有因子之和,這個(gè)數(shù)就稱為“完數(shù),請(qǐng)編寫一個(gè)判別m是否為完數(shù)的函數(shù),并編寫主函數(shù),通過調(diào)用此函數(shù)統(tǒng)計(jì)自然數(shù)1100間完數(shù)的個(gè)數(shù)。 #includestdio.hmain() int i,m,sum=0; for(i=2;i100;i+) sum=0; for(m=1;mi;m+) if(i%m=0) sum=sum+m; if(sum=i) printf(%dn,i); getch(); return 0
18、;2編寫一個(gè)函數(shù),實(shí)現(xiàn)對(duì)n個(gè)整數(shù)進(jìn)行排序用起泡法,并編寫主函數(shù)調(diào)用此函數(shù),實(shí)現(xiàn)對(duì)10個(gè)整數(shù)的排序。#includemain() int a10;int i,j,k;printf(in put 10 number:n); for(i=0;i=9;i+) scanf(%d,&ai); for(i=0;i=9;i+) if(aiai+1) k=ai+1; for(i=0;i=i+1;j-) if(ajaj-1) k=aj; aj=aj-1; aj-1=k; for(i=0;i=9;i+) printf( %d,ai);printf(n); 3根據(jù)以下公式求的近似值,直到最后一項(xiàng)的絕對(duì)值小于10-5為
19、止# include# includemain() double h,w,s,m;int n,i; for(n=1;n318;n+) if(1.0/(n*n)0.00001) printf(%dn,n); for(i=1,s=0;i=n;i+) m=1.0/(i*i); s=s+m; w=s*6; h=sqrt(w); printf(h=%lfn,h); 2.2指針1寫一個(gè)函數(shù),求字符串的長(zhǎng)度。在main函數(shù)中輸入字符串,并輸出其長(zhǎng)度。#include main() char s100,*p=s;printf(字符串: );gets(s);while(*+p);printf(長(zhǎng)度%dn,p-s
20、);2編程判斷輸入的一個(gè)字符串是否是回文。所謂回文,即順讀和倒讀都是一樣的。如eye,level,abba等。 #includeVoid column(char *str,int n)int fun(char str) int n,k,f; for(n=0;strn!=0;n+); for(k=0;kn/2;k+) if(strk!=strn-k-1) f=0; break; return f;main() char s80; printf(n please enter string: n); gets(s); if(fun(s)=1) printf(%s is not hui wenn,s)
21、; else printf(%s is hui wenn,s); getch();3用指針優(yōu)化學(xué)生成績(jī)1 定義一個(gè)數(shù)組stu10存放10個(gè)學(xué)生的成績(jī),從鍵盤輸入數(shù)據(jù),要求用指針實(shí)現(xiàn);2將數(shù)組stu10的內(nèi)容輸出到屏幕上,要求用指針實(shí)現(xiàn);3將成績(jī)數(shù)組按照從高到低進(jìn)行排序,要求用指針實(shí)現(xiàn);4將第三步內(nèi)容放在函數(shù)中實(shí)現(xiàn),在主函數(shù)中調(diào)用實(shí)現(xiàn)排序,用指針實(shí)現(xiàn),輸出排序后的成績(jī)單 #includestdio.h#includestring.hvoid cube(int *p) int i,j,t; for(i=0;i9;i+) for(j=0;j9-i;j+) if(*(p+j)*(p+j+1) t=*(
22、p+j); *(p+j)=*(p+j+1); *(p+j+1)=t; int main(void) int stu10,i,*p; printf(Input ten studentsscore:n); for(p=stu,i=0;i10;i+,p+) scanf(%d,p); printf(Output the scores;n); for(p=stu,i=0;i10;i+,p+) printf(%3d,*p); printf(n); cube(stu); printf(Out the scores after sort:n); for(p=stu,i=0;i10;i+,p+) printf(
23、%3d,*p);2.3結(jié)構(gòu)體1有10個(gè)學(xué)生,每個(gè)學(xué)生的數(shù)據(jù)包括學(xué)號(hào),姓名,及三門課成績(jī),總成績(jī)和平均成績(jī),從鍵盤輸入10個(gè)學(xué)生的數(shù)據(jù)包括學(xué)號(hào),姓名及3門課成績(jī),要求打印出每位學(xué)生的學(xué)號(hào),姓名,三門課的成績(jī),總成績(jī)和平均成績(jī),最后再打印出3門課的總平均成績(jī)以及最高分的學(xué)生的數(shù)據(jù)包括姓名和總成績(jī)。實(shí)驗(yàn)要求:1根據(jù)學(xué)生信息定義一個(gè)結(jié)構(gòu)體類型,在說明一個(gè)該結(jié)構(gòu)體類型的數(shù)組;2用input函數(shù)從鍵盤上輸入10個(gè)學(xué)生的數(shù)據(jù);3用average函數(shù)求出每個(gè)學(xué)生總成績(jī)、平均成績(jī)和所有學(xué)生的總平均成績(jī);4用maximum函數(shù)找出最高分的學(xué)生的數(shù)據(jù);5在主函數(shù)中輸出每位學(xué)生的學(xué)號(hào)、姓名、三門課的成績(jī)、總成績(jī)和平均
24、成績(jī)以及總平均分和最高分學(xué)生的數(shù)據(jù)。 輸出形式如下: NO. name score1 score2 score3 total average 101 wang 80 79 81 240 80.00 102 li 91 90 89 270 90.00 Average=85.00 The highest score:li,score total:270# include struct studentlong num;char name20;int score1;int score2;int score3;int total;double average;stu10;main() struct st
25、udent stu10; int i,w,m,j; double h; printf(please input .score1.score2 and score3n); for(i=0;i10;i+) scanf(%d%s%d%d%dn,&stui.num,&,&stui.score1,&stui.score2,&stui.score3); printf(numtnametscore1tscore2tscore3ttotaltaveragen); for(i=0;i10;i+) stui.total=stui.score1+stui.score2+stui.s
26、core3; stui.average=stui.total/3; printf(%dt%st%dt%dt%dt%dt%.2lf,stui.num,,stui.score1,stui.score2,stui.score3,stui.total,stui.average); printf(n); for(i=0,w=0;i10;i+) w=w+stui.average; h=w/10; printf(average=%.2lfn,h); for(i=0;i10;i+)for(j=0;jstuj.total) m=stuj-1.total;stuj-1.total=stuj.to
27、tal;stuj.total=m; printf(%st%dn,,stu9.total);2定義一個(gè)結(jié)構(gòu)體變量包括年、月、日。編寫一個(gè)函數(shù)days,計(jì)算該日期在本年中是第幾天(注意閏年問題)。由主函數(shù)將年月日傳遞給days函數(shù),計(jì)算之后,將結(jié)果傳回到主函數(shù)輸出。 #include struct date int year; int month; int day; ;main() struct date stu1; int a,b,c,m=0; printf(please enter a is year,b is month,c is day:n ); scanf(%d %d
28、%d,&stu1.year,&stu1.month,&stu1.day); a=stu1.year; b=stu1.month; c=stu1.day; if(a%400=0|a%4=0&a%100!=0) printf(the year is runn ); switch(b) case 1:m=c;break;case 2:m=31+c;break;case 3:m=31+29+c;break;case 4:m=31+29+31+c;break;case 5:m=31+29+31+30+c;break;case 6:m=31+29+31+30+31+c;break;case 7:m=31+
29、29+31+30+31+30+c;break;case 8:m=31+29+31+30+31+30+31+c;break;case 9:m=31+29+31+30+31+30+31+31+c;break;case 10:m=31+29+31+30+31+30+31+31+30+c;break;case 11:m=31+29+31+30+31+30+31+31+30+31+c;break;case 12:m=31+29+31+30+31+30+31+31+30+31+30+c;break; printf(%d %d %d is %dth of the yearn,stu1.year,stu1.m
30、onth,stu1.day,m); else printf(the year is pingn ); switch(b+12) case 13:m=c; break;case 14:m=31+c; break;case 15:m=31+28+c; break;case 16:m=31+28+31+c; break;case 17:m=31+28+31+30+c; break;case 18:m=31+28+31+30+31+c; break;case 19:m=31+28+31+30+31+30+c; break;case 20:m=31+28+31+30+31+30+31+c; break;
31、case 21:m=31+28+31+30+31+30+31+31+c; break;case 22:m=31+28+31+30+31+30+31+31+30+c; break;case 23:m=31+28+31+30+31+30+31+31+30+31+c; break;case 24:m=31+28+31+30+31+30+31+31+30+31+30+c; break; printf(%d %d %d is %dth of the yearn,stu1.year,stu1.month,stu1.day,m); getch(); 2、讀程序?qū)W生成績(jī)管理系統(tǒng)源代碼#include stdi
32、o.h /*標(biāo)準(zhǔn)輸入輸出函數(shù)庫*/#include stdlib.h /*標(biāo)準(zhǔn)函數(shù)庫*/#include string.h /*字符串函數(shù)庫*/#include conio.h /*屏幕操作函數(shù)庫*/#define HEADER1 -STUDENT- n#define HEADER2 | number | name |Comp|Math|Eng | sum | ave |mici | n#define HEADER3 |-|-|-|-|-|-|-|-| #define FORMAT | %-10s |%-15s|%4d|%4d|%4d| %4d | %.2f |%4d |n#define DA
33、TA p-data.num,,p-data.egrade,p-data.mgrade,p-data.cgrade,p-data.total,p-data.ave,p-data.mingci#define END - nint saveflag=0; /*是否需要存盤的標(biāo)志變量*/*定義與學(xué)生有關(guān)的數(shù)據(jù)結(jié)構(gòu)*/typedef struct student /*標(biāo)記為student*/char num10; /*學(xué)號(hào)*/char name15; /*姓名*/int cgrade; /*C語言成績(jī)*/int mgrade; /*數(shù)學(xué)成績(jī)*/int egrade; /*英語成績(jī)*
34、/int total; /*總分*/float ave; /*平均分*/int mingci; /*名次*/;/*定義每條記錄或結(jié)點(diǎn)的數(shù)據(jù)結(jié)構(gòu),標(biāo)記為:node*/typedef struct nodestruct student data; /*數(shù)據(jù)域*/struct node *next; /*指針域*/Node,*Link; /*Node為node類型的結(jié)構(gòu)變量,*Link為node類型的指針變量*/void menu() /*主菜單*/system(cls); /*調(diào)用DOS命令,清屏.與clrscr()功能相同*/textcolor(10); /*在文本模式中選擇新的字符顏色*/go
35、toxy(10,5); /*在文本窗口中設(shè)置光標(biāo)*/cprintf( The Students Grade Management System n);gotoxy(10,8);cprintf( *Menu*n);gotoxy(10,9);cprintf( * 1 input record 2 delete record *n);gotoxy(10,10);cprintf( * 3 search record 4 modify record *n);gotoxy(10,11);cprintf( * 5 insert record 6 count record *n);gotoxy(10,12);
36、cprintf( * 7 sort record 8 save record *n);gotoxy(10,13);cprintf( * 9 display record 0 quit system *n);gotoxy(10,14);cprintf( *n);/*cprintf()送格式化輸出至文本窗口屏幕中*/void printheader() /*格式化輸出表頭*/ printf(HEADER1); printf(HEADER2); printf(HEADER3);void printdata(Node *pp) /*格式化輸出表中數(shù)據(jù)*/ Node* p; p=pp; printf(F
37、ORMAT,DATA);void Wrong() /*輸出按鍵錯(cuò)誤信息*/printf(nnnnn*Error:input has wrong! press any key to continue*n);getchar();void Nofind() /*輸出未查找此學(xué)生的信息*/printf(n=Not find this student!n);void Disp(Link l) /*顯示單鏈表l中存儲(chǔ)的學(xué)生記錄,內(nèi)容為student結(jié)構(gòu)中定義的內(nèi)容*/Node *p;p=l-next; /*l存儲(chǔ)的是單鏈表中頭結(jié)點(diǎn)的指針,該頭結(jié)點(diǎn)沒有存儲(chǔ)學(xué)生信息,指針域指向的后繼結(jié)點(diǎn)才有學(xué)生信息*/if(
38、!p) /*p=NULL,NUll在stdlib中定義為0*/ printf(n=Not student record!n); getchar(); return;printf(nn);printheader(); /*輸出表格頭部*/while(p) /*逐條輸出鏈表中存儲(chǔ)的學(xué)生信息*/ printdata(p); p=p-next; /*移動(dòng)直下一個(gè)結(jié)點(diǎn)*/ printf(HEADER3);getchar();/*作用:用于定位鏈表中符合要求的節(jié)點(diǎn),并返回指向該節(jié)點(diǎn)的指針參數(shù):findmess保存要查找的具體內(nèi)容; nameornum保存按什么查找; 在單鏈表l中查找;*/Node* Lo
39、cate(Link l,char findmess,char nameornum)Node *r;if(strcmp(nameornum,num)=0) /*按學(xué)號(hào)查詢*/ r=l-next; while(r) if(strcmp(r-data.num,findmess)=0) /*假設(shè)找到findmess值的學(xué)號(hào)*/ return r; r=r-next; else if(strcmp(nameornum,name)=0) /*按姓名查詢*/ r=l-next; while(r) if(strcmp(,findmess)=0) /*假設(shè)找到findmess值的學(xué)生姓名*
40、/ return r; r=r-next; return 0; /*假設(shè)未找到,返回一個(gè)空指針*/*輸入字符串,并進(jìn)行長(zhǎng)度驗(yàn)證(長(zhǎng)度lens)printf(n exceed the required length! n); /*進(jìn)行長(zhǎng)度校驗(yàn),超過lens值重新輸入*/ while(strlen(n)lens); strcpy(t,n); /*將輸入的字符串拷貝到字符串t中*/*輸入分?jǐn)?shù),0分?jǐn)?shù)100 | t100 | tnext;system(cls);Disp(l); /*先打印出已有的學(xué)生信息*/while(r-next!=NULL) r=r-next; /*將指針移至于鏈表最末尾,準(zhǔn)備添
41、加記錄*/while(1) /*一次可輸入多條記錄,直至輸入學(xué)號(hào)為0的記錄結(jié)點(diǎn)添加操作*/ while(1) /*輸入學(xué)號(hào),保證該學(xué)號(hào)沒有被使用,假設(shè)輸入學(xué)號(hào)為0,那么退出添加記錄操作*/ stringinput(num,10,input number(press 0return menu):); /*格式化輸入學(xué)號(hào)并檢驗(yàn)*/ flag=0; if(strcmp(num,0)=0) /*輸入為0,那么退出添加操作,返回主界面*/ return; s=l-next; while(s) /*查詢?cè)搶W(xué)號(hào)是否已經(jīng)存在,假設(shè)存在那么要求重新輸入一個(gè)未被占用的學(xué)號(hào)*/ if(strcmp(s-data.n
42、um,num)=0) flag=1; break; s=s-next; if(flag=1) /*提示用戶是否重新輸入*/ getchar(); printf(=The number %s is not existing,try again?(y/n):,num); scanf(%c,&ch); if(ch=y|ch=Y) continue; else return; else break; p=(Node *)malloc(sizeof(Node); /*申請(qǐng)內(nèi)存空間*/ if(!p) printf(n allocate memory failure ); /*如沒有申請(qǐng)到,打印提示信息*/
43、 return ; /*返回主界面*/ strcpy(p-data.num,num); /*將字符串num拷貝到p-data.num中*/ stringinput(,15,Name:); p-data.cgrade=numberinput(C language Score0-100:); /*輸入并檢驗(yàn)分?jǐn)?shù),分?jǐn)?shù)必須在0100之間*/ p-data.mgrade=numberinput(Math Score0-100:); /*輸入并檢驗(yàn)分?jǐn)?shù),分?jǐn)?shù)必須在0100之間*/ p-data.egrade=numberinput(English Score0-100:); /*輸
44、入并檢驗(yàn)分?jǐn)?shù),分?jǐn)?shù)必須在0100之間*/ p-data.total=p-data.egrade+p-data.cgrade+p-data.mgrade; /*計(jì)算總分*/ p-data.ave=(float)(p-data.total/3); /*計(jì)算平均分*/ p-data.mingci=0; p-next=NULL; /*說明這是鏈表的尾部結(jié)點(diǎn)*/ r-next=p; /*將新建的結(jié)點(diǎn)參加鏈表尾部中*/ r=p; saveflag=1; return ;void Qur(Link l) /*按學(xué)號(hào)或姓名,查詢學(xué)生記錄*/int select; /*1:按學(xué)號(hào)查,2:按姓名查,其他:返回主界
45、面菜單*/char searchinput20; /*保存用戶輸入的查詢內(nèi)容*/Node *p;if(!l-next) /*假設(shè)鏈表為空*/ system(cls); printf(n=No student record!n); getchar(); return;system(cls);printf(n =1 Search by number =2 Search by namen);printf( please choice1,2:);scanf(%d,&select);if(select=1) /*按學(xué)號(hào)查詢*/ stringinput(searchinput,10,input the e
46、xisting student number:); p=Locate(l,searchinput,num);/*在l中查找學(xué)號(hào)為searchinput值的節(jié)點(diǎn),并返回節(jié)點(diǎn)的指針*/ if(p) /*假設(shè)p!=NULL*/ printheader(); printdata(p); printf(END); printf(press any key to return); getchar(); else Nofind(); getchar();else if(select=2) /*按姓名查詢*/ stringinput(searchinput,15,input the existing stud
47、ent name:); p=Locate(l,searchinput,name); if(p) printheader(); printdata(p); printf(END); printf(press any key to return); getchar(); else Nofind(); getchar();else Wrong(); getchar(); /*刪除學(xué)生記錄:先找到保存該學(xué)生記錄的節(jié)點(diǎn),然后刪除該節(jié)點(diǎn)*/void Del(Link l)int sel;Node *p,*r;char findmess20;if(!l-next) system(cls); printf(n
48、=No student record!n); getchar(); return;system(cls);Disp(l);printf(n =1 Delete by number =2 Delete by namen);printf( please choice1,2:);scanf(%d,&sel);if(sel=1) stringinput(findmess,10,input the existing student number:); p=Locate(l,findmess,num); if(p) /*p!=NULL*/ r=l; while(r-next!=p) r=r-next; r
49、-next=p-next;/*將p所指節(jié)點(diǎn)從鏈表中去除*/ free(p); /*釋放內(nèi)存空間*/ printf(n=delete success!n); getchar(); saveflag=1; else Nofind(); getchar();else if(sel=2) /*先按姓名查詢到該記錄所在的節(jié)點(diǎn)*/ stringinput(findmess,15,input the existing student name); p=Locate(l,findmess,name); if(p) r=l; while(r-next!=p) r=r-next; r-next=p-next; f
50、ree(p); printf(n=delete success!n); getchar(); saveflag=1; else Nofind(); getchar();else Wrong(); getchar();/*修改學(xué)生記錄。先按輸入的學(xué)號(hào)查詢到該記錄,然后提示用戶修改學(xué)號(hào)之外的值,學(xué)號(hào)不能修改*/void Modify(Link l)Node *p;char findmess20;if(!l-next) system(cls); printf(n=No student record!n); getchar(); return;system(cls);printf(modify stu
51、dent recorder);Disp(l);stringinput(findmess,10,input the existing student number:); /*輸入并檢驗(yàn)該學(xué)號(hào)*/p=Locate(l,findmess,num); /*查詢到該節(jié)點(diǎn)*/if(p) /*假設(shè)p!=NULL,說明已經(jīng)找到該節(jié)點(diǎn)*/ printf(Number:%s,n,p-data.num); printf(Name:%s,); stringinput(,15,input new name:); printf(C language score:%d,p-dat
52、a.cgrade); p-data.cgrade=numberinput(C language Score0-100:); printf(Math score:%d,p-data.mgrade); p-data.mgrade=numberinput(Math Score0-100:); printf(English score:%d,p-data.egrade); p-data.egrade=numberinput(English Score0-100:); p-data.total=p-data.egrade+p-data.cgrade+p-data.mgrade; p-data.ave=(
53、float)(p-data.total/3); p-data.mingci=0; printf(n=modify success!n); Disp(l); saveflag=1;else Nofind(); getchar();/*插入記錄:按學(xué)號(hào)查詢到要插入的節(jié)點(diǎn)的位置,然后在該學(xué)號(hào)之后插入一個(gè)新節(jié)點(diǎn)。*/void Insert(Link l) Link p,v,newinfo; /*p指向插入位置,newinfo指新插入記錄*/ char ch,num10,s10; /*s保存插入點(diǎn)位置之前的學(xué)號(hào),num保存輸入的新記錄的學(xué)號(hào)*/ int flag=0; v=l-next; system(
54、cls); Disp(l); while(1) stringinput(s,10,please input insert location after the Number:); flag=0;v=l-next; while(v) /*查詢?cè)搶W(xué)號(hào)是否存在,flag=1表示該學(xué)號(hào)存在*/ if(strcmp(v-data.num,s)=0) flag=1;break; v=v-next; if(flag=1) break; /*假設(shè)學(xué)號(hào)存在,那么進(jìn)行插入之前的新記錄的輸入操作*/ else getchar(); printf(n=The number %s is not existing,try
55、 again?(y/n):,s); scanf(%c,&ch); if(ch=y|ch=Y) continue; else return; /*以下新記錄的輸入操作與Add()相同*/ stringinput(num,10,input new student Number:); v=l-next; while(v) if(strcmp(v-data.num,num)=0) printf(=Sorry,the new number:%s is existing !n,num); printheader(); printdata(v); printf(n); getchar(); return;
56、v=v-next; newinfo=(Node *)malloc(sizeof(Node); if(!newinfo) printf(n allocate memory failure ); /*如沒有申請(qǐng)到,打印提示信息*/ return ; /*返回主界面*/ strcpy(newinfo-data.num,num); stringinput(,15,Name:); newinfo-data.cgrade=numberinput(C language Score0-100:); newinfo-data.mgrade=numberinput(Math Sc
57、ore0-100:); newinfo-data.egrade=numberinput(English Score0-100:); newinfo-data.total=newinfo-data.egrade+newinfo-data.cgrade+newinfo-data.mgrade; newinfo-data.ave=(float)(newinfo-data.total/3); newinfo-data.mingci=0; newinfo-next=NULL; saveflag=1; /*在main()有對(duì)該全局變量的判斷,假設(shè)為1,那么進(jìn)行存盤操作*/ /*將指針賦值給p,因?yàn)閘中的頭
58、節(jié)點(diǎn)的下一個(gè)節(jié)點(diǎn)才實(shí)際保存著學(xué)生的記錄*/ p=l-next; while(1) if(strcmp(p-data.num,s)=0) /*在鏈表中插入一個(gè)節(jié)點(diǎn)*/ newinfo-next=p-next; p-next=newinfo; break; p=p-next; Disp(l); printf(nn); getchar();/*統(tǒng)計(jì)該班的總分第一名和單科第一,和各科不及格人數(shù)*/void Tongji(Link l)Node *pm,*pe,*pc,*pt; /*用于指向分?jǐn)?shù)最高的節(jié)點(diǎn)*/Node *r=l-next;int countc=0,countm=0,counte=0; /
59、*保存三門成績(jī)中不及格的人數(shù)*/if(!r) system(cls); printf(n=Not student record!n); getchar(); return ;system(cls);Disp(l);pm=pe=pc=pt=r;while(r) if(r-data.cgradedata.mgradedata.egradedata.cgrade=pc-data.cgrade) pc=r; if(r-data.mgrade=pm-data.mgrade) pm=r; if(r-data.egrade=pe-data.egrade) pe=r; if(r-data.total=pt-d
60、ata.total) pt=r; r=r-next;printf(n-the TongJi result-n);printf(C Language60:%d (ren)n,countc);printf(Math 60:%d (ren)n,countm);printf(English ,pt-data.total);printf(The highest student by English score name:%s totoal score:%dn,,pe-data.egrade);printf(The highest student by Math
溫馨提示
- 1. 本站所有資源如無特殊說明,都需要本地電腦安裝OFFICE2007和PDF閱讀器。圖紙軟件為CAD,CAXA,PROE,UG,SolidWorks等.壓縮文件請(qǐng)下載最新的WinRAR軟件解壓。
- 2. 本站的文檔不包含任何第三方提供的附件圖紙等,如果需要附件,請(qǐng)聯(lián)系上傳者。文件的所有權(quán)益歸上傳用戶所有。
- 3. 本站RAR壓縮包中若帶圖紙,網(wǎng)頁內(nèi)容里面會(huì)有圖紙預(yù)覽,若沒有圖紙預(yù)覽就沒有圖紙。
- 4. 未經(jīng)權(quán)益所有人同意不得將文件中的內(nèi)容挪作商業(yè)或盈利用途。
- 5. 人人文庫網(wǎng)僅提供信息存儲(chǔ)空間,僅對(duì)用戶上傳內(nèi)容的表現(xiàn)方式做保護(hù)處理,對(duì)用戶上傳分享的文檔內(nèi)容本身不做任何修改或編輯,并不能對(duì)任何下載內(nèi)容負(fù)責(zé)。
- 6. 下載文件中如有侵權(quán)或不適當(dāng)內(nèi)容,請(qǐng)與我們聯(lián)系,我們立即糾正。
- 7. 本站不保證下載資源的準(zhǔn)確性、安全性和完整性, 同時(shí)也不承擔(dān)用戶因使用這些下載資源對(duì)自己和他人造成任何形式的傷害或損失。
最新文檔
- 產(chǎn)業(yè)園區(qū)入駐合同協(xié)議
- 關(guān)于推進(jìn)跨部門合作項(xiàng)目的工作計(jì)劃
- 關(guān)于采購流程的往來文書說明
- 商務(wù)會(huì)議溝通要點(diǎn)及會(huì)議紀(jì)要模板
- 健康管理平臺(tái)的構(gòu)建及運(yùn)營(yíng)規(guī)劃
- 機(jī)器人智能化生產(chǎn)線建設(shè)委托代理合同
- 交通物流調(diào)度管理系統(tǒng)建設(shè)方案
- 房屋預(yù)約買賣合同
- 木材原木購銷合同
- 2025年版《認(rèn)識(shí)大熊貓》課件發(fā)布
- 2025年安徽水利水電職業(yè)技術(shù)學(xué)院?jiǎn)握新殬I(yè)適應(yīng)性測(cè)試題庫(含答案)
- 山東省青島市市北區(qū)2024-2025學(xué)年七年級(jí)上學(xué)期期末考試英語試題(含答案+解析)
- 餐飲及食品安全管理制度
- 湖北省襄陽市襄州區(qū)2024-2025學(xué)年九年級(jí)上學(xué)期期末語文試題(含答案)
- 2025年安徽電氣工程職業(yè)技術(shù)學(xué)院?jiǎn)握新殬I(yè)技能測(cè)試題庫及答案1套
- 2025年房屋交易代持策劃協(xié)議書
- 課題申報(bào)參考:“四新”建設(shè)背景下教育創(chuàng)新與課程數(shù)字化實(shí)踐研究
- 2025年煙臺(tái)汽車工程職業(yè)學(xué)院高職單招職業(yè)適應(yīng)性測(cè)試近5年??及鎱⒖碱}庫含答案解析
- 2025年江蘇農(nóng)牧科技職業(yè)學(xué)院高職單招職業(yè)技能測(cè)試近5年常考版參考題庫含答案解析
- 2024年長(zhǎng)沙衛(wèi)生職業(yè)學(xué)院高職單招職業(yè)技能測(cè)驗(yàn)歷年參考題庫(頻考版)含答案解析
- 2024年度國(guó)網(wǎng)營(yíng)銷安全(用電檢查)安全準(zhǔn)入客觀題備考試題庫(附答案)
評(píng)論
0/150
提交評(píng)論