C++语言基础教程 教学课件 ppt 作者 吕凤翥习题答案 1_ 第7章

上传人:w****i 文档编号:94398225 上传时间:2019-08-06 格式:DOC 页数:3 大小:32KB
返回 下载 相关 举报
C++语言基础教程 教学课件 ppt 作者 吕凤翥习题答案 1_ 第7章_第1页
第1页 / 共3页
C++语言基础教程 教学课件 ppt 作者 吕凤翥习题答案 1_ 第7章_第2页
第2页 / 共3页
C++语言基础教程 教学课件 ppt 作者 吕凤翥习题答案 1_ 第7章_第3页
第3页 / 共3页
亲,该文档总共3页,全部预览完了,如果喜欢就下载吧!
资源描述

《C++语言基础教程 教学课件 ppt 作者 吕凤翥习题答案 1_ 第7章》由会员分享,可在线阅读,更多相关《C++语言基础教程 教学课件 ppt 作者 吕凤翥习题答案 1_ 第7章(3页珍藏版)》请在金锄头文库上搜索。

1、第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() struc

2、t 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.

3、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

4、应付金额为: 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

5、,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

展开阅读全文
相关资源
正为您匹配相似的精品文档
相关搜索

最新文档


当前位置:首页 > 高等教育 > 大学课件

电脑版 |金锄头文库版权所有
经营许可证:蜀ICP备13022795号 | 川公网安备 51140202000112号