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

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 编程资源 > 编程问答 >内容正文

编程问答

[YTU]_2916(Shape系列-2)

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

Description

小聰不喜歡小強的Shape類,聲稱用Shape類做出的形狀不真實,于是小聰創建了Rectangle類,并且決定用該類做兩個矩形出來,送給好朋友小亮。Rectangle類有整型的數據成員color(小強的Shape類中的color可以繼續使用,無需新定義),浮點型的數據成員widthheight,求面積的成員函數area()。但是小聰沒有為Rectangle類寫構造函數和成員函數,請幫助小聰完成Rectangle類。

小強寫的文件頭和Shape類:

#include<iostream>

using namespace std;

class Shape { public: Shape(); Shape(int c); int getcolor(); double area(); protected: int color; }; Shape::Shape()
{ color=0; }
Shape::Shape(int c)
{ color=c; }
int Shape::getcolor()
{
??????? return color; }
double Shape::area()
{
?????? return 10000;
}
小聰的測試函數: int main() { Rectangle rr=Rectangle(1,2,3); cout<<"Rectangle color:"<<rr.getcolor()<<endl <<"Rectangle width:"<<rr.getwidth()<<endl <<"Rectangle height:"<<rr.getheight()<<endl <<"Rectangle area:"<<rr.area()<<endl <<"Rectangle price:"<<rr.price()<<endl; return 0; } 提示:不用提交全部程序,只提交補充部分。

Input

Output

輸出小聰創建的矩形的相關數據。

Sample Output

Rectangle color:1Rectangle width:2Rectangle height:3Rectangle area:6Rectangle price:6#include<iostream> using namespace std; class Shape { public: Shape();Shape(int c);int getcolor();double area(); protected:int color; }; Shape::Shape() {color=0; } Shape::Shape(int c) {color=c; } int Shape::getcolor() {return color; } double Shape::area() {return 10000; } class Rectangle:public Shape { public:Rectangle(){}Rectangle(int c,int w,int h):Shape(c),width(w),height(h){}int getwidth();int getheight();int area();int price(); private:int width,height; };int Rectangle::getwidth() {return width;} int Rectangle::getheight() {return height;} int Rectangle::area() {return width*height;} int Rectangle::price() {return width+height+color;} int main(){Rectangle rr=Rectangle(1,2,3);cout<<"Rectangle color:"<<rr.getcolor()<<endl<<"Rectangle width:"<<rr.getwidth()<<endl<<"Rectangle height:"<<rr.getheight()<<endl<<"Rectangle area:"<<rr.area()<<endl<<"Rectangle price:"<<rr.price()<<endl;return 0; }

總結

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

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。