收藏 分享(赏)

面向对象程序设计C++双语.doc

上传人:hskm5268 文档编号:7674286 上传时间:2019-05-23 格式:DOC 页数:16 大小:124KB
下载 相关 举报
面向对象程序设计C++双语.doc_第1页
第1页 / 共16页
面向对象程序设计C++双语.doc_第2页
第2页 / 共16页
面向对象程序设计C++双语.doc_第3页
第3页 / 共16页
面向对象程序设计C++双语.doc_第4页
第4页 / 共16页
面向对象程序设计C++双语.doc_第5页
第5页 / 共16页
点击查看更多>>
资源描述

1、第 1 页 共 16 页12、For static member data, it is initialized at(b).A. Before the declaration of class and after the main functionB. Before the main function and after the declaration of classC. In the classD. In the main function二、Judgment, if it is right please otherwise . (Every question is 2 point, t

2、otal is 18 point)1、C+ is a sub-set of C, it reserves almost all the characteristics of C.-2、Given int a; int b=a; a=10; b=20; if coutvoid main()demo d;d.show();demo d1(3,5);d1.show();demo d2(d1);d2.show();class demoint x, y;public:-demo(int x=0,int y=0)-x=a; y=b;-demo(*d)- x=d.x;y=d.y;第 2 页 共 16 页-d

3、emo()- - Destructor is called.-void show()-cout#include class personchar *Name;int Age;public:person(char * name, int age);person();char *GetName()return Name;int GetAge()return Age;void show();person:person(char * name, int age)-Age=age;person:person()delete Name;void person:show() cout#include cla

4、ss Pointpublic:Point(double xx=0, double yy=0) X=xx;Y=yy;double GetX() return X;double GetY() return Y;-private:double X,Y;double Dist( Pointint main() Point p1(3.0, 5.0), p2(4.0, 6.0);-coutint sub(int n)int a;if(n=1)return 1;a=n+sub(n-1);return(a);第 4 页 共 16 页void main() int i=5;coutclass testpriva

5、te:int num;float fl;public:test( );int getint( )return num;float getfloat( )return fl;test( );test:test( )cout#includeclass Studentstring name;public:static int num;Student (string+num;int Student:num = 0; int main()Student s1(“Smith“), s2(“John”); coutclass B1 public:B1(int i) cout#include using na

6、mespace std;int main( )string str;coutstr;coutlong fac(int n)long f;bif (n1) f=n*fac(n-1);else f=1;return f;void main()coutvoid func(int p, int t=p; p=q; q=t;void main() int x=1,y=2;func(x,y);coutusing namespace std;class myclassint num;-public:myclass(int x)num=x;第 11 页 共 16 页- -myclass()sum=sum-1;

7、- -void display()cout#include class personchar *Name;int Age;public:person(char * name, int age);person();char *GetName()return Name;int GetAge()return Age;void show();person:person(char * name, int age)-Age=age;person:person()delete Name;void person:show() coutusing namespace std;class birthdaypriv

8、ate:int year, month, day;public:birthday(int Year,int Month,int Day)year=Year; month=Month; day=Day;-void show() coutclass simplecat public:simplecat(int age=1, int weight=2); int GetAge() return itsage;int GetWeight() return itsweight;private:int itsage;int itsweight;simplecat:simplecat(int age, in

9、t weight) itsage=age;itsweight=weight;void main()simplecat F1; coutclass Cint d;static int s;public:C(int a=0) d=a; s+; int GetD() return d;int GetS() return s;void SetD(int a) d=a;第 14 页 共 16 页int C:s=0;void main()C c5;for (int i=0; iclass C1int x1;public:C1(int a=0)x1=a;coutclass Bpublic:B();B(int

10、 i);B() cout“Bs destructor called.“endl;void Print() coutbendl;private:int b;B:B() b=0;cout“Bs default constructor called.“endl;B:B(int i) b=i;cout“Bs constructor called.“ endl;class C: public Bpublic:C();C()cout“Cs destructor called.“endl;C(int i,int j);void Print()B:Print(); coutcendl;private:int

11、c;C:C() c=0;cout“Cs default constructor called.“endl;C:C(int i,int j):B(i) c=j;cout“Cs constructor called.“endl;int main()C obj2;obj2.Print();return 0;A (class)*NameSetName()GetName()B (class)*Depf1( )C (class)*Spef2( )D (class)Finish()第 16 页 共 16 页V、Programming (The question takes 15 points)According to the following class structure, design an optimal C+ program and give a main function to describe the outputs of the program. (Requirement: in the derived classes B, C, and D, constructors must be used.)

展开阅读全文
相关资源
猜你喜欢
相关搜索

当前位置:首页 > 企业管理 > 管理学资料

本站链接:文库   一言   我酷   合作


客服QQ:2549714901微博号:道客多多官方知乎号:道客多多

经营许可证编号: 粤ICP备2021046453号世界地图

道客多多©版权所有2020-2025营业执照举报