C++程序设计基础课后答案--第五章教学提纲.docx

上传人:h**** 文档编号:27168177 上传时间:2022-07-22 格式:DOCX 页数:7 大小:12.31KB
返回 下载 相关 举报
C++程序设计基础课后答案--第五章教学提纲.docx_第1页
第1页 / 共7页
C++程序设计基础课后答案--第五章教学提纲.docx_第2页
第2页 / 共7页
点击查看更多>>
资源描述

《C++程序设计基础课后答案--第五章教学提纲.docx》由会员分享,可在线阅读,更多相关《C++程序设计基础课后答案--第五章教学提纲.docx(7页珍藏版)》请在taowenge.com淘文阁网|工程机械CAD图纸|机械工程制图|CAD装配图下载|SolidWorks_CaTia_CAD_UG_PROE_设计图分享下载上搜索。

1、C+程序设计基础课后答案-第五章教学提纲 C+程序设计基础课后答案-第五章 5.1 阅读下列程序,写出执行结果 1#include struct data int n ; float score ; ; void main() data a3 = 1001,87,1002,72,1003,90 , *p = a ; cout s q-s q-q-s endl ; 4#include class A public : int f1(); int f2(); void setx( int m ) x = m ; cout x endl; void sety( int n ) y = n ; cou

2、t y endl; int getx() return x ; int gety() return y ; private : int x, y ; ; int A:f1() return x + y ; int A:f2() return x - y ; void main() A a ; a.setx( 10 ) ; a.sety( 5 ) ; cout a.getx() t a.gety() endl ; cout a.f1() t a.f2() endl ; 5 #include class T public : T( int x, int y ) a = x ; b = y ; co

3、ut 调用构造函数1. endl ; cout a t b endl ; T( T &d ) cout 调用构造函数2. endl ; cout d.a t d.b endl ; T() cout 调用析构函数.endl; int add( int x, int y = 10 ) return x + y ; private : int a, b ; ; void main() T d1( 4, 8 ) ; T d2( d1 ) ; cout d2.add( 10 ) endl ; 6 #include class T public: T(int x) a=x; b+=x; static vo

4、id display(T c) couta=c.atb=c.bendl; private: int a; static int b; ; int T:b=5; void main() T A(3),B(5); T:display(A); T:display(B); 7 #include #include class point public : point( float x, float y ) a = x; b = y;? cout 点( a , b ) ; friend double d( point &A , point &B ) return sqrt(A.a-B.a) * (A.a-

5、B.a) + (A.b-B.b) * (A.b-B.b) ; private: double a, b ; ; void main() point p1( 2, 3 ) ; cout 到 ; point p2( 4, 5 ) ; cout 的距离是: d( p1,p2 ) endl ; 8 #include class A public : A() a = 5 ; void printa() cout A:a = a endl ; private : int a ; friend class B ; ; class B public: void display1( A t ) t.a + ;

6、cout display1:a = t.a endl ; ; void display2( A t ) t.a - ; cout display2:a = t.a endl ; ; ; void main() A obj1 ; B obj2 ; obj1.printa() ; obj2.display1( obj1 ) ; obj2.display2( obj1 ) ; obj1.printa() ; 5.2 思考题 1结构和类有什么区别?如果把程序中定义结构的关键字struct直接改成class,会有什么问题?用教材上的一个例程试一试,想一想做什么修改能使程序正确运行? 2分析以下说明结构的语句 struct node int data; node error; /错误 node * ok; /正确 ; error和ok分别属于什么数据类型?有什么存储要求?error出错的原因是什么? 3有说明 class A int a; double x; public: funMember(); ; A a1, a2, a3 ;

展开阅读全文
相关资源
相关搜索

当前位置:首页 > 应用文书 > 策划方案

本站为文档C TO C交易模式,本站只提供存储空间、用户上传的文档直接被用户下载,本站只是中间服务平台,本站所有文档下载所得的收益归上传人(含作者)所有。本站仅对用户上传内容的表现方式做保护处理,对上载内容本身不做任何修改或编辑。若文档所含内容侵犯了您的版权或隐私,请立即通知淘文阁网,我们立即给予删除!客服QQ:136780468 微信:18945177775 电话:18904686070

工信部备案号:黑ICP备15003705号© 2020-2023 www.taowenge.com 淘文阁