版權說明:本文檔由用戶提供并上傳,收益歸屬內(nèi)容提供方,若內(nèi)容存在侵權,請進行舉報或認領
文檔簡介
Chapter16AnswerstoSelectedExercisesAnswerstoSelectedExercises2.[was#2;modified](a)struct{doublereal,imaginary;}c1,c2,c3;(b)struct{doublereal,imaginary;}c1={0.0,1.0},c2={1.0,0.0},c3;(c)Onlyonestatementisnecessary:c1=c2;(d)c3.real=c1.real+c2.real;c3.imaginary=c1.imaginary+c2.imaginary;4.[was#4;modified](a)typedefstruct{doublereal,imaginary;}Complex;(b)Complexc1,c2,c3;(c)Complexmake_complex(doublereal,doubleimaginary){Complexc;c.real=real;c.imaginary=imaginary;returnc;}(d)Complexadd_complex(Complexc1,Complexc2){Complexc3;c3.real=c1.real+c2.real;c3.imaginary=c1.imaginary+c2.imaginary;returnc3;}11.[was#10;modified]Theamemberwilloccupy8bytes,theunionewilltake8bytes(thelargestmember,c,is8byteslong),andthearrayfwillrequire4bytes,sothetotalspaceallocatedforswillbe20bytes.14.[was#12;modified](a)doublearea(structshapes){if(s.shape_kind==RECTANGLE)returns.u.rectangle.height*s.u.rectangle.width;elsereturn3.14159*s.u.circle.radius*s.u.circle.radius;}(b)structshapemove(structshapes,intx,inty){structshapenew_shape=s;new_shape.center.x+=x;new_shape.center.y+=y;returnnew_shape;}(c)structshapescale(structshapes,doublec){structshapenew_shape=s;if(new_shape.shape_kind==RECTANGLE){new_shape.u.rectangle.height*=c;new_shape.u.rectangle.width*=c;}elsenew_shape.u.circle.radius*=c;returnnew_shape;}15.[was#14]enumweek_days{MON,TUE,WED,THU,FRI,SAT,SUN};typedefenum{MON,TUE,WED,THU,FRI,SAT,SUN}Week_days;17.[was#16]Allthestatementsarelegal,sinceCallowsintegersandenumerationvaluestobemixedwithoutrestriction.Only(a),(d),and(e)aresafe.(b)isnotmeaningfulifihasavalueotherthan0or1.(c)willnotyieldameaningfulresultifbhasthevalue1.1.[was#6;1.[was#6;modified]#include<stdio.h>#defineCOUNTRY_COUNT\((int)(sizeof(country_codes)/sizeof(country_codes[0])))structdialing_code{char*country;intcode;};conststructdialing_code{{"Argentina",country_codes[]=54},{"Bangladesh",880},{"Brazil",55},{"Burma(Myanmar)",95},{"China",86},{"Colombia",57},{"Congo,Dem.Rep.of",243},{"Egypt",20},{"Ethiopia",251},{"France",33},{"Germany",49},{"India",91},{"Indonesia",62},{"Iran",98},{"Italy",39},{"Japan",81},{"Mexico",52},{"Nigeria",234},{"Pakistan",92},{"Philippines",63},{"Poland",48},{"Russia",7},{"SouthAfrica",27},{"SouthKorea",82},{"Spain",34},{"Sudan",249},{"Thailand",66},{"Turkey",90},{"Ukraine",380},{"UnitedKingdom",44},{"UnitedStates",1},{"Vietnam",84}};intmain(void){intcode,i;printf("Enterdialingcode:");scanf("%d",&code);for(i=0;i<COUNTRY_COUNT;i++)if(code==country_codes[i].code){printf("Thecountrywithdialingcode%dis%s\n",code,country_codes[i].country);return0;}printf("Nocorrespondingcountryfound\n");return0;}3.[was#8]#include<stdio.h>#include"readline.h"#defineNAME_LEN25#defineMAX_PARTS100structpart{intnumber;charname[NAME_LEN+1];inton_hand;};intfind_part(intnumber,conststructpartinv[],intvoidinsert(structpartinv[],int*np);voidsearch(conststructpartinv[],intvoidupdate(structpartinv[],intnp);voidprint(conststructpartinv[],intnp);/**********************************************************main:Promptstheusertoenteranoperationcode, *thencallsafunctiontoperformtherequested *action.Repeatsuntiltheuserentersthe *command'q'.Printsanerrormessageiftheuser*entersanillegalcode. ***********************************************************/intmain(void){charcode;structpartinventory[MAX_PARTS];intnum_parts=0;for(;;){printf("Enteroperationcode:");scanf("%c",&code);while(getchar()!='\n') /*skipstoendofline*/;switch(code){case'i':insert(inventory,break;case's':search(inventory,num_parts);break;case'u':update(inventory,num_parts);break;case'p':print(inventory,num_parts);break;case'q':return0;default: printf("Illegalcode\n");}printf("\n");}}/**********************************************************find_part:Looksupapartnumberintheinvarray. *Returnsthearrayindexifthepartnumber *isfound;otherwise,returns-1. ***********************************************************/intfind_part(intnumber,conststructpartinv[],intnp){inti;for(i=0;i<np;i++)if(inv[i].number==number)returni;return-1;}/***********************************************************insert:Promptstheuserforinformationaboutanew**partandtheninsertsthepartintotheinv**array.Printsanerrormessageandreturns**prematurelyifthepartalreadyexistsorthe**arrayisfull.***********************************************************/voidinsert(structpartinv[],int*np){intpart_number;if(*np==MAX_PARTS){printf("Databaseisfull;can'taddmoreparts.\n");return;}printf("Enterpartnumber:");scanf("%d",&part_number);if(find_part(part_number,inv,*np)>=0){printf("Partalreadyexists.\n");return;}inv[*np].number=part_number;printf("Enterpartname:");read_line(inv[*np].name,NAME_LEN);printf("Enterquantityonhand:scanf("%d",&inv[*np].on_hand);(*np)++;}/***********************************************************search:Promptstheusertoenterapartnumber,then**looksupthepartintheinvarray.Ifthe**partexists,printsthenameandquantityon**hand;ifnot,printsanerrormessage.***********************************************************/voidsearch(conststructpartinv[],intnp){inti,number;printf("Enterpartnumber:");scanf("%d",&number);i=find_part(number,inv,np);if(i>=0){printf("Partname:%s\n",inv[i].name);printf("Quantityonhand:%d\n",inv[i].on_hand);}elseprintf("Partnotfound.\n");}/**********************************************************update:Promptstheusertoenterapartnumber. *Printsanerrormessageifthepartcan'tbe *foundintheinvarray;otherwise,promptsthe*usertoenterchangeinquantityonhandand *updatesthearray. ***********************************************************/voidupdate(structpartinv[],intnp){inti,number,change;printf("Enterpartnumber:scan
溫馨提示
- 1. 本站所有資源如無特殊說明,都需要本地電腦安裝OFFICE2007和PDF閱讀器。圖紙軟件為CAD,CAXA,PROE,UG,SolidWorks等.壓縮文件請下載最新的WinRAR軟件解壓。
- 2. 本站的文檔不包含任何第三方提供的附件圖紙等,如果需要附件,請聯(lián)系上傳者。文件的所有權益歸上傳用戶所有。
- 3. 本站RAR壓縮包中若帶圖紙,網(wǎng)頁內(nèi)容里面會有圖紙預覽,若沒有圖紙預覽就沒有圖紙。
- 4. 未經(jīng)權益所有人同意不得將文件中的內(nèi)容挪作商業(yè)或盈利用途。
- 5. 人人文庫網(wǎng)僅提供信息存儲空間,僅對用戶上傳內(nèi)容的表現(xiàn)方式做保護處理,對用戶上傳分享的文檔內(nèi)容本身不做任何修改或編輯,并不能對任何下載內(nèi)容負責。
- 6. 下載文件中如有侵權或不適當內(nèi)容,請與我們聯(lián)系,我們立即糾正。
- 7. 本站不保證下載資源的準確性、安全性和完整性, 同時也不承擔用戶因使用這些下載資源對自己和他人造成任何形式的傷害或損失。
最新文檔
- 2025江西撫州金控基金管理有限公司職業(yè)經(jīng)理人招聘2人(公共基礎知識)綜合能力測試題附答案
- 2025年樺甸市總工會公開招聘工會社會工作者(6人)備考題庫附答案
- 2025廣東東莞理工學院第二批招聘聘用人員19人考試模擬卷附答案
- 2025年哈爾濱道里區(qū)安靜社區(qū)衛(wèi)生服務中心招聘1人(公共基礎知識)測試題附答案
- 2026新疆生產(chǎn)建設兵團第十師一八八團連隊(社區(qū))跟班“兩委”后備力量招聘6人筆試備考試題及答案解析
- 2026山東重工集團有限公司社會招聘筆試備考題庫及答案解析
- 職場簡約商務風年終述職報告【演示文檔課件】
- 2026德欽縣公開(特招)治安聯(lián)防人員(7人)筆試備考題庫及答案解析
- 2026內(nèi)蒙古鄂爾多斯職業(yè)學院汽車工程系招聘筆試模擬試題及答案解析
- 上海煙草集團有限責任公司2026年應屆生招聘筆試模擬試題及答案解析
- 無人機吊運培訓課件
- 沈陽市行道樹栽植現(xiàn)狀分析與發(fā)展對策
- 2026年中國馬術行業(yè)發(fā)展現(xiàn)狀調(diào)查、競爭格局分析及未來前景預測報告
- 電力市場基礎知識面試題及高頻考點
- 健康體檢重要異常結果管理專家共識2025
- 2026屆四川省成都市樹德實驗中學物理九上期末調(diào)研試題含解析
- TCNAS50-2025成人吞咽障礙患者口服給藥護理學習解讀課件
- 工程概算編制方案
- 2026年全球美容與個人護理趨勢預測報告-英敏特-202510
- 2025至2030全球及中國供應鏈的區(qū)塊鏈行業(yè)項目調(diào)研及市場前景預測評估報告
- 2025內(nèi)蒙古通遼市扎魯特旗巨日合鎮(zhèn)人民政府招聘護林員9人考試參考試題及答案解析
評論
0/150
提交評論