Construct a class named Circle that has a floating-point data member named radius. The class should have a zero-argument constructor that initializes this data member to 0. It should have member functions named calcCircumferencel) and calcArea() that calculate the circumference and area of a circle respectively, a member function setRadiusOto set the radius of the circle, a member function getRadius() to return the radius, and a member function showData() that displays the circle's radius, circumference, and area. The formula for the area of a circle is A-ar?. The formula for the circumference of a circle is C-2ar. Use your class in a program that creates an instance of a Circle (utilizing the zero-argument constructor), prompts a user for a radius, calls the şetRadius() function to set the circle's radius, and then calls showData() to display the circle's radius, circumference, and area. Your program should allow the user to enter circle dimensions until the user enters -1. Be sure to include appropriate error checking. Does it make sense to enter "abc" as the radius of a circle? No. Therefore, you should ensure that the user enters numeric data for the radius. Negative numbers (other than the -1 to exit) should also be prevented. showData() should not refer to the data members directly. Instead, it should call getRadius() to retrieve its value. Think of your getters and setters as middlemen. You should try to avoid accessing your data members directly due to maintenance issues. Pretend that you decided to change the name of your radius variable to be "rad". You really should only have to make that change in two functions: getRadius and setRadius. If you refer to the private data members directly throughout your code, you'll have a nightmare trying to make all the changes necessary. If you always use the getters to retrieve your data, any changes you make to the variable name will only necessitate changes to your get function rather than your whole code base. CalcCircumference. CalcArea, and ShowData should not have the radius passed in as an argument because radius is a data member of the class. Class functions have direct access to all data members in their own class. By passing in an argument for the value of the radius, you're not using the value that has already been stored in the data member. You're using the value that you've passed in to the functions, which circumvents the whole purpose of storing radius in the class. Be sure to avoid using global variables in your program unless they are constants. (Hint: a good constant to create in your program would be the value of pi.)

EBK JAVA PROGRAMMING
9th Edition
ISBN:9781337671385
Author:FARRELL
Publisher:FARRELL
Chapter11: Advanced Inheritance Concepts
Section: Chapter Questions
Problem 3PE
icon
Related questions
Question

Can I pleae get help writing this in C++

