日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當(dāng)前位置: 首頁 > 编程资源 > 编程问答 >内容正文

编程问答

[YTU]_2921( Shape系列-7)

發(fā)布時間:2025/4/16 编程问答 19 豆豆
生活随笔 收集整理的這篇文章主要介紹了 [YTU]_2921( Shape系列-7) 小編覺得挺不錯的,現(xiàn)在分享給大家,幫大家做個參考.

Description

小強做的Shape類在本次的測試中出了點狀況,發(fā)現(xiàn)原來是其中的area函數(shù)的問題,請大家根據(jù)題意,幫助小強完成改動后的Shape類。 小強寫的各種類 class Rectangle:public Shape
{
public:
?Rectangle(int c,double w,double h);
?double getwidth();
?double getheight();
?double area();
?double price();
protected:
?double height;
?double width;
};
Rectangle::Rectangle(int c,double w,double h):Shape(c)
{
?width=w;
?height=h;
}
double Rectangle::getwidth()
{
?return width;
}
double Rectangle::getheight()
{
?return height;
}
double Rectangle::area()
{
?return height*width;
}
double Rectangle::price()
{
?return height*width*color;
}??
class Circle:public Shape
{
public:
?Circle(int c,double r);
?double getradius();
?double area();
?double price();
protected:
?double radius;
};??
Circle::Circle(int c,double r):Shape(c)
{
?radius=r;
}
double Circle::getradius()
{
?return radius;
}
double Circle::area()
{
?return PI*radius*radius;
}
double Circle::price()
{
?return PI*radius*radius*color;
}
class Triangle:? public Shape
{
public:
?Triangle(int c,double b,double h);
?double area();
protected:
?double base,height;
};
Triangle::Triangle(int c,double b,double h):Shape(c)
{
?base=b;height=h;
}
double Triangle::area()
{
?return 0.5*base*height;
}
int main()
{
?Shape *pt[3];
?Rectangle rr(1,1,1);
?Circle cc(2,1);
?Triangle tt(2,1,3);
?pt[0]=&rr;
?pt[1]=&cc;
?pt[2]=&tt;
?cout<<"Rectangle area:"<<pt[0]->area()<<endl;
?cout<<"Circle area:"<<pt[1]->area()<<endl;
?cout<<"Triangle area:"<<pt[2]->area()<<endl;
return 0;?
}
提示:不用提交全部程序,只提交補充部分(包括頭文件和π的定義)。

Input

Output

小強測試的各個類面積的數(shù)據(jù)

Sample Output

Rectangle area:1 Circle area:3.14 Triangle area:1.5#include <iostream> #define PI 3.14 using namespace std; class Shape { public:Shape(int c);virtual double area()=0; protected:double color; }; Shape::Shape(int c){color=c;} class Rectangle:public Shape { public: Rectangle(int c,double w,double h); double getwidth(); double getheight(); double area(); double price(); protected: double height; double width; }; Rectangle::Rectangle(int c,double w,double h):Shape(c) { width=w; height=h; } double Rectangle::getwidth() { return width; } double Rectangle::getheight() { return height; } double Rectangle::area() { return height*width; } double Rectangle::price() { return height*width*color; } class Circle:public Shape { public: Circle(int c,double r); double getradius(); double area(); double price(); protected: double radius; }; Circle::Circle(int c,double r):Shape(c) { radius=r; } double Circle::getradius() { return radius; } double Circle::area() { return PI*radius*radius; } double Circle::price() { return PI*radius*radius*color; } class Triangle: public Shape { public:Triangle(int c,double b,double h);double area(); protected:double base,height; }; Triangle::Triangle(int c,double b,double h):Shape(c) {base=b;height=h; } double Triangle::area() {return 0.5*base*height; }int main() { Shape *pt[3];Rectangle rr(1,1,1);Circle cc(2,1);Triangle tt(2,1,3);pt[0]=&rr;pt[1]=&cc;pt[2]=&tt;cout<<"Rectangle area:"<<pt[0]->area()<<endl;cout<<"Circle area:"<<pt[1]->area()<<endl;cout<<"Triangle area:"<<pt[2]->area()<<endl; return 0; }

總結(jié)

以上是生活随笔為你收集整理的[YTU]_2921( Shape系列-7)的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網(wǎng)站內(nèi)容還不錯,歡迎將生活随笔推薦給好友。