Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

The purpose of this assignment is to give you some practice with creating your own classes. This program serves as the basis for all the

The purpose of this assignment is to give you some practice with creating your own classes. This program serves as the basis for all the other programming assignments in this class and your future Computer Science classes.
Reminders:
Do not put all your code into a single file. It will cost you points.
Each Class you create requires two files. The first one is
.
h and the second one is
.
cpp
.
If each Class is not in this format, it will cost you points.
o Do a Google search on C
+
+
.
h vs
.
cpp to get a good idea of what type of code goes in each file. Putting the wrong code in one of the files can cost you points.
Each class has one or more constructors. Many students make a mistake with their Class constructors
(
you will be learning about them
)
and use code that looks like this:
(
std::string k
)
: setName
(
k
)
{
}
o The code in bold and yellow belongs between the
{
}
,
not in the declaration line of the constructor. There is a loophole in C
+
+
that allows you to put code after the constructor declaration, but in CSIS
1
1
2
,
always put the code between the
{
}
,
or it will cost you points. Use the example below for the correct format.
(
std::string k
)
{
setName
(
k
)
;
}
o You will find examples of code after the constructor declaration and a colon. The only purpose we put code after the constructor declaration in this class is when we get into Inheritance. We will not use Inheritance until the last few weeks of the course.
Unless instructed to do so
,
there is no user input or output done inside a class.
Remember to review the checklist at the end of the instructions.
INSTRUCTIONS
Class:
Name: Circle
Purpose: To accept and store the data for a circle and to provide functions that will manipulate the data.
Constructor:
Zero
-
argument constructor that initializes the data members to
0
.
Data Members:
radius
int Must be
1
.
0
or greater.
colorFill
string Cannot be blank.
Functions:
calcDiameter
(
)
-
double Calculates and returns the diameter of the circle. The diameter is a double.
calcArea
(
)
-
double Calculates and returns the area of the circle. The area is a double.
calcCircumference
(
)
-
double Calculates and returns the circumference of the circle. The circumference is a double.
setRadius
(
)
-
void Accepts a radius value and updates the radius data member.
getRadius
(
)
-
int Returns the value stored in the radius data member.
setColorFill
(
)
-
void Accepts the fill color value and updates the colorFill data member.
getColorFill
(
)
-
string Returns the value stored in the colorFill data member.
Note: Setters and Getters are required even if they are not used.
Non
-
Class Functions:
displayCircleInfo
(
)
void Creates and displays the formatted output of the book shipment information. Do a Google search for C
+
+
setw
(
)
,
left, right for how to use these functions
/
commands to create easy to read formatted output.
Formulas:
Note: The calc functions are returning a double, and the radius is an integer. The simplest way to convert an int to a double is to multiply the radius by
1
.
0
.
Example: double myDiameter; myDiameter
=
(
getRadius
*
1
.
0
)
*
2
;
Area
=
Pi
*
radius squared For Pi
,
use the value of
3
.
1
4
so your results will match mine. You can make this a const using the following line of code in the Circle.cpp file above the constructor const double PI
=
3
.
1
4
; For radius squared, use the pow
(
)
function instead of getRadius
(
)
*
getRadius
(
)
Example: pow
(
4
,
2
)
is
4
squared where
4
is the value of the radius, and
2
is the power to
raise the radius to
,
in this case, squared. Use the getRadius
(
)
function to get the radius value.
Circumference
=
2
*
PI
*
radius
Diameter
=
2
*
radius
The class should use appropriate protection levels for the member data and functions. Data members must be in the private: section. It must also follow
principles of minimalization
: that is
,
no data member should be part of a class unless most functions of the object need it
.
A general rule of thumb is that
if you can easily calculate it
,
don
t store it
.
Program Flow:
Start a loop that goes until the user enters
-
1
for the radius.
Create the Circle object using the zero argument constructor.
Prompt the user for the radius. If the user enters
-
1
,
exit the loop, otherwise, update the Circle object with the value entered.
Prompt the user for the fill color and update the Circle object with the value entered.
Display the Circl

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_2

Step: 3

blur-text-image_3

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

Data Mining Concepts And Techniques

Authors: Jiawei Han, Micheline Kamber, Jian Pei

3rd Edition

0123814790, 9780123814791

More Books

Students also viewed these Databases questions

Question

in computer programming Universal means supporting?

Answered: 1 week ago

Question

How do Data Types perform data validation?

Answered: 1 week ago

Question

How does Referential Integrity work?

Answered: 1 week ago