Question: Write a Circle class that has the following member variables and using pointers, radius: a double pi: a double initialized with the value 3.14159 The

Write a Circle class that has the following member variables and using pointers,

radius: a double

pi: a double initialized with the value 3.14159 The class should have the following member functions:

Default Constructor. A default constructor that sets radius to 0.0.

Constructor. Accepts the radius of the circle as an argument.

setRadius. A mutator function for the radius variable.

getRadius. An accessor function for the radius variable.

getArea. Returns the area of the circle, which is calculated as area = pi * radius * radius

getDiameter. Returns the diameter of the circle, which is calculated as diameter = radius * 2

getCircumference. Returns the circumference of the circle, which is calculated as circumference = 2 * pi * radius

Write a program that demonstrates the Circle class by asking the user for the circles radius, creating a Circle object, and then reporting the circles area, diameter, and circumference. using pointers.

Use this program as an example of how it should look.

1 // Contact class specification file (version 2)

2 #ifndef CONTACTINFO_H

3 #define CONTACTINFO_H

4 #include // Needed for strlen and strcpy

5

6 // ContactInfo class declaration.

7 class ContactInfo

8 {

9 private:

10 char *name; // The contact's name

11 char *phone; // The contact's phone number

12

13 // Private member function: initName

14 // This function initializes the name attribute.

15 void initName(char *n)

16 { name = new char[strlen(n) + 1];

17 strcpy(name, n); }

18

19 // Private member function: initPhone

20 // This function initializes the phone attribute.

21 void initPhone(char *p)

22 { phone = new char[strlen(p) + 1];

23 strcpy(phone, p); }

24 public:

25 // Constructor

26 ContactInfo(char *n, char *p)

27 { // Initialize the name attribute.

28 initName(n);

29

30 // Initialize the phone attribute.

31 initPhone(n); }

32

33 // Destructor

34 ~ContactInfo()

35 { delete[] name;

36 delete[] phone; }

37

38 const char *getName() const

39 { return name; }

40

41 const char *getPhoneNumber() const

42 { return phone; }

43 };

44 #endif

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!