欢迎来到淘文阁 - 分享文档赚钱的网站! | 帮助中心 好文档才是您的得力助手!
淘文阁 - 分享文档赚钱的网站
全部分类
  • 研究报告>
  • 管理文献>
  • 标准材料>
  • 技术资料>
  • 教育专区>
  • 应用文书>
  • 生活休闲>
  • 考试试题>
  • pptx模板>
  • 工商注册>
  • 期刊短文>
  • 图片设计>
  • ImageVerifierCode 换一换

    C程序设计程序分析题.doc

    • 资源ID:3003146       资源大小:52.52KB        全文页数:9页
    • 资源格式: DOC        下载积分:8金币
    快捷下载 游客一键下载
    会员登录下载
    微信登录下载
    三方登录下载: 微信开放平台登录   QQ登录  
    二维码
    微信扫一扫登录
    下载资源需要8金币
    邮箱/手机:
    温馨提示:
    快捷下载时,用户名和密码都是您填写的邮箱或者手机号,方便查询和重复下载(系统自动生成)。
    如填写123,账号就是123,密码也是123。
    支付方式: 支付宝    微信支付   
    验证码:   换一换

     
    账号:
    密码:
    验证码:   换一换
      忘记密码?
        
    友情提示
    2、PDF文件下载后,可能会被浏览器默认打开,此种情况可以点击浏览器菜单,保存网页到桌面,就可以正常下载了。
    3、本站不支持迅雷下载,请使用电脑自带的IE浏览器,或者360浏览器、谷歌浏览器下载即可。
    4、本站资源下载后的文档和图纸-无水印,预览文档经过压缩,下载后原文更清晰。
    5、试题试卷类文档,如果标题没有明确说明有答案则都视为没有答案,请知晓。

    C程序设计程序分析题.doc

    !-三 程序分析题阅读以下程序,写出其运行结果。1#include <iostream.h>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 << endl;int fun( int i ) if ( i >= 10 ) throw i ; return ai ;2#include <iostream.h>void f();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 <iostream.h>class 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 << p1.fun() << endl; Bclass & p2 = obj ; cout << p2.fun() << endl; cout << p2.Bclass : fun() << endl; Bclass *p3 = &obj; cout << p3 -> fun() << endl;4#include <iostream.h>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() cout<<"x = "<<x<<t<<"y = x * x = "<<x*x<<endl; ;class B:public BASE public: void fun() cout << "x = " << x << t << "y = " << y << endl; cout << "y = x / y = " << x / y << endl; ;void main() BASE * pb; A obj1; B obj2; pb = &obj1; pb -> getxy( 10 ); pb -> fun(); pb = &obj2; pb -> getxy( 100, 20 );pb -> fun();5. #include <iostream.h>class BASE1 public: BASE1( int i ) cout << "调用基类BASE1的构造函数:" << i << endl ; ;class BASE2 public: BASE2( int 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 <iostream.h>class T public : T() a = 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; tempobj.a = a * obj.a; tempobj.b = b * obj.b; tempobj.c = c * obj.c; return tempobj;void main() T obj1( 1,2,3 ), obj2( 5,5,5 ), obj3; int a , b , c; obj3 = obj1 * obj2; obj3.get( 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 < iostream.h >class vector public: vector() vector(int i,int j) x = i ; y = j ; friend vector operator + ( vector v1, vector v2 ) vector tempvector ; tempvector.x = v1.x + v2.x ; tempvector.y = v1.y + v2.y ; return tempvector ; void display() cout << "( " << x << ", " << y << ") "<< endl ; private: int x , y ;void main() vector v1( 1, 2 ), v2( 3, 4 ), v3 ; cout << "v1 = " ; v1.display() ; cout << "v2 = " ; v2.display() ; v3 = v1 + v2 ; cout << "v3 = v1 + v2 = " ; v3.display() ; 8 #include < iostream.h > struct data int n ; int score ; ; void main() data a3 = 1000,83,1005,70,1009,95 , *p = a ; cout << (p+)-> score << endl ; cout << (p+)-> score << endl ; cout << p-> score << endl ; cout << (*p). score + << endl ; 9 #include < iostream.h >class A public :int f1();int f2();void setx( int m ) x = m ; cout << x << endl; void sety( int n ) y = n ; cout << 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 ;10 #include < iostream.h >class T public : T( int x, int y ) a = x ; b = y ; cout << "调用构造函数2." << endl ; cout << a << t << b << endl ; T( T &d ) cout << "调用构造函数1." << 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( 2, 4 ) ; T d2( d1 ) ; cout << d2.add( 8 ) << endl ;11 #include < iostream.h > class T public: T(int x) a=x; b+=x; static void display(T c) cout<<"a="<<c.a<<t<<"b="<<c.b<<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 < iostream.h >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 ) t.a + ; 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() ;13. #include <iostream.h>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" << endl; ;class D: public B public: D( ) cout << "D" << endl; void f( ) cout << "D:f" << endl; virtual D( ) cout << "D" << endl; private: A a;void main( ) B* pB = new D; pB->f( ); delete pB;14. class Myclasspublic: Myclass(int a,int b,int c); void PrintNumber( ); void PrintSum( ); private: int A,B,C; static int Sum; #include <iostream.h>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<<","<<C<<endl; void Myclass:PrintSum( ) cout<<"Sum="<<Sum<<endl;void main( ) Myclass M(3,7,10), N(14,9,1); M.PrintNumber( ); N.PrintNumber( ); M.PrintSum( ); N.PrintSum( );

    注意事项

    本文(C程序设计程序分析题.doc)为本站会员(小**)主动上传,淘文阁 - 分享文档赚钱的网站仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对上载内容本身不做任何修改或编辑。 若此文所含内容侵犯了您的版权或隐私,请立即通知淘文阁 - 分享文档赚钱的网站(点击联系客服),我们立即给予删除!

    温馨提示:如果因为网速或其他原因下载失败请重新下载,重复下载不扣分。




    关于淘文阁 - 版权申诉 - 用户使用规则 - 积分规则 - 联系我们

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

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

    收起
    展开