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

加入VIP,免费下载
 

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

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

下载须知

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

版权提示 | 免责声明

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

C++课程实验3文档格式.docx

1、copy(Myclass &my) this-x=my.x;y=my.y;*/-not use this-void Myclass: x=my.x; y=my.y;void main() Myclass my(10,20),t(30,40); my.print( ); my.copy(t);/*(2)设计一个类,实现两个复数的四则运算。实现加减乘除功能的函数用友元函数实现。*/#include0) coutre+imreal1image1;输入第二个复数的实部和虚部:real2image2; complex myp1(real1,image1),myp2(real2,image2); add(

2、myp1,myp2); sub(myp1,myp2); pls(myp1,myp2); div(myp1,myp2);3/*分析下面程序,给出横线部分的语句,并分析程序的输出,和m_count的功能*/class A static int m_counter; A(); A(); static void display();int A:m_counter=0;/ /将m_counter初始化为;A:A() m_counter+;A() m_counter-;void A:display()There are:m_counterobjects of class A.nint main() A a

3、1; A a2; A a3; A:display(); a1.display();4 /*商店经销一种货物,货物成箱购进,成箱卖出,购进和卖出时以重量为单位,各箱的重量不一样,单价不一样,因此商店需要记录下目前库存的货物的总重量和总价值。编写一个程序,通过定义类Carlo来模拟商店货物购进和卖出的情况。 本题目主要练习静态数据成员的使用,定义私有变量存每件货物的价格和重量,用静态数据成员存货物的总重量和总价钱,定义构造函数和析构函数,当定义新的对象完成初始化的功能和删除对象时,从总重量和总价钱中减去对象的重量和价格*/定义Box类class Box float weight; /每一箱的重量

4、float price; /每一箱的单价 friend class Carlo; /Carlo是Box的友元类,故可以直接调用Box的私有成员 Box(float x=0,float p=0) /构造函数 weight=x;price=p;/定义Carlo类class Carlo static int num; /交易次数 static float totalweight;/定义总重量 static float totalprice;/定义总价值 Carlo(); Carlo()num-; void buy(Box& p); void sell(Box&/静态变量初始化int Carlo:nu

5、m=0;float Carlo:totalprice=0;totalweight=0;/-/函数实现Carlo:Carlo() num+;The numth business /交易之前的货物总价值和总重量The totalweight of the goods shop has is totalweightThe totalprice of the goods shop has is totalprice0)/首先判断当前货物是否满足卖出重量 totalweight=totalweight-p.weight;The totalweight after selling is totalpric

6、e=totalprice-p.price*p.weight;The totalprice after selling is Dont have the enough goods Box b1(10,2),b2(3,3); Carlo shop; shop.buy(b1); shop.sell(b2); Carlo shop2; shop2.buy(b1);/*5.1)。编写一个类Node,声明一个数据成员member和已经静态成员count,另构造函数初始化数据成员,并把静态数据成员加,另析构函数把静态数据成员减。class Node int member; static int count;

7、 Node(int x=0) member=x; count=+1; Node()count-=1;int Node:count=0;/*5.2)。在)的基础上编写应用程序,创建个对象,然后显示他们的数据成员和静态成员,再析构每个对象,并显示他们对静态数据成员的影响。 count+; Node() count-;析构以后count=count void showM()coutmember=member void showC()coutcount= Node n1(1),n2(2),n3(3); n1.showM(); n1.showC(); n2.showM(); n2.showC(); n3

8、.showM(); n3.showC();/*5.3修改),让静态成员函数访问静态数据成员,并让静态数据成员是私有的。 static void showC()cout Node:showC();/*(6)个类分别为整型数集合类和实型数集合数类。将缺少的内容补齐。并完成要求的其它内容。如:(1)在Intset中再增加一个成员函数,将对象的整型数据拷贝的到floatset的对象中此成员函数的原型为:void settofloat(floatset &set);/形参为拷贝的目标对象/class floatset;class floatset float num3; /friend class In

9、tset; floatset( float x,float y, float z) /添加初始化内容 num0=x; num1=y; num2=z; void set1(float x,float y,float z) void print( ) /打印数据 for(int i=0;i3;i+) coutnum=numinum0; set.num1=this-num1; set.num2=this-num2;/*7.1分析以下程序的功能,把程序用三种方法(公有数据成员)补充完整,实现对对象peppy的成员*/class Animal;/void SetValue(Animal&, int);,

10、 int, int);class Animal Animal():itsWeight(0),itsAge(0) void show()coutitsWeightendlitsAge int itsWeight; int itsAge;void SetValue(Animal& ta, int tw) / 设置itsWeight值 ta.itsWeight=tw; ta, int tw, int tn) / 设置itsWeight和itsAge值 ta.itsAge=tn; Animal peppy; SetValue(peppy, 5); peppy.show(); SetValue(peppy, 7, 9); return 0;7.2*分析以下程序的功能,把程序用三种方法(友元访问私有数据成员) friend void SetValue(Animal& ta, int tw); ta, int tw, int tn);/*7.3分析以下程序的功能,把程序用三种方法(用成员函数访问私有数据成员) void set1( int tw, int tn ) itsWeight = tw; itsAge = tn; void set2( int tw ) ta.set2(tw); ta.set1(tw,tn); peppy.show()

copyright@ 2008-2023 冰点文库 网站版权所有

经营许可证编号:鄂ICP备19020893号-2