Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

C++ Exercise #1: Design and implement class Circle to represent a circle object. The class defines the following attributes (variables) and methods: A private variable

C++ Exercise #1: Design and implement class Circle to represent a circle object. The class defines the following attributes (variables) and methods:

A private variable of type double named radius to represent the radius. Set to 1.

Constructor Methods:

Python : An overloaded constructor method to create a default circle.

C# & Java: Default Constructor with no arguments.

C# & Java: Constructor method that creates a circle with user-specified radius.

Method getRadius() that returns the radius.

Method setRadius() that sets the radius.

Method getArea() that returns the area.

Method getPerimeter() that returns the perimeter.

Method toString()to printout a meaningful description of the circle as follows:

The circle has radius X. Where X is the value of variable radius.

Now design and implement a test program to create a default circle object and test all class methods on the object. Print the object after each method call and use meaningful label for each method call as shown in the following sample run.

Sample run:

Print radius:

The radius is 1.

Print area:

The area is 3.14

Print perimeter:

The perimeter is 6.28

Set radius to 10 and print the object: The circle has radius 10.

Print area:

The area is 314.23

Print perimeter:

The perimeter is 62.81

Exercise #2: Design and implement class Radio to represent a radio object. The class defines the following attributes (variables) and methods:

Assume that the station and volume settings range from 1 to 10.

A private variable of type int named station to represent a station number. Set to 1.

A private variable of type int named volume to represent the volume setting. Set to 1.

A private variable of type boolean named on to represent the radio on or off. Set to false.

A non-argument constructor method to create a default radio.

Method getStation() that returns the station.

Method getVolume() that returns the volume.

Method turnOn() that turns the radio on.

Method turnOff() that turns the radio off.

Method stationUp() that increments the station by 1 only when the radio is on.

Method stationDown() that decrements the station by 1 only when the radio is on.

Method volumeUp() that increment the volume by 1 only when the radio is on.

Method volumeDown() that decrements the volume by 1 only when the radio is on.

Method toString()to printout a meaningful description of the radio as follows(if the radio is on):

The radio station is X and the volume level is Y. Where X and Y are the values of variables station and volume. If the radio is off, the message is: The radio is off.

Now design and implement a test program to create a default radio object and test all class methods on the object in random order. Print the object after each method call and use meaningful label for each method call as shown in the following sample run.

Sample run:

Turn radio on:

The radio station is 1 and the volume level is 1.

Turn volume up by 3:

The radio station is 1 and the volume level is 4.

Move station up by 5:

The radio station is 6 and the volume level is 4.

Turn volume down by 1:

The radio station is 6 and the volume level is 3.

Move station up by 3:

The radio station is 9 and the volume level is 3.

Turn radio off.

The radio is off.

Turn volume up by 2: The radio is off.

Turn station down by 2: The radio is off.

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

More Books

Students also viewed these Databases questions

Question

=+Is it possible to operate union-free?

Answered: 1 week ago

Question

=+impact member states and MNEs?

Answered: 1 week ago