Construct a class named Circle that has a floating-point data member named radius. The class
should have a zero-argument constructor that initializes this data member to 0. It should have
member functions named calcCircumterencel) and calcArea() that calculate the circumference
and area of a circle respectively, a member function setRadius(to set the radius of the circle, a
member function getRadius() to return the radius, and a member function showData() that
displays the circle's radius, circumference, and area. The formula for the area of a circle is
A-ar?. The formula for the circumference of a circle is C=2ar. Use your class in a program that
creates an instance of a Circle (utilizing the zero-argument constructor), prompts a user for a
radius, calls the şetRadius() function to set the circle's radius, and then calls showData() to
display the circle's radius, circumference, and area. Your program should allow the user to enter
circle dimensions until the user enters -1. Be sure to include appropriate error checking. Does it
make sense to enter "abc" as the radius of a circle? No. Therefore, you should ensure that the
user enters numeric data for the radius. Negative numbers (other than the -1 to exit) should also
be prevented.
showData() should not refer to the data members directly. Instead, it should call
getRadius() to retrieve its value. Think of your getters and setters as middlemen. You
should try to avoid accessing your data members directly due to maintenance issues.
Pretend that you decided to change the name of your radius variable to be "rad". You
really should only have to make that change in two functions: getRadius and setRadius.
If you refer to the private data members directly throughout your code, you'll have a
nightmare trying to make all the changes necessary. If you always use the getters to
retrieve your data, any changes you make to the variable name will only necessitate
changes to your get function rather than your whole code base.
CalcCircumference. CalcArea, and ShowData should not have the radius passed in as an
argument because radius is a data member of the class. Class functions have direct
access to all data members in their own class. By passing in an argument for the value of
the radius, you're not using the value that has already been stored in the data member.
You're using the value that you've passed in to the functions, which circumvents the
whole purpose of storing radius in the class. Be sure to avoid using global variables in
your program unless they are constants. (Hint: a good constant to create in your program
would be the value of pi.)
• Finally, be sure not to include any unnecessary libraries.
Transcribed Image Text:Construct a class named Circle that has a floating-point data member named radius. The class should have a zero-argument constructor that initializes this data member to 0. It should have member functions named calcCircumterencel) and calcArea() that calculate the circumference and area of a circle respectively, a member function setRadius(to set the radius of the circle, a member function getRadius() to return the radius, and a member function showData() that displays the circle's radius, circumference, and area. The formula for the area of a circle is A-ar?. The formula for the circumference of a circle is C=2ar. Use your class in a program that creates an instance of a Circle (utilizing the zero-argument constructor), prompts a user for a radius, calls the şetRadius() function to set the circle's radius, and then calls showData() to display the circle's radius, circumference, and area. Your program should allow the user to enter circle dimensions until the user enters -1. Be sure to include appropriate error checking. Does it make sense to enter "abc" as the radius of a circle? No. Therefore, you should ensure that the user enters numeric data for the radius. Negative numbers (other than the -1 to exit) should also be prevented. showData() should not refer to the data members directly. Instead, it should call getRadius() to retrieve its value. Think of your getters and setters as middlemen. You should try to avoid accessing your data members directly due to maintenance issues. Pretend that you decided to change the name of your radius variable to be "rad". You really should only have to make that change in two functions: getRadius and setRadius. If you refer to the private data members directly throughout your code, you'll have a nightmare trying to make all the changes necessary. If you always use the getters to retrieve your data, any changes you make to the variable name will only necessitate changes to your get function rather than your whole code base. CalcCircumference. CalcArea, and ShowData should not have the radius passed in as an argument because radius is a data member of the class. Class functions have direct access to all data members in their own class. By passing in an argument for the value of the radius, you're not using the value that has already been stored in the data member. You're using the value that you've passed in to the functions, which circumvents the whole purpose of storing radius in the class. Be sure to avoid using global variables in your program unless they are constants. (Hint: a good constant to create in your program would be the value of pi.) • Finally, be sure not to include any unnecessary libraries.
AutoSave O Off
Document1
Word
P Search (Alt+Q)
Steven Brightwel
SB
File
Home
Insert
Draw
Design
Layout
References
Mailings
Review
View
Help
PDFelement
A Share
P Comments
Compiles and Executes without crashing
No global variables
Appropriate Internal Documentation
Rectangle Class Created:
Çircle.h (header file)
Circle.cpp (class file)
CircleDriver.cpp (Driver file)
Data members:
Appropriate data members are declared
Style:
Appropriate Pre-processing and using directives
Constructor:
Zero argument constructor initializes data member to zero
Member functions are correct and used correctly:
calcCircumference()
calcArea()
setRadius()
getRadius()
showData()
Protection:
Member functions and variables are declared with appropriate
protection (i.e. private or public)
Object Creation:
Page 2 of 3
D Focus
540 words
English (United States)
100%
Transcribed Image Text:AutoSave O Off Document1 Word P Search (Alt+Q) Steven Brightwel SB File Home Insert Draw Design Layout References Mailings Review View Help PDFelement A Share P Comments Compiles and Executes without crashing No global variables Appropriate Internal Documentation Rectangle Class Created: Çircle.h (header file) Circle.cpp (class file) CircleDriver.cpp (Driver file) Data members: Appropriate data members are declared Style: Appropriate Pre-processing and using directives Constructor: Zero argument constructor initializes data member to zero Member functions are correct and used correctly: calcCircumference() calcArea() setRadius() getRadius() showData() Protection: Member functions and variables are declared with appropriate protection (i.e. private or public) Object Creation: Page 2 of 3 D Focus 540 words English (United States) 100%
Expert Solution
trending now

Trending now

This is a popular solution!

steps

Step by step

Solved in 4 steps with 1 images

Blurred answer
Knowledge Booster
Algebraic Expressions
Learn more about
Need a deep-dive on the concept behind this application? Look no further. Learn more about this topic, computer-science and related others by exploring similar questions and additional content below.
Similar questions
  • SEE MORE QUESTIONS
Recommended textbooks for you
EBK JAVA PROGRAMMING
EBK JAVA PROGRAMMING
Computer Science
ISBN:
9781337671385
Author:
FARRELL
Publisher:
CENGAGE LEARNING - CONSIGNMENT