-->
当前位置:首页 > 题库

PROGRAMMING:Constructors and destructors in simple inheritance

Luz5年前 (2021-05-10)题库526
Write code to achieve a point of the parent class dot and a circle of the subclass CIR, calculate the area of the circle.
The dot class has two private data members, float x, y;
CIR class adds a private data member radius float R and a public function getarea();
The main function has been given, please write dot and cir classes.
```
#include
#include
using namespace std;
const double PI=3.14;
//Please write your code
int main(){
float x,y,r;
cin>>x>>y>>r;
Cir c(x,y,r);
cout<return 0;
}
```
###Input format:
Enter the center and radius of the circle, x, y, R separated by a space.
###Output format:
Output the area of the circle, and reserve 2 significant digits after the decimal point. Note: const double pi = 3.14, area = ` pi * r * r '.
###Input example:
Here is a set of inputs. For example, the center point of a circle is the origin (0,0), and the radius is 3:
```in
0 0 4
```
###Output example:
The corresponding output is given here. For example:
```out
Dot constructor called
Cir constructor called
fifty point two four
Cir destructor called
Dot destructor called
```







answer:If there is no answer, please comment