C++问题:定义一个Rectangle类,包括两个数据成员length和width,以及用于求长方形面积的成员函数.

学习 时间:2026-04-07 18:03:33 阅读:4126
C++问题:定义一个Rectangle类,包括两个数据成员length和width,以及用于求长方形面积的成员函数.再定义Rectangle的派生类Rectangular,它包括一个新数据成员height和用来求长方体体积的成员函数.在main函数中,使用两个类,求某个长方形的面积和某个长方体的体积.

最佳回答

落寞的面包

愤怒的煎饼

2026-04-07 18:03:33

#includeusing namespace std;class Rectangle{protected:double length,width;public:Rectangle(double a,double b):length(a),width(b){}double area(){return length*width;}};class Rectangular:publiv class Rectangle{double height;public:Rectangular(double a,double b,double c):Rectangle(a,b){height=c;}doouble tiji(){return length * width * height ; }};int main(){Rectangle r1(1,2);Rectangular r2(1,2,3);cout

最新回答共有2条回答

  • 无聊的保温杯
    回复
    2026-04-07 18:03:33

    #includeusing namespace std;class Rectangle{protected:double length,width;public:Rectangle(double a,double b):length(a),width(b){}double area(){return length*width;}};class Rectangular:publiv class Rectangle{double height;public:Rectangular(double a,double b,double c):Rectangle(a,b){height=c;}doouble tiji(){return length * width * height ; }};int main(){Rectangle r1(1,2);Rectangular r2(1,2,3);cout

上一篇 She goes to work by car(同同义句 )怎么改

下一篇 菌落总数测定的空白可以做哪几种