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

加入VIP,免费下载
 

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

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

下载须知

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

版权提示 | 免责声明

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

类和对象练习题Word文档格式.docx

1、C).类的其他函数可以调用类的静态成员函数D).类的静态数据成员被类的所有对象共享14以下关于类和对象叙述正确的是_。A).一个类只能有一个对象B).一个对象可以属于几个不同的类C)对象是类的一个具体实例(实体)D)一个类中可以有本类的对象18_将在对象生存期结束时由系统自动调用。A) 构造函数 B) 成员变量函数 C) 析构函数 D) 虚函数19下面关于友员函数的说法中,正确的是 _ 。A)友员函数是本类的一个成员函数 B)友员函数可以通过对象访问本类的所有成员 C)友员函数有this指针D)友员函数可以直接访问本类的所有成员20假定AB为一个类名,则执行AB a(4),b5,*p; 语句时

2、,自动调用该类构造函数的次数为 。A)5 B)6 C)7 D)9二阅读程序, 写出以下程序运行结果。1.#include lass myclass int a,b; public: myclass (int i=0,int j=0); void show( ); ; myclass: myclass(int i,int j) a=i; b=j; void myclass:show( ) a+=b; b+=a;cout”a=”a ”b=”bendl; void main() myclass ob1; ob1.show(); myclass ob2(2); ob2,show(); myclass

3、ob3(2,5); ob3.show(); 运行结果: 2#include class cube public:cube(int ht=2,int wd=5,int dp=3) height=ht; width=wd; depth=dp;depth=depthconstruncted calledcube() coutDestructed calledint volume() return height *width*depth;private: int height,width,depth;void main() cube cone(10,20,15), ctwo;cone.volume()

4、ctwo.volume()运行结果:3写出以下程序运行结果。class Apublic:A() A(int i,int j):a(i),b(j) coutconstructorn;A() coutlead1lead2;total=p1*lead1+p2*lead2;void display() couttotal=total TC A,B(6,8);A.datap();A.display();5写出以下程序运行结果。#includeclass value int a; value()a=1; cout”Defaultn”;value(int i)a=i;”constructuren”;void

5、 list( )cout” “; value( ) cout”Destructuren”;void main( ) value data14;value data24=10,20,30;for(int i=0;i4;i+) data1i.list();for(i=0;i+) data2i.list();6写出以下程序运行结果。 A(int i,int j) a=i;constructor.n;A( ) coutDestructor int a,b; A *pa,*pb;pa=new A(4,6);pb=new A(10,15);delete pa;delete pb;7写出以下程序运行结果。c

6、lass countcount () count1+;static int data () return count1;count( ) count1-; static int count1;int count :count1=60; count a,b,c,d,e;count: data()a.data()e.data()8写出以下程序运行结果。class myclass int x,y;static long sum; myclass(int a,int b) x=a;y=b;void getxy() sum+=x*y;sum=sumA(char *str);A( ); char stri

7、ng50;A:A(char *str) strcpy(string,str);constructor called forstringA()destructor called forvoid fun() A funobject(Fun对象);static A staticobject(static对象In fun()A Globalobject(G对象 /全局对象 A Mainobject(Main对象In Main(), before calling funnfun( );In Main(), after calling funn10写出以下程序运行结果。class sample int x

8、,y; sample()x=0;y=0;sample(int i,int j)x=i;y=j;void copy(sample &A) x=A.x; y=A.y;void display()x=xendl y=yclass stringclass stringclass (char *str);stringclass();void showstring(); char *ptr;long len;stringclass:stringclass(char *str) len=strlen(str);ptr=new charlen+1;if(!ptr) coutAllocution errorn;

9、 exit(1);strcpy(ptr,str);stringclass()Freeing Allocutionn;deleteptr;void stringclass:showstring()ptrlen stringclass s1(C+ programming);stringclass s2(Test string);s1showstring();s2二 程序填空1编写一个求n!的类,分别输出29的阶乘。class FACT int n;long int fact;FACT(int );void display( ) coutn!=_ _ 1) fact*= _ ; val-; for(

10、int i=2;10;i+) FACT p(i); p.display();2以下程序能根据对象提供的长方形的长和宽得到该长方形的面积和周长。class rectangle float ledge,sedge;rectangle()ledge=0;sedge=0;rectangle(float a,float b) ledge=a; sedge=b;void area()cout”面积:” _ _ void length()cout”周长: _ _ rectangle A(3.5, 2.0),B(4.2, 2.0);A.area();A.length();B.area();B.length()

11、;3填空完成以下程序,使该程序的执行结果为10。class MyClass int x; x=n; int GetNum() ;void main() MyClass my(10);my.GetNum()4以下程序能实现求a2+b2+c2。其中a、b、c分别为5、10、15由不同对象的初始化值提供。该程序使用静态成员实现。class myclassmyclass(int x);void getnumber();static void Result();int a;_ _ ; /定义静态数据成员summyclass:myclass(int x)a=x;sum+=a*a;void myclass:

12、getnumber( )Number=Result( )Result=_ _ ; /static数据成员初始化void main()myclass ob1(5),ob2(10),ob3(15);ob1.getnumber();ob2.getnumber();ob3.getnumber();_ _; /调用Result输出结果5以下程序能求出n个不同字符串的总长度。程序中定义一个类,其中数据成员length记录每一个字符串的长度,静态数据成员total-length记录所有字符串的总长度,用静态成员函数求总长度。class stringstring(char *s);static int get

13、_total_length(string a);string() void show(); int length;static int total_length;char str80;string:string(char *s) /构造函数实现 length=strlen(s); strcpy(str,s);int string:get_total_length(string a) total_length+=a.length ;return total_length ;_ _ ;void string:show()str length=length string ob1(“The first

14、 abcde”);ob1.show();Total=get_total_length(obl)string ob2(“The second fghijklmn”);ob2.show();Total length=get_total_length(ob2)string ob3(program end!);ob3.show();Total_length=get_total_length(ob3)The first abcde length=15Total=15The second fghijklmn length=20Total length=35program end! length=12Tot

15、al_length=476某单位经销的货物,购进和卖出以重量为单位,以下程序记下目前库存货物的总重量(total_weight),在横线填空并写出运行结果.class goods static int total_weight;int weight; goods(int w) weight=w; total_weight +=w;goods(goods &gd) weight=gd.weight; total_weight+=weight;goods( ) total_weight -= weight; total_weightw;goods g1(w);” 第一种货物重”g1.get()”输

16、入第二种货物重量:goods g2(w);” 第二种货物重”g2.get()”货物总重量是:”; goods:gettotal( ) ob2.value2 )return 1;else if ( _ _ return -1;else return 0; classone ob1(40);classtwo ob2(15);if(function(ob1,ob2)=1) coutob2.valuen;else if( function(ob1,ob2)= =-1 ) coutob1.valueelse coutclass point public: point(double a,double b) x=a; y=b; double setx( ) return x; double sety( ) return y; friend double dist(point &d1,poin

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

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