當前位置:
首頁 >
YTU 2917: Shape系列-3
發布時間:2025/7/14
54
豆豆
生活随笔
收集整理的這篇文章主要介紹了
YTU 2917: Shape系列-3
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
2917: Shape系列-3
時間限制:?1 Sec??內存限制:?128 MB提交:?372??解決:?237
題目描述
送給小亮的Rectangle類已完成,送給小華Circle類還沒有完成。Circle類有整型的數據成員color(小強的Shape類中的color可以繼續使用,無需新定義),浮點型的數據成員radius,求面積的成員函數area()。但是小聰沒有為Circle類寫構造函數和成員函數,請幫助小聰完成Circle類。小強寫的Shape類:
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()
{
Circle cc=Circle(3,1);
cout<<"Circle color:"<<cc.getcolor()<<endl
<<"Circle radius:"<<cc.getradius()<<endl
<<"Circle area:"<<cc.area()<<endl
<<"Circle price:"<<cc.price()<<endl;
return 0;
}
輸入
無
輸出
輸出小聰測試的Circle類的各個數據。
樣例輸出
Circle color:3 Circle radius:1 Circle area:3.14 Circle price:9.42 im0qianqian_站在回憶的河邊看著搖晃的渡船終年無聲地擺渡,它們就這樣安靜地畫下黃昏畫下清晨......
#include<iostream>
using namespace std;
#define PI 3.14
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 Circle
{
public:int x,y;Circle(int a,int b);int getcolor();int getradius();double area();double price();
};
Circle::Circle(int a,int b)
{x=a,y=b;
}
int Circle::getcolor()
{return x;
}
int Circle::getradius()
{return y;
}
double Circle::area()
{return PI*y;
}
double Circle::price()
{return x*PI;
}
int main()
{Circle cc=Circle(3,1);cout<<"Circle color:"<<cc.getcolor()<<endl<<"Circle radius:"<<cc.getradius()<<endl<<"Circle area:"<<cc.area()<<endl<<"Circle price:"<<cc.price()<<endl;return 0;
}
轉載于:https://www.cnblogs.com/im0qianqian/p/5989655.html
總結
以上是生活随笔為你收集整理的YTU 2917: Shape系列-3的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: JavaScript编码规范[百度]
- 下一篇: 客户端向服务端传送特殊字符解决方法(检测