欢迎来到天天文库
浏览记录
ID:6698016
大小:38.50 KB
页数:4页
时间:2018-01-22
《c++ 面向对象作业三》由会员上传分享,免费在线阅读,更多相关内容在教育资源-天天文库。
1、定义一个类B,该类包含用于输出信息的成员函数vf(),再设计一个继承于该类的派生类D,也包含用于输出信息的成员函数vf(),调用这两个函数,实现编译时的多态。ClassB{Public:Voidvf(){cout<<””<vf();Pb=&d;Pb->vf();Pd=(D*)&B;pd->vf();Pd=&d;pd->vf();}若改成运行
2、时多态;PublicB{Public:Voidvirtualvf(){cout<<””<3、lassincircle:publiccircle{Doublea;Public:Incircle(doublex=0):circle(x){}Voiddisplay(){A=sqrt(r) ;Cout<<”内切正方形面积”<4、dl;Cout<<”外切正方形周长”<<8*r<5、l;}}Classc:publicb{Public:C(){cout<<””<6、dl;}}设计一个抽象类Shape,使得其派生类Square、Circle和Rectangle都能定义计算面积函数Area()。Classshape{Public:Virtualvoidarea()=0;}ClassSquare:publicshape{Inta;Public:Doublearea(inta){Returna*a;}}ClassCircle:publicshape{Intr;Public:Doublearea(intr){Returnpi*r*r;}}ClassRectangle:publicshap7、e{Intl,w;Public:Doublearea(intl,intw){Returnl*w}}编写一个程序,重载插入符>>和提取符<<,使得这两种运算符对于复数也可以直接进行操作。Classcomplex{Doublereal;Doubleimag;Public:Complex(){real=0;imag=0;}Friendostream&operator>>(ostream&,complex&);Friendostream&operator<<(ostream&,complex&);Ostream&operat8、or<<(ostream&output,complex&c){Output<<”(“+c.real<<”+”<>(ostream&input,complex&c){Input>>c.real>>c.imag;Returninput;}}编写一个
3、lassincircle:publiccircle{Doublea;Public:Incircle(doublex=0):circle(x){}Voiddisplay(){A=sqrt(r) ;Cout<<”内切正方形面积”<4、dl;Cout<<”外切正方形周长”<<8*r<5、l;}}Classc:publicb{Public:C(){cout<<””<6、dl;}}设计一个抽象类Shape,使得其派生类Square、Circle和Rectangle都能定义计算面积函数Area()。Classshape{Public:Virtualvoidarea()=0;}ClassSquare:publicshape{Inta;Public:Doublearea(inta){Returna*a;}}ClassCircle:publicshape{Intr;Public:Doublearea(intr){Returnpi*r*r;}}ClassRectangle:publicshap7、e{Intl,w;Public:Doublearea(intl,intw){Returnl*w}}编写一个程序,重载插入符>>和提取符<<,使得这两种运算符对于复数也可以直接进行操作。Classcomplex{Doublereal;Doubleimag;Public:Complex(){real=0;imag=0;}Friendostream&operator>>(ostream&,complex&);Friendostream&operator<<(ostream&,complex&);Ostream&operat8、or<<(ostream&output,complex&c){Output<<”(“+c.real<<”+”<>(ostream&input,complex&c){Input>>c.real>>c.imag;Returninput;}}编写一个
4、dl;Cout<<”外切正方形周长”<<8*r<5、l;}}Classc:publicb{Public:C(){cout<<””<6、dl;}}设计一个抽象类Shape,使得其派生类Square、Circle和Rectangle都能定义计算面积函数Area()。Classshape{Public:Virtualvoidarea()=0;}ClassSquare:publicshape{Inta;Public:Doublearea(inta){Returna*a;}}ClassCircle:publicshape{Intr;Public:Doublearea(intr){Returnpi*r*r;}}ClassRectangle:publicshap7、e{Intl,w;Public:Doublearea(intl,intw){Returnl*w}}编写一个程序,重载插入符>>和提取符<<,使得这两种运算符对于复数也可以直接进行操作。Classcomplex{Doublereal;Doubleimag;Public:Complex(){real=0;imag=0;}Friendostream&operator>>(ostream&,complex&);Friendostream&operator<<(ostream&,complex&);Ostream&operat8、or<<(ostream&output,complex&c){Output<<”(“+c.real<<”+”<>(ostream&input,complex&c){Input>>c.real>>c.imag;Returninput;}}编写一个
5、l;}}Classc:publicb{Public:C(){cout<<””<6、dl;}}设计一个抽象类Shape,使得其派生类Square、Circle和Rectangle都能定义计算面积函数Area()。Classshape{Public:Virtualvoidarea()=0;}ClassSquare:publicshape{Inta;Public:Doublearea(inta){Returna*a;}}ClassCircle:publicshape{Intr;Public:Doublearea(intr){Returnpi*r*r;}}ClassRectangle:publicshap7、e{Intl,w;Public:Doublearea(intl,intw){Returnl*w}}编写一个程序,重载插入符>>和提取符<<,使得这两种运算符对于复数也可以直接进行操作。Classcomplex{Doublereal;Doubleimag;Public:Complex(){real=0;imag=0;}Friendostream&operator>>(ostream&,complex&);Friendostream&operator<<(ostream&,complex&);Ostream&operat8、or<<(ostream&output,complex&c){Output<<”(“+c.real<<”+”<>(ostream&input,complex&c){Input>>c.real>>c.imag;Returninput;}}编写一个
6、dl;}}设计一个抽象类Shape,使得其派生类Square、Circle和Rectangle都能定义计算面积函数Area()。Classshape{Public:Virtualvoidarea()=0;}ClassSquare:publicshape{Inta;Public:Doublearea(inta){Returna*a;}}ClassCircle:publicshape{Intr;Public:Doublearea(intr){Returnpi*r*r;}}ClassRectangle:publicshap
7、e{Intl,w;Public:Doublearea(intl,intw){Returnl*w}}编写一个程序,重载插入符>>和提取符<<,使得这两种运算符对于复数也可以直接进行操作。Classcomplex{Doublereal;Doubleimag;Public:Complex(){real=0;imag=0;}Friendostream&operator>>(ostream&,complex&);Friendostream&operator<<(ostream&,complex&);Ostream&operat
8、or<<(ostream&output,complex&c){Output<<”(“+c.real<<”+”<>(ostream&input,complex&c){Input>>c.real>>c.imag;Returninput;}}编写一个
此文档下载收益归作者所有