




版權(quán)說明:本文檔由用戶提供并上傳,收益歸屬內(nèi)容提供方,若內(nèi)容存在侵權(quán),請(qǐng)進(jìn)行舉報(bào)或認(rèn)領(lǐng)
文檔簡介
1、C語言程序設(shè)計(jì)實(shí)驗(yàn)報(bào)告指導(dǎo)教師: 同組人姓名:專業(yè):班級(jí):日期:成績:實(shí)驗(yàn)組別:第 次實(shí)驗(yàn):學(xué)生姓名:學(xué)號(hào):實(shí)驗(yàn)名稱:指針實(shí)驗(yàn)一、實(shí)驗(yàn)?zāi)康?1) 熟練掌握指針的說明、賦值、使用。(2) 掌握用指針引用數(shù)組的元素,熟悉指向數(shù)組的指針的使用。(3) 熟練掌握字符數(shù)組與字符串的使用,掌握指針數(shù)組及字符指針數(shù)組的用法。(4) 掌握帶有參數(shù)的 main函數(shù)的用法。二、實(shí)驗(yàn)內(nèi)容及要求1源程序改錯(cuò)下面的源程序中是否存在錯(cuò)誤?如果存在,原因是什么?如果存在錯(cuò)誤要求在計(jì)算機(jī)上對(duì) 這個(gè)源程序進(jìn)行調(diào)試修改,是之能夠正確執(zhí)行。源程序:#i nclude int main( void)float * p;scan f(
2、%f,p);prin tf(%fn,*p);return 0;2源程序修改替換(1) 下面源程序的功能是,通過函數(shù)指針和菜單選擇來調(diào)用字符串拷貝函數(shù)或字符串連接 函數(shù)。請(qǐng)?jiān)诔绦蛑械南聞澗€處填寫合適的表達(dá)式、語句或代碼片段來完善該程序。源程序:#i nclude #in clude int main( void)char a80,b80,c160,*result=c; int choice,i;doprin tf(tt1 copy stri ng.n ”);prin tf(tt2 connect stri ng.n ”);prin tf(tt3 exit.n);printf(ttinput a
3、number(1-3)please! n”); scan f(%d, &choice);while(choice5);switch (choice)case 1:p=strcpy; break;case 2:p=strcat;break;case 3:goto dow n;getchar();prin tf(i nput the first stri ng please! n);i=0;printf(input the second string please!n); i=0;result=(a,b);prin tf(the result is %sn ”,result);dow n:5ret
4、urn 0;(2) 請(qǐng)上機(jī)運(yùn)行第(1)題程序使之能按下面要求輸出結(jié)果(注:(輸入)表示該行數(shù)據(jù)是鍵盤數(shù)據(jù)):1. copy string。2. Connect string。3. Exit。In put a nu mber ( 1-3) please!2 (輸入)In put the first stri ng please!The more you lear n,(輸入)In put the sec ond stri ng please !The more you get.(輸入)The result is the more you lear n,the more you get.3.跟蹤調(diào)
5、試程序請(qǐng)按下面的要求對(duì)所給源程序進(jìn)行操作,并回答問題和排除錯(cuò)誤。(1 )單步執(zhí)行源程序。進(jìn)入strcpy時(shí),watches窗口中s為何值?返回 main時(shí),watches窗口中s為何值?(2)排除源程序中的錯(cuò)誤,使程序輸出結(jié)果為:there is a boat on the lake.源程序:#i nclude char * strcpy(char*,char*);int main( void)char a20,b60=there is a boat on the lack.;prin tf(%sn,strcpy(a,b);return 0;char *strcpy(char*s,char*t
6、)while(*s+=*t+)5return (s);4程序設(shè)計(jì)編寫并上機(jī)調(diào)試運(yùn)行能實(shí)現(xiàn)以下功能的程序或函數(shù):(1) 已知一個(gè)長整形變量占四個(gè)字符,其中每個(gè)字節(jié)又分高四位和低四位。試編寫一個(gè)程 序,從該長整形變量的高字節(jié)開始,依次取出每個(gè)字節(jié)的高四位和低四位并以數(shù)字字符的形 式進(jìn)行顯示。(2) 利用大小為n的指針數(shù)組指向用 gets函數(shù)輸入的n行,每行不超過 80個(gè)字符。試編 寫一個(gè)函數(shù),它將每一行中連續(xù)的多個(gè)空格字符壓縮為一個(gè)空格字符。在調(diào)用函數(shù)中輸出壓 縮空格后的各行,空行不予輸出。(3) 編寫一個(gè)程序,輸入n個(gè)整數(shù),排序后輸出。排序的原則由命令行可選參數(shù)-d決定,并且有參數(shù)-d時(shí)按遞減順
7、序,否則按遞增順序排序。要求將排序算法定義成函數(shù),利用指向函數(shù)的指針是該函數(shù)實(shí)現(xiàn)遞增或遞減排序。(4) 設(shè)每個(gè)班有n個(gè)學(xué)生,每個(gè)學(xué)生所修的 M門課程的成績,并且都存放到相應(yīng)的數(shù)組中, 試編寫以下函數(shù): 計(jì)算每個(gè)學(xué)生各門課程平均成績 計(jì)算全班每門課程的平均成績 分別統(tǒng)計(jì)低于全班各門課程平均成績的人數(shù) 分別統(tǒng)計(jì)全班各門課程不及格的人數(shù)和90分以上(包含90)的人數(shù)。在調(diào)用函數(shù)中輸出結(jié)果(要求都用指針操作,不得用下標(biāo))5選做題(1) 編寫并上機(jī)調(diào)試運(yùn)行能實(shí)現(xiàn)以下功能的程序:設(shè)有N位整數(shù)和M位小數(shù)(N=20, M=10 )的兩個(gè)數(shù)據(jù)a, b。編程計(jì)算a+b并輸出結(jié)果。 如:12345678912345
8、678912.1234567891+98765432109876543210.0123456789(2) 編寫一個(gè)使用復(fù)雜聲明的char * ( *p2)(const char*,const char *); ”的程序。 提示:p中元素可為 strcmp,strstr等函數(shù)名。三、實(shí)驗(yàn)步驟及結(jié)果1源程序改錯(cuò)錯(cuò)誤:懸掛指針,指針未初始化 改后程序:#in cludeint main( void)float *p,a;p=&a;scan f(%f,p);prin tf(%fn,*p);return 0;2源程序完善、修改、替換#in clude #in clude int main( void)c
9、har *(*p)(char *a,char *b);char a80,b80,c160,*result=c;int choice,i;doprin tf(tt1 copy stri ng.n ”);prin tf(tt2 connect stri ng.n ”);prin tf(tt3 exit.n);prin tf(tt in put a number(1-3)please!n); scan f(%d, &choice); while(choice5);switch(choice)case 1:p=strcpy;break;case 2:p=strcat;break;case 3:goto
10、 dow n;getchar();prin tf(i nput the first stri ng please!n);i=0;while(ai=getchar()!=n)i+;ai=0:printf(input the second string please!n); i=0;while(bi=getchar()!=n)i+- bi=0: result=(*p)(a,b); prin tf(the result is %sn,result);dow n:return 0;g *C: Docuents and Sett ingsibMIy DociULent e學(xué)樓.c作業(yè)Ic實(shí)鯊 1 指針實(shí)
11、鯊 12. 1 copy string.2 connect string.3 exit.input a numberplease*input the first string please*the more you learn,input the second string please *the more you get-the result is the more you learn,the more you get.Process returned 0 execution time : 37.250 s Press any key to continue.3.跟蹤調(diào)試程序VetchesE
12、 Local vari aElfesNo locals.B Fiinct i on Arfument ss = 0x2ff2c峨Ei峨” =0x22fefO thare is 直 bot on th lack. ,V&tcKeslxE Local var i aElesNb locals.B Fuiict i on Arfumentss = 0x22 f49 “t = 0x22ffDd g#i nclude char * strcpy(char*,char*);int main( void)char a20,b60=there is a boat on the lack.; prin tf(%
13、sn,strcpy(a,b);return 0;char *strcpy(char*s,char*t)char *m;m=s;while(*s+=*t+)5return (m);4程序設(shè)計(jì)(1)#in clude#in clude#defi ne MAX 32int mai n()long int n;int i;char sMAX;prin tf(please in put a nu mber:n);scan f(%ld, &n);if(n =-2147483647&n=0)for(i=0; n!=0;i+)si=n%2+0;n/=2;for(;i=MAX-1;i+)si=O:elsen=_
14、(n+1);for(i=0; n!=0;i+)si=n%2+0;n/=2;for(;i=MAX-2;i+)si=O;for(i=0;i=28;i-)putchar(si);putchar(t);for(i=27;i=24;i-)putchar(si);putchar(t);for(i=23;i=20;i-)putchar(si);putchar(t);for(i=19;i=16;i-)putchar(si); putchar(t);for(i=15;i=12;i-) putchar(si); putchar(t);for(i=11;i=8;i-) putchar(si); putchar(t)
15、;for(i=7;i=4;i-) putchar(si); putchar(t);for(i=3;i=0;i-) putchar(si); putchar(t);return 0;(2)#in clude#in clude #in clude #defi ne N 3 void output(char*s); int main( void)int i;char *sN;prin tf(please in put your massage: n); for(i=0;iN;i+)si=malloc(80); gets(si);prin tf(your massage has bee n cha n
16、ged in to;n); for(i=0;iN;i+)output(si); prin tf(%sn,si); return 0;void output(char*s)int i,j;for(i=0,j=0;si!=0;i+,j+)if(isspace(si)for(;isspace(si);i+) sj+=; sj=si; else sj=si; sj=si;口Ld(3)oinowyo LIP what#in clude#defi ne MAX 5void swap(i nt v,i nt i,i nt j);void qsort(i nt v,i nt left,i nt right);
17、int main (i nt argc,char *argv)int i=0,sMAX;if(-argc0&(*+argv)0=_)if(*argv)1=d)while(i=0;i-)prin tf(%dt,si);elseprin tf(wr on g:n);elsewhile(ient s and Sett ings.ibaly DociULent e學(xué)樓作業(yè)Ic實(shí)鯊l指針實(shí)鯊4 please input youi* massage: whatQ execution time : 46.234 s cont inue.for(i=0;iright)return;swap(v,left,(l
18、eft+right)/2); last=left;for(i=left+1;i=right;i+) if(vivleft) swap(v,+last,i);swap(v,left,last); qsort(v,left,last-1); qsort(v,last+1,right);void swap(i nt v,i nt i,i nt j)int temp;temp=vi; vi=vj;vj=temp;(4)#i nclude #defi ne N 5#defi ne M 3struct coursechar *s;int dN; smM;void saverage(struct cours
19、e *sm);void caverage(struct course *sm);void summary_below(struct course *sm);void summary_both(struct course *sm);int main( void)int i;prin tf(Please in put the n ames of the %d courses.n,M);for(i=0;is=malloc(10)=NULL)prin tf(ERROR);for(i=0;is);for(k=0;kd+k);saverage(sm);caverage(sm);summary_below(
20、sm);summary_both(sm);return 0;void saverage(struct course *sm)double sum=0,av;int i,k;for(i=0;iN;i+)printf(This is the %d students average gradet,i+1); for(k=0;kd+i);av=sum/M;prin tf(%lfn,av);sum=0;void caverage(struct course *sm)double sum=0,av;int i,k;for(i=0;is);for(k=0;kd+k);av=sum/N;prin tf(%lf
21、n,av);sum=0;void summary_below(struct course *sm)double sum=0,av;int i,k;for(i=0;iM;i+)for(k=0;kd+k);av=sum/N;prin tf(I n %s the nu mber of below-average stude nt ist,(sm+i)-s); for(sum=0,k=0;kd+k)av)sum+;prin tf(%dn,(i nt)sum);sum=0;void summary_both(struct course *sm)int i,k;int fsum=0,esum=0;for(
22、i=0;iM;i+)prin tf(The course is %st,(*(sm+i).s);for(k=0;kd+k)d+k)90)esum+;prin tf(the failed is %d,while the above 90 is %dn,fsum,esum); fsum=0,esum=0;names of the 3 courses.Please input thegradesof Ej studentsofthe87 78 92 58 68Please input thegradesof Ej studentsofthe56 62 58 73 94Please input the
23、gradesof Ej studentsofthemath subjectphysics subjectc_languagePlease input the oath phys ic s c_languagesubject77 68 92 57 90ThisThisThisThisThisThisThisThisis is is is is is is isthe the the the the the the the1 studentJ s2 studentf s3 student1s4 studentf s5 student1saverage average average average
24、 averagegrade grade grade grade grade73.33333369.33333380.66666762.66666784.00000076.60000068.60000076.8000002average grade of mathaverage grade of physics average grade of c_language number of below-auerage student isIn math theIn physics the number of below-auerage student is In c_languageThe co l
25、ipse isThe course is The co Ltrse isthe number of math the phys ics the c_languageis above above3290 is 190 is 1below-auepage student failed is 1,while the failed is 2,while thethe failed is 1,while the above 90 is 1Process returned 0 execution time : 86.563 s Press any key to continue.s *C: Docuent s an
溫馨提示
- 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ì)自己和他人造成任何形式的傷害或損失。
最新文檔
- 2024秋八年級(jí)英語上冊(cè) Unit 4 My Neighbourhood Lesson 20 No Stopping教學(xué)設(shè)計(jì) (新版)冀教版
- 三年級(jí)語文下冊(cè) 第三單元 11 趙州橋第1課時(shí)教學(xué)設(shè)計(jì) 新人教版
- Module3 Unit2 Writing(教學(xué)設(shè)計(jì))-2024-2025學(xué)年外研版英語九年級(jí)上冊(cè)
- 2024-2025學(xué)年高中歷史 專題一 古代中國的政治制度 1.2《走向“大一統(tǒng)”的秦漢政治》教學(xué)設(shè)計(jì) 人民版必修1
- 2023六年級(jí)數(shù)學(xué)上冊(cè) 五 數(shù)據(jù)處理練習(xí)四配套教學(xué)設(shè)計(jì) 北師大版
- 九年級(jí)歷史下冊(cè) 第四單元 和平與發(fā)展 18 夢(mèng)想成真的時(shí)代教學(xué)設(shè)計(jì) 北師大版
- Module 12 Unit 2 Reading and vocabulary-教學(xué)設(shè)計(jì) 2023-2024學(xué)年外研版英語八年級(jí)上冊(cè)
- 14《刷子李》教學(xué)設(shè)計(jì)-2024-2025學(xué)年五年級(jí)下冊(cè)語文統(tǒng)編版
- 8《燈光》(教學(xué)設(shè)計(jì))-2024-2025學(xué)年統(tǒng)編版語文六年級(jí)上冊(cè)
- Unit 3 My Friends Lesson 1(教學(xué)設(shè)計(jì))-2024-2025學(xué)年人教新起點(diǎn)版英語二年級(jí)上冊(cè)
- 城區(qū)建筑垃圾處理資源再利用設(shè)備采購 投標(biāo)方案(技術(shù)方案)
- 2025年開封大學(xué)單招職業(yè)傾向性測試題庫含答案
- 全國川教版信息技術(shù)八年級(jí)下冊(cè)第二單元第2節(jié)《制作文創(chuàng)作品》教學(xué)設(shè)計(jì)設(shè)計(jì)
- DG-TG08-12-2024 普通中小學(xué)建設(shè)標(biāo)準(zhǔn)
- 建筑工程材料采購管理職責(zé)
- 實(shí)時(shí)數(shù)字孿生數(shù)據(jù)同步技術(shù)-深度研究
- Unit 4 History and traditions Project 說課稿 -2024-2025學(xué)年高中英語人教版(2019)必修第二冊(cè)
- 【道法】歷久彌新的思想理念課件 2024-2025學(xué)年統(tǒng)編版道德與法治七年級(jí)下冊(cè)
- 【培訓(xùn)課件】DOE培訓(xùn)
- 2025年高考數(shù)學(xué)備考立體幾何壓軸題(八省聯(lián)考新考向)
- 《淺談A企業(yè)消防安全管理中存在的問題及完善對(duì)策研究》6300字(論文)
評(píng)論
0/150
提交評(píng)論