Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Q8: Design and implement in C# a class named Circle that has the following: Fields: - radius: a double - PI : a const double

Q8: Design and implement in C# a class named Circle that has the following:

Fields:

- radius: a double

- PI : a const double initialized with the value 3.14159

Constructors:

- A one-argument constructor that accepts a radius of the circle as an argument.

- A no-argument constructor that sets the radius field to 0.0.

Properties:

-Radius

-both set and

get where set should ensure that a negative value will not be stored by assigning a 0 (do not print out an error message as that should be done in the program that uses Circle)

Methods:

- GetArea: returns the area for the circle, which is calculated as area = PI x radius2

- GetCircumference: returns the circumference of the circle, which is calculated as: circumference = 2 x PI x Radius

The basic structure of your Circle class might look something like:

public class Circle

{

private double radius

private const double PI = 3.14159;

// No argument constructor

public Circle()

{

//insert code here

}

//GetArea

public double GetArea()

{

//insert code here

}

//GetCircumference

public double GetCircumference()

{

//insert code here

}

}

Once you have written the Circle class, write a driver program (i.e. a class in another file that has a Main() method) that demostrates the working of the circle class by creating several Circle objects, asking the user for the raduis (and validating that is is positive), and then printing the circles' area and circumference. Use a loop to allow the program to test several different values so you can demonstrate that the program works for a range of input. Be sure you show that both constructors work.

NOTE: On this assignment you can assume the correct datatype: that is, if the program requests a double, you can assume that the user will input a double, etc . You need to validate that the data entered is in the correct range.

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

Database Publishing With Filemaker Pro On The Web

Authors: Maria Langer

1st Edition

0201696657, 978-0201696653

More Books

Students also viewed these Databases questions

Question

=+What is the most that you should pay to complete development?

Answered: 1 week ago

Question

=+development and make the product, should you go ahead and do so?

Answered: 1 week ago