試驗(yàn)九試驗(yàn)報(bào)告_卓越14_彭佳偉_第1頁(yè)
試驗(yàn)九試驗(yàn)報(bào)告_卓越14_彭佳偉_第2頁(yè)
試驗(yàn)九試驗(yàn)報(bào)告_卓越14_彭佳偉_第3頁(yè)
試驗(yàn)九試驗(yàn)報(bào)告_卓越14_彭佳偉_第4頁(yè)
試驗(yàn)九試驗(yàn)報(bào)告_卓越14_彭佳偉_第5頁(yè)
已閱讀5頁(yè),還剩9頁(yè)未讀, 繼續(xù)免費(fèi)閱讀

下載本文檔

版權(quán)說(shuō)明:本文檔由用戶(hù)提供并上傳,收益歸屬內(nèi)容提供方,若內(nèi)容存在侵權(quán),請(qǐng)進(jìn)行舉報(bào)或認(rèn)領(lǐng)

文檔簡(jiǎn)介

1、C語(yǔ)言程序設(shè)計(jì)實(shí)驗(yàn)報(bào)告班級(jí)卓越工程師班成績(jī)指導(dǎo)教師 李開(kāi)學(xué)號(hào) U201414716同組人姓名專(zhuān)業(yè)計(jì)算機(jī)科學(xué)與技術(shù)日期2014年1月13日第九次實(shí)驗(yàn)結(jié)構(gòu)與聯(lián)合實(shí)驗(yàn)學(xué)生姓名 彭佳偉實(shí)驗(yàn)組別實(shí)驗(yàn)名稱(chēng)結(jié)構(gòu)與聯(lián)合實(shí)驗(yàn)一、實(shí)驗(yàn)?zāi)康模?)熟悉和掌握結(jié)構(gòu)的說(shuō)明和引用、結(jié)構(gòu)的指針、結(jié)構(gòu)數(shù)組,以及函數(shù)中使用結(jié)構(gòu)的方 法。(2)掌握動(dòng)態(tài)存儲(chǔ)分配函數(shù)的用法,掌握自引用結(jié)構(gòu)和單向鏈表的創(chuàng)建、遍歷、結(jié)點(diǎn)的 增刪、查找等操作。(3)了解字段結(jié)構(gòu)和聯(lián)合的用法。二、實(shí)驗(yàn)任務(wù)1表達(dá)式求值的程序驗(yàn)證設(shè)有說(shuō)明:char u = "UVWXYZ"char v = "xyz"struct Tint

2、兀char c;char *t;a = 11, 'A', u, 100, 'B', v, *p = a;請(qǐng)先自己計(jì)算表2.1中表達(dá)式的值,然后編寫(xiě)程序并運(yùn)行來(lái)加以驗(yàn)證。(各表達(dá)式相互無(wú)關(guān))表2.1表達(dá)式值的計(jì)算序號(hào)表達(dá)式計(jì)算值驗(yàn)證值1(+p) -> x2p+, p -> c3* p+ -> t, * p -> t4* (+p) -> t5* +p -> t6+ * p -> t2源程序修改、替換下面所給源程序的功能是: 給定一批整數(shù),以0作為結(jié)束標(biāo)志且不作為結(jié)點(diǎn), 將其建成一個(gè) 先進(jìn)先出的鏈表。先進(jìn)先出鏈表的頭指針始終指

3、向最先創(chuàng)建的結(jié)點(diǎn)(鏈頭),先建結(jié)點(diǎn)指向后建結(jié)點(diǎn),后建結(jié)點(diǎn)始終是尾結(jié)點(diǎn)。請(qǐng)完成以下工作:(1)源程序中存在什么樣的錯(cuò)誤(先觀(guān)察執(zhí)行結(jié)果)?對(duì)程序進(jìn)行修改、調(diào)試。使之能 夠正確完成指定任務(wù)。(2)修改替換creat_list函數(shù),將其建成一個(gè)后進(jìn)先出的鏈表。后進(jìn)先出的鏈表的頭指針始終指向最后創(chuàng)建的結(jié)點(diǎn)(鏈頭),后建結(jié)點(diǎn)指向先建結(jié)點(diǎn),先建結(jié)點(diǎn)始終是尾結(jié)點(diǎn)。 源程序#in clude<stdio.h>#include<stdlib.h>struct s_list int data;struct s_list *next;void creat_list(struct s_list

4、 *headp, int *p);int main(void)struct s_list *head = NULL, *p;int s = 1, 2, 3, 4, 5, 6, 7, 8, 0; creat_list(head, s); p = head;while(p)printf("%dt", p -> data);p = p -> next;printf("n");return 0;void creat_list(struct s_list *headp, int *p)struct s_list *loc_head = NULL, *t

