ImageVerifierCode 换一换
格式:DOCX , 页数:13 ,大小:16.31KB ,
资源ID:29765299      下载积分:3 金币
快捷下载
登录下载
邮箱/手机:
温馨提示:
快捷下载时,用户名和密码都是您填写的邮箱或者手机号,方便查询和重复下载(系统自动生成)。 如填写123,账号就是123,密码也是123。
特别说明:
请自助下载,系统不会自动发送文件的哦; 如果您已付费,想二次下载,请登录后访问:我的下载记录
支付方式: 支付宝    微信支付   
验证码:   换一换

加入VIP,免费下载
 

温馨提示:由于个人手机设置不同,如果发现不能下载,请复制以下地址【https://www.bdocx.com/down/29765299.html】到电脑端继续下载(重复下载不扣费)。

已注册用户请登录:
账号:
密码:
验证码:   换一换
  忘记密码?
三方登录: 微信登录   QQ登录  

下载须知

1: 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。
2: 试题试卷类文档,如果标题没有明确说明有答案则都视为没有答案,请知晓。
3: 文件的所有权益归上传用户所有。
4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
5. 本站仅提供交流平台,并不能对任何下载内容负责。
6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。

版权提示 | 免责声明

本文(c程序分析题.docx)为本站会员(b****8)主动上传,冰豆网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对上载内容本身不做任何修改或编辑。 若此文所含内容侵犯了您的版权或隐私,请立即通知冰豆网(发送邮件至service@bdocx.com或直接QQ联系客服),我们立即给予删除!

c程序分析题.docx

1、c程序分析题三 程序分析题阅读以下程序,写出其运行结果。1#include using namespace std;int a 10 = 1, 2, 3, 4, 5, 6, 7, 8, 9, 10 ;int fun( int i );void main() int i ,s = 0; for( i = 0; i = 10; i+ ) try s = s + fun( i ) ; catch( int ) cout 数组下标越界! endl; cout s = s = 10 ) throw i ; return ai ;2#include using namespace std;void f()

2、;class T public: T() cout constructor endl; try throw exception; catch( char * ) cout exception2 endl; throw exception; T() cout destructor; ;void main() cout main function endl; try f() ; catch( char * ) cout exception1 endl; cout main function endl; void f() T t; 3#include using namespace std;clas

3、s Bclass public:Bclass( int i, int j ) x = i; y = j; virtual int fun() return 0 ; protected: int x, y ;class Iclass:public Bclass public : Iclass(int i, int j, int k):Bclass(i, j) z = k; int fun() return ( x + y + z ) / 3; private : int z ;void main() Iclass obj( 2, 4, 10 ); Bclass p1 = obj; cout ()

4、 endl; Bclass & p2 = obj ; cout () endl; cout : fun() endl; Bclass *p3 = &obj; cout fun() endl;4#include using namespace std;class BASE public: virtual void getxy( int i,int j = 0 ) x = i; y = j; virtual void fun() = 0 ; protected: int x , y; ;class A: public BASE public:void fun() coutx = xty = x *

5、 x = x*xendl; ;class B:public BASE public: void fun() cout x = x t y = y endl; cout y = x / y = x / y getxy( 10 ); pb - fun(); pb = &obj2; pb - getxy( 100, 20 ); pb - fun();5. #include using namespace std;class BASE1 public: BASE1( int i ) cout 调用基类BASE1的构造函数: i endl ; ;class BASE2 public: BASE2( in

6、t j ) cout 调用基类BASE2的构造函数: j endl ; ; class A: public BASE1, public BASE2 public:A( int a, int b, int c, int d ) : BASE2(b), BASE1(c), b2(a), b1(d) cout 调用派生类A的构造函数: a+b+c+d endl; private: BASE1 b1; BASE2 b2; ; void main() A obj( 1, 2, 3, 4 ); 6. #include using namespace std;class T public : T() a =

7、 0; b = 0; c = 0; T( int i , int j , int k ) a = i; b =j ; c = k; void get( int &i , int &j , int &k ) i = a; j = b; k = c; T operator * ( T obj );private: int a , b , c;T T:operator * ( T obj ) T tempobj; = a * ; = b * ; = c * ; return tempobj;void main() T obj1( 1,2,3 ), obj2( 5,5,5 ), obj3; int a

8、 , b , c; obj3 = obj1 * obj2; ( a, b, c ); cout ( obj1 * obj2 ): t a = a t b = b t c = c t endl; ( obj2 * obj3 ).get( a, b, c ); cout ( obj2 * obj3 ): t a = a t b = b t c = c t endl;7. #include using namespace std;class vector public: vector() vector(int i,int j) x = i ; y = j ; friend vector operat

9、or + ( vector v1, vector v2 ) vector tempvector ; = + ; = + ; return tempvector ; void display() cout ( x , y ) endl ; private: int x , y ;void main() vector v1( 1, 2 ), v2( 3, 4 ), v3 ; cout v1 = ; () ; cout v2 = ; () ; v3 = v1 + v2 ; cout v3 = v1 + v2 = ; () ; 8 #include using namespace std; struc

10、t data int n ; int score ; ; void main() data a3 = 1000,83,1005,70,1009,95 , *p = a ; cout score endl ; cout score endl ; cout score endl ; cout (*p). score + endl ; 9 #include using namespace std;class A public :int f1();int f2();void setx( int m ) x = m ; cout x endl; void sety( int n ) y = n ; co

11、ut 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 ;( 10 ) ; ( 5 ) ;cout () t () endl ;cout () t () endl ;10#include using namespace std;class T public : T( int x, int y ) a = x ; b = y ; cout 调用构造函数2. endl ;

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

13、outa=tb=endl; private: int a; static int b; ;int T:b=5;void main() T A(3),B(5); T:display(A); T:display(B);12#include using namespace std;class A public : A() a = 25 ; void printa() cout A:a = a endl ; private : int a ; friend class B ; ;class B public: void display1( A t ) + ; cout display1:a = end

14、l ; ; void display2( A t ) - ; cout display2:a = endl ; ;void main() A obj1 ; B obj2 ; () ; ( obj1 ) ; ( obj1 ) ; () ;13. #include using namespace std;class A public: A( ) cout A endl; A( ) cout A endl; ; class B public: B( ) f( ); cout B endl; virtual void f( ) cout B:f endl; virtual B( ) cout B en

15、dl; ;class D: public B public: D( ) cout D endl; void f( ) cout D:f endl; virtual D( ) cout D f( ); delete pB;14. #include using namespace std;class Myclasspublic: Myclass(int a,int b,int c); void PrintNumber( ); void PrintSum( ); private: int A,B,C; static int Sum; int Myclass:Sum=10; Myclass:Myclass(int a,int b,int c) A=a; B=b; C=c; Sum+=A+B+C; void Myclass:PrintNumber() cout Number=A,B,Cendl; void Myclass:PrintSum( ) coutSum=Sumendl;void main( ) Myclass M(3,7,10), N(14,9,1); ( ); ( ); ( ); ( );

copyright@ 2008-2022 冰豆网网站版权所有

经营许可证编号:鄂ICP备2022015515号-1