资源预览内容
第1页 / 共3页
第2页 / 共3页
第3页 / 共3页
亲,该文档总共3页全部预览完了,如果喜欢就下载吧!
资源描述
第7章 习题解答7.1判断题对的有1,2,5,8,97.2单选题ADBCB7.3填空题1. struct union2. 1 4 6 83. px-p-b x.p-a4. union d x=9;7.4程序结果1. Wang ping:98.52. 10,152:43. 13 54. 1: break2: while3: switch5. BEI JING!7.5编程题 1. #include struct date int day,month,year;int month_days=0,31,28,31,30,31,30,31,31,30,31,30,31;void main() struct date d1; int days=0; coutd1.yeard1.monthd1.day; for(int i=1;i2&(d1.year%4=0&d1.year%100!=0|d1.year%400=0)days+; coutYear=d1.year Month=d1.month Day= d1.day No=days+d1.dayendl; 2. #include #include struct book char name10; int quantity; double unit_price;struct book books10=Pascal,40,22.5,C+,50,30.0,FoxPro,25,26.8;void main() cout显示各种书名等信息:n; cout书名t数量t单价n; for(int i=0;i3;i+)coutbooksi.nametbooksi.quantitytbooksi.unit_priceendl; coutbook1; for(i=0;i3;i+)if(strcmp(book1,booksi.name)=0) cout该书数量为: booksi.quantity; coutendlendl; coutbook1number; for(i=0;i3;i+)if(strcmp(book1,booksi.name)=0) cout应付金额为: booksi.unit_price*number; coutendlendl; int n=3; coutbooksn-1.namebooksn-1.quantitybooksn-1.unit_price; coutendl; cout书名t数量t单价n; for(i=0;in;i+)coutbooksi.nametbooksi.quantitytbooksi.unit_priceendl; coutendl; 3. #include union un unsigned short part2; unsigned long w;void parts(unsigned long n,unsigned short &l,unsigned short &h) union un u; u.w=n; l=u.part0; h=u.part1;void main() unsigned long x; unsigned short a,b; coutx; parts(x,a,b); couthex; cout髙位=0xb,低位=0xaendl; 7.6 回答问题1. 答:结构成员是异址的,而联合成员是同址的。2. 答:结构成员是不同类型的,而数组元素是相同类型的。3. 答:可以。4. 答:结构的成员可以是联合变量,而联合的成员也可以是结构变量。5. 答:给结构变量初始化可用初始值表给其所有成员初始化,而给联合变量初始化仅能用初始值表给其首成员初始化。3
收藏 下载该资源
网站客服QQ:2055934822
金锄头文库版权所有
经营许可证:蜀ICP备13022795号 | 川公网安备 51140202000112号