廣工Anyview試題答案_第1頁
廣工Anyview試題答案_第2頁
廣工Anyview試題答案_第3頁
已閱讀5頁,還剩4頁未讀 繼續(xù)免費(fèi)閱讀

下載本文檔

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

文檔簡介

1、/*【習(xí)題 9.023 】結(jié)構(gòu)體類型定義如下:struct dateint year; int month; int day; /定義日期結(jié)構(gòu)體類型struct student char name20;struct date birth; /出生日期;結(jié)構(gòu)體數(shù)組 s 存儲了 n 個人的名字和出生日期。寫一函數(shù),求這 n 個人中年齡最大 (即出生日期最小)者的姓名。*/char *oldest(student s, int n)int j,k=0;for(j=1;jsj.birth.year) k=j;else if(sk.birth.year=sj.birth.year) if(sk.birt

2、h.monthsj.birth.month) k=j;else if(sk.birth.month=sj.birth.month) if(sk.birth.daysj.birth.day) k=j;return ;/*【習(xí)題 9.025 】結(jié)構(gòu)體類型定義如下:struct dateint year; int month; int day; /定義日期結(jié)構(gòu)體類型struct student char id10; /學(xué)號char name20; /姓名struct date birth; /出生日期;結(jié)構(gòu)體數(shù)組 s 存儲了 n 個人的學(xué)號、名字和出生日期。寫一函數(shù),以結(jié)構(gòu)體的形式 返

3、回這 n 個人中年齡最大(即出生日期最小)者的信息。*/struct student oldest(struct student s, int n)int j,k=0;for(j=1;jsj.birth.year) k=j;else if(sk.birth.year=sj.birth.year)if(sk.birth.monthsj.birth.month) k=j;else if(sk.birth.month=sj.birth.month)if(sk.birth.daysj.birth.day) k=j;return sk;/*【習(xí)題 9.027 】結(jié)構(gòu)體類型定義如下:學(xué)號 姓名 各門課成績

4、struct student char id10; / char name10; / int score5; /;結(jié)構(gòu)體數(shù)組 s 存儲了 n 個學(xué)生的學(xué)號、名字和各門課成績。編寫 函數(shù),返回這 n 個人中第 i 門課成績最高者的學(xué)號。*/ char *best(struct student s, int n, int i) int t=s0.scorei,k;for(int j=0;jn;j ) if(tsj.scorei) t=sj.scorei;k=j; return sk.id;/*學(xué)號姓名 各門課成績【習(xí)題 9.029 】結(jié)構(gòu)體類型定義如下: struct student char i

5、d10; / char name10; / int score5; /;結(jié)構(gòu)體數(shù)組 s 存儲了 n 個學(xué)生的學(xué)號、名字及其 5 門課成績。編寫 函數(shù),返回這 n 個人中 5 門課成績總分最高者的學(xué)號。*/char *best(struct student s, int n) int sum=0,k,t=0; for(int i=0;in;i )for(int j=0;jt)t=sum;sum=0;k=i; else sum=0;return sk.id;日期結(jié)構(gòu)體類型 鏈表結(jié)點(diǎn)的結(jié)構(gòu)體類型人名 出生日期*/習(xí)題 9.033 】日期和鏈表結(jié)點(diǎn)的結(jié)構(gòu)體類型定義如下: struct dateint

6、year; int month; int day; / struct studentNode / char name10; / struct date birth; / struct studentNode *next;結(jié)構(gòu)體鏈表 L 存儲了 n 個人的名字和出生日期。寫一函數(shù),求這 n 個人中 年齡最大(即出生日期最小)者的名字。char *oldest(struct studentNode *L)/* 若 L 是空表,則返回空指針 null 否則返回表中年齡最大者的名字*/struct studentNode *p;if(L=NULL) return NULL;for(p=L-next;p

7、!=NULL;p=p-next)if(*p).birth.year(*L).birth.year) continue;if(*p).birth.year=(*L).birth.year)if(*p).birth.month(*L).birth.month) continue;if(*p).birth.month=(*L).birth.month&(*p).birth.day=(*L).birth.day) continue;L=p;return(*L).name);*習(xí)題 9.053 】結(jié)構(gòu)體類型定義如下:struct person int id; /員工號char name10; /姓名in

8、t age;/年齡char sex;/性別;結(jié)構(gòu)體數(shù)組 personneln 存儲了 n 位員工的信息 寫一函數(shù),返回年齡在 a 及以上的員工數(shù)。*/int count(struct person personnel, int n, int a)int t=0;for(int i=0;i=a)t ; return t;*習(xí)題 9.055 】結(jié)構(gòu)體類型定義如下:struct person int id; /員工號char name10; /姓名int age;/年齡char sex;/性別;結(jié)構(gòu)體數(shù)組 personneln 存儲了 n 位員工的信息。 寫一函數(shù),返回年齡在a及以上的x性別的員工數(shù)