5、ail;if(p0 = 0)Jelseloc_head = (struct s_list *)malloc(sizeof(struct s_list);loc_head -> data = *p+;tail = loc_head;while(*p)tail -> next = (struct s_list *)malloc(sizeof(struct s_list);tail = tail -> next;tail -> data = *p+;tail -> next = NULL;headp = loc_head;3.程序設(shè)計(jì) 編寫(xiě)并上機(jī)調(diào)試運(yùn)行能實(shí)現(xiàn)以下功能的

6、程序或函數(shù):(1) 編寫(xiě)一個(gè)程序,實(shí)現(xiàn)以下功能:定義一個(gè)字段結(jié)構(gòu)struct bits ,它將一個(gè) 8 位無(wú)符號(hào)字節(jié)從最低位向最高位聲明為8個(gè)字段,各字段依次為bitO, bitl,bit7,且bitO的優(yōu)先級(jí)最高。同時(shí)設(shè)計(jì)8個(gè)函數(shù),第i個(gè)函數(shù)以biti (i = 0, 1,7)為參數(shù),并且在函數(shù)體內(nèi)輸出 biti的值。將8個(gè)函數(shù)的名字存入一個(gè)函數(shù)指針數(shù)組p_fun。如果bit0為1,調(diào)用p_funO指向的函數(shù)。如果 struct bits中有多位為1,則根據(jù)優(yōu)先級(jí)從高到低依次調(diào)用函數(shù)指針數(shù)組 p_fun中相應(yīng)元素指向的函數(shù)。8個(gè)函數(shù)中的第0個(gè)函數(shù)可以設(shè)計(jì)為Void f0(struct bit

7、s b)Printf( fhe function %d is called!'n ”,b);(3)設(shè)計(jì)用單詞鏈表建立一張班級(jí)成績(jī)單,包括每個(gè)學(xué)生的學(xué)號(hào)、姓名、英語(yǔ)、高等數(shù)學(xué)、普通物理、C語(yǔ)言程序設(shè)計(jì)四門(mén)課程的成績(jī),試用函數(shù)編程實(shí)現(xiàn)下列功能: 輸入每個(gè)學(xué)生的各項(xiàng)信息。 輸出每個(gè)學(xué)生的各項(xiàng)信息。 修改指定學(xué)生的指定數(shù)據(jù)項(xiàng)的內(nèi)容。 統(tǒng)計(jì)每個(gè)同學(xué)的平均成績(jī)(保留兩位小數(shù))。 輸出各位同學(xué)的學(xué)號(hào)、姓名、四門(mén)課程的總成績(jī)和平均成績(jī)。4選做題(1) 對(duì)上述程序設(shè)計(jì)題中第(2)題的程序,增加按照平均成績(jī)進(jìn)行升序排序的函數(shù),試寫(xiě) 出用交換結(jié)點(diǎn)數(shù)據(jù)域的方法升序排序的函數(shù),排序可用選擇法或冒泡法。(2)對(duì)選

8、做題第(1)題,進(jìn)一步寫(xiě)出用交換結(jié)點(diǎn)指針域的方法升序排序的函數(shù)。(3) 采用雙向鏈表重做編程設(shè)計(jì)題中的第(2)題。三、實(shí)驗(yàn)步驟及結(jié)果1、序號(hào)表達(dá)式計(jì)算值驗(yàn)證值1(+p) -> x1001002p+, p -> c'B''B'3* p+ -> t, * p -> t X' X'4* (+p) -> t X' X'5* +p -> t V' V'6+ * p -> t V' V'2、(1)錯(cuò)誤:create_list函數(shù)中傳入的是一級(jí)指針,應(yīng)該傳入二級(jí)指針。修改

9、后代碼:#in clude<stdio.h>#in clude<stdlib.h> struct s_listint data;struct s_list *n ext;;void creat_list(struct s_list *headp, int *p);int mai n(void)struct s_list *head = NULL, *p;int s = 1,2, 3, 4, 5, 6, 7, 8, 0;creat_list(&head, s);p = head;while(p)printf("%dt", p -> dat

10、a);p = p -> n ext;prin tf("n ”);return 0;void creat_list(struct s_list *headp, int *p)struct s_list *loc_head = NULL, *tail;if(pO = 0)5elseloc_head = (struct s_list *)malloc(sizeof(struct s_list);loc_head -> data = *p+;tail = loc_head;while(*p)tail -> next = (struct s_list *)malloc(siz

11、eof(struct s_list);tail = tail -> n ext;tail -> data = *p+;tail -> next = NULL;*headp = loc_head;運(yùn)行結(jié)果:12345678Program ended with exit code: 0(2 )源代碼:#in clude<stdio.h>#in clude<stdlib.h> struct s_listint data;struct s_list *n ext;;void creat_list(struct s_list *headp, int *p);in

12、t main( void)struct s_list *head = NULL, *p;int s = 1,2, 3, 4, 5, 6, 7, 8, 0;creat_list(&head, s);p = head;while(p)printf("%dt", p -> data);p = p -> n ext;prin tf("n ”);return 0;void creat_list(struct s_list *headp, int *p)struct s_list *loc_head = NULL, *temp = NULL;if(pO =

13、 0)elsewhile(*p)loc_head = (struct s_list*)malloc(sizeof(struct s_list);loc_head -> data = *p+;loc_head -> n ext = temp;temp = loc_head;*headp = loc_head;運(yùn)行結(jié)果:07654321Program Ended with exit cade: 03、( 1)源代碼:#include <stdio.h> struct bitsunsigned char bit0 : 1;unsigned char bit1 : 1;unsi

14、gned char bit2 : 1;unsigned char bit3 : 1;unsigned char bit4 : 1;unsigned char bit5 : 1;unsigned char bit6 : 1;unsigned char bit7 : 1;union wstruct bits a;unsigned char t;m;void f0(unsigned char bit)printf("the function %d is called!n", bit);void f1(unsigned char bit)printf("the funct

15、ion %d is called!n", bit);void f2(unsigned char bit)printf("the function %d is called!n", bit);void f3(unsigned char bit)printf("the function %d is called!n", bit);void f4(unsigned char bit)printf("the function %d is called!n", bit); void f5(unsigned char bit)print

16、f("the function %d is called!n", bit);void f6(unsigned char bit)printf("the function %d is called!n", bit);void f7(unsigned char bit)printf("the function %d is called!n", bit);int main(int argc, char const *argv)unsigned int n;void (*p_fun8)(unsigned char b);printf(&quo

17、t;input n: ");scanf("%d", &n);m.t = n;p_fun0 = f0;p_fun1 = f1;p_fun2 = f2;p_fun3 = f3;p_fun4 = f4;p_fun5 = f5;p_fun6 = f6;p_fun7 = f7;if(m.a.bit0)p_fun0(m.a.bit0);if(m.a.bit1)p_fun1(m.a.bit1);if(m.a.bit2)p_fun2(m.a.bit2);if(m.a.bit3)p_fun3(m.a.bit3);if(m.a.bit4)p_fun4(m.a.bit4);if

18、(m.a.bit5)p_fun5(m.a.bit5);if(m.a.bit6)p_fun 6(m.a.bit6);if(m.a.bit7)P_fun 7(m.a.bit7);return 0;運(yùn)行結(jié)果: int main(void)input n: 255 the function the function the "furKtion the function the function the function the function the function Prog1 is called!1 is called!1 is called!1 is called!1 is call

19、ed!1 is called!1 is called!1 is called!ram ended with exit code: 03. ( 2)源代碼:#i nclude <stdio.h>#i nclude <stdlib.h>#in clude <stri ng.h>#in clude <ctype.h>typedef struct Stude nt Stude nt;struct Stude ntint nu mber;char n ame10;float en glish;float math;float physics;float c

20、;float average;float sum;Stude nt *n ext;void In put(Stude nt *head);void Output(Stude nt *head);void Cha ngel nfo(Stude nt *head);void Sort(Stude nt *head);Student *head = NULL;int n;int flag = 1;while (flag = 1)printf("Please input the number of options :n"); printf("1 : Input Infor

21、mationt 2 : Change Informationn"); printf("3 : Output Informationt 4 : Sort Informationn"); printf("5 : Quitn");scanf(" %d", &n);switch (n)case 1:Input(&head);break;case 2:ChangeInfo(head);break;case 3:Output(head);break;case 4:Sort(head);break;case 5:flag

22、= 0;break;default:printf("Illegal Input! Please input again."); break;printf("nn");return 0;void Input(Student *head)/ 采用的是后進(jìn)先出的單向鏈表 char answer = 'y'while (answer = 'y')Student *current = NULL;current = (Student*)malloc(sizeof(Student);current->next = *head;*h

23、ead = current; printf("nPlease input the student's number : "); scanf(" %d", &current->number);printf("Please input the student's name : "); scanf(" %s", current->name);printf("Please input the score of english: "); scanf(" %f&

24、quot;, &current->english);printf("Please input the score of math : "); scanf(" %f", &current->math);printf("Please input the score of physics : "); scanf(" %f", &current->physics);printf("Please input the score of c : "); scanf(&

25、quot; %f", &current->c);current->sum = current->english + current->math + current->physics + current->c;current->average = current->sum / 4; printf("Do you want to input the infomation of another student? (Y/N) "); scanf(" %c", &answer);answer

26、 = tolower(answer);void Output(Student *head)if (head = NULL)printf("You have not input any information!");elseprintf("nnttThe Infomation Of Studentsn");doprintf("name:%stt", head->name); printf("number:%dtt", head->number); printf("english:%.2ft&qu

27、ot;, head->english); printf("math:%.2ft", head->math); printf("physics:%.2fnn", head->physics); printf("c:%.2ft", head->c);printf("sum:%.2f", head->sum);printf("average:%.2f", head->average);head = head->next; while (head != NULL

28、);void ChangeInfo(Student *head)if (head = NULL)printf("You have not input any information!");elseStudent *current = head;char name10;int flag = 0;int n;printf("Please input the student's name : "); scanf("%s", name);while (current->next != NULL)if (strcmp(name,

29、current->name) != 0)current = current->next;elseflag = 1;printf("Please input the number of options :n");printf("1 : englisht2 : matht 3 : physicst 4 : ct 5 : namet 6 : numbern");scanf("%d", &n);switch (n)case 1: printf("Please input the score of english

30、: "); scanf(" %f", &current->english); break;case 2: printf("Please input the score of math : "); scanf(" %f", &current->math); break;case 3:printf("Please input the score of physics : "); scanf(" %f", &current->physics);bre

31、ak;case 4: printf("Please input the score of c : "); scanf(" %f", &current->c); break;case 5: printf("Please input the student's name : "); scanf(" %s", current->name); break;case 6:printf("Please input the student's number : "); sc

32、anf(" %d", &current->number);default: break;if (n <= 3)+ current->math +current->sum = current->english current->physics + current->c;current->average = current->sum / 4;break;void Sort(Student *head)/ 采用的是冒泡排序/ 交換的是數(shù)據(jù)域,不是指針if (head = NULL)printf("You ha

33、ve not input any information!");elseStudent temp;while (head->next != NULL)Student *current = head; while (current->next != NULL)if (current->average < current->next->average)temp = *current;temp.next = current->next->next; current->next->next = current->next; *

34、current = *current->next;*current->next = temp;current = current->next;head = head->next;運(yùn)行結(jié)果:Please input the number of options :1 : Input Information2 : Change Information3 : Output Information4 : Sort Information5 : Quit1Please input the student's number : 124Please input the stud

35、ent's name : pjwPlease input the score of english: 54Please input the score of math : 75Please input the score of physics :65Please input the score of c : 45Do you want to input the infomation of another student? (Y/N)yPlease input the student's number :7896Please input the student's nam

36、e :tsrPlease input the score of english:64Please input the score of math :23Please input the score of physics :75Please input the score of c : 34Do you want to input the infomation of another student? (Y/N)yPlease input the student's number : 0706Please input the student's name :lgyPlease in

37、put the score of english: 79Please input the score of math :64Please input the score of physics : 76Please input the score of c : 34Do you want to input the infomation of another student? (Y/N)nPlease input the number of options :1 : Input Information2 : Change Information3 : Output Information4 : Sort Information5 : Quit4Please input the number of options :1 : Input Information2 : Change Information3 : Output Information4 : Sort Information5 : Quit3math:64.00 physics:76.00number:124 english:54.00The

溫馨提示

  • 1. 本站所有資源如無(wú)特殊說(shuō)明,都需要本地電腦安裝OFFICE2007和PDF閱讀器。圖紙軟件為CAD,CAXA,PROE,UG,SolidWorks等.壓縮文件請(qǐng)下載最新的WinRAR軟件解壓。
  • 2. 本站的文檔不包含任何第三方提供的附件圖紙等,如果需要附件,請(qǐng)聯(lián)系上傳者。文件的所有權(quán)益歸上傳用戶(hù)所有。
  • 3. 本站RAR壓縮包中若帶圖紙,網(wǎng)頁(yè)內(nèi)容里面會(huì)有圖紙預(yù)覽,若沒(méi)有圖紙預(yù)覽就沒(méi)有圖紙。
  • 4. 未經(jīng)權(quán)益所有人同意不得將文件中的內(nèi)容挪作商業(yè)或盈利用途。
  • 5. 人人文庫(kù)網(wǎng)僅提供信息存儲(chǔ)空間,僅對(duì)用戶(hù)上傳內(nèi)容的表現(xiàn)方式做保護(hù)處理,對(duì)用戶(hù)上傳分享的文檔內(nèi)容本身不做任何修改或編輯,并不能對(duì)任何下載內(nèi)容負(fù)責(zé)。
  • 6. 下載文件中如有侵權(quán)或不適當(dāng)內(nèi)容,請(qǐng)與我們聯(lián)系,我們立即糾正。
  • 7. 本站不保證下載資源的準(zhǔn)確性、安全性和完整性, 同時(shí)也不承擔(dān)用戶(hù)因使用這些下載資源對(duì)自己和他人造成任何形式的傷害或損失。

最新文檔

評(píng)論

0/150

提交評(píng)論