Class

First of all, I kinda dont know is this mean (English is my 7th lag)
I got the first part but now the second part:

1
2
3
A.	Write a statement that defines an array of 5 objects of the Circle class. Let the default constructor execute for each element of the array.
B.	Write a statement that defines an array of 5 objects of the Circle class. Now pass the following arguments to the elements’ constructor: 12, 7, 9, 14 and 8.
C.	Write a for loop that displays the radius and area of the circles represented by the array that you defined in part B of this problem.





1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
#include <iostream>
using namespace std;

class Circle
{
public:
	Circle();
	void set(double r);
	double get();
	double getArea();
private:
	double radius;
};

int main()
{
	Circle cir;
	
	
	return 0;
}

Circle::Circle()
{
	radius = 0;
}

void Circle::set(double r)
{
	radius = r;
}

double Circle::get()
{
	return radius;
}

double Circle::getArea()
{
	return 3.14*radius*radius;
}
Ok, so for the second one you need to define another constructor that can take a double.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
class Circle
{
public:
	Circle();
	Circle(double num); // <-- New constructor definition
	void set(double r);
	double get();
	double getArea();
private:
	double radius;
};

Circle::Circle(double num)
{
    radius = num;
}


For the third one you just need to use your get() and getArea() functions.
i dont get it
Topic archived. No new replies allowed.