9、。 */int count(struct person personnel, int n, int a, char x) int t=0;for(int i=0;i=a&personneli.sex=x)t ; return t;*習(xí)題 9.063 】結(jié)構(gòu)體類型定義如下: struct course int cID; / char name10; / float credit; / int semester; /課程號,取值 099 課程名 學(xué)分,取值 05 學(xué)期,取值 18;結(jié)構(gòu)體數(shù)組c存儲了 n門課程的信息。寫一函數(shù),求學(xué)期 s的總學(xué)分*/float creditSum(struct co

10、urse c, int n, int s) float sum=0; for(int i=0;inext;p!=NULL;p=p-next) if(*p).semester=s) sum =(*p).credit;if(s=1)sum =(*Lc).credit;return sum;/*【習(xí)題 9.133 】日期和結(jié)構(gòu)體類型定義如下:struct dateint year; int month; int day; /日期結(jié)構(gòu)體類型struct student / 結(jié)構(gòu)體類型 char name10; /人名struct date birth; /出生日期;結(jié)構(gòu)體數(shù)組 s 存儲了 n 個人的名

11、字和出生日期。寫一函數(shù),由數(shù)組 s 中 n 個人 的信息及其順序構(gòu)造相應(yīng)的鏈表。鏈表的結(jié)點(diǎn)的結(jié)構(gòu)體類型定義如下:struct studentNode /結(jié)構(gòu)體類型 char name10; /人名struct date birth; /出生日期struct studentNode *next;*/struct studentNode *CreateLinkList(struct student s, int n)struct studentNode *head,*p1,*p2;int i=0;p1=p2=(struct studentNode *) malloc(sizeof(struct s

12、tudentNode); head=NULL;while(iname,); p1-birth=si.birth;if(i=0) head=p1;else p2-next=p1;p2=p1;p1=(struct studentNode *) malloc(sizeof(struct studentNode); i;p2-next=NULL; return (head);習(xí)題 9.173 】課程鏈表結(jié)點(diǎn)的結(jié)構(gòu)體類型定義如下:struct courseNode / int cID; /char name10; / float credit; /課程鏈表結(jié)點(diǎn)的結(jié)構(gòu)體類型 課程號,取值 0

13、99 課程名學(xué)分,取值 05int semester; / 學(xué)期,取值 18 struct courseNode *next;結(jié)構(gòu)體鏈表 Lc 存儲了多門課程的信息。寫一函數(shù),將課程號為 c 的 課程的學(xué)分修改為 t 。*/ struct courseNode *creditChange(struct courseNode *Lc, int c, float t) /* 若課程 c 不存在,則修改不成功,返回 null;否則修改該課程的學(xué)分為 t ,返回指向該課程結(jié)點(diǎn)的指針。*/struct courseNode *p;for(p=Lc-next;p!=NULL;p=p-next)if(*p)

14、.cID=c)(*p).credit=t; return p;if(*Lc).cID=c)(*Lc).credit=t;return Lc;return NULL;習(xí)題 9.183 】課程鏈表結(jié)點(diǎn)的結(jié)構(gòu)體類型定義如下:struct courseNode / int cID; /char name10; /float credit; / int semester; / struct courseNode *next;課程鏈表結(jié)點(diǎn)的結(jié)構(gòu)體類型 課程號,取值 099 課程名學(xué)分,取值 05學(xué)期,取值 18;結(jié)構(gòu)體鏈表 Lc 存儲了多門課程的信息。寫一函數(shù),將課程號為 c 的 課程結(jié)點(diǎn)刪除。*/str

15、uct courseNode *deleteCourse(struct courseNode *Lc, int c)/* 若在鏈表 Lc 中課程 c 不存在,則刪除不成功,返回 null; 否則從鏈表 Lc 中刪除該課程結(jié)點(diǎn),并返回指向該課程結(jié)點(diǎn)的指針 */struct courseNode *p,*q,*t; p=*Lc;while(c!=p-cID&p-next!=NULL)q=p;p=p-next;if(c=p-cID) if(p=*Lc) t=p;*Lc=p-next;elset=p;q-next=p-next;return(t);/*【習(xí)題 9.302 】單向鏈表的結(jié)點(diǎn)類型定義如下:

16、struct nodechar ch;struct node *next;編寫函數(shù),對單向鏈表 L 實現(xiàn)就地逆置,即將所有結(jié)點(diǎn) 的指針反向,原鏈頭當(dāng)作鏈尾,原鏈尾當(dāng)作鏈頭,并返 回逆置后鏈表的頭指針。*/struct node *inverse(struct node *L)struct node *p=L,*q;int n=0,i=0; char t;while(p!=NULL)p=p-next;n;p=L;for(;inext;if(p-ch)ch) t=p-ch,p-ch=q-ch,q-ch=t; if(q-next!=NULL)p=p-next; else p=NULL;p=L;return L;/*【習(xí)題 9.352 】單向鏈表的結(jié)點(diǎn)類型定義如下:struct nodechar ch;struct node *next;編寫函數(shù),對單向鏈表 L 實現(xiàn)排序,即按結(jié)點(diǎn)的 ch 值, 從小到大重構(gòu)鏈表L,并

溫馨提示

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

評論

0/150

提交評論