Write a simple class named Circle, with three private variables: doubles named x, y and radius.  The center of the circle is denoted by coordinates (x,y), and the radius of the circle is denoted by radius.  It should have public member functions with the following signatures: void setRadius(double r) void setX(double value) void setY(double value) double getRadius() double getX() double getY() double getArea() bool containsPoint(double xValue, double yValue) The first six member functions are straightforward functions to set and get the private member variables. double getArea() This member function should return the area of the circle.  When you are calculating the area you can use 3.14 for pi.  The formula is radius * radius * pi.   bool containsPoint(double xValue, double yValue) This member function should return true if the point at (xValue, yValue) is contained in the circle, and false if not.  You can determine whether or not a point is in a circle by calculating the distance from the center of the circle (its x and y coordinates) to the point (parameters xValue, yValue).  If this distance is less than or equal to the radius then the point is inside the circle.  For your reference, here is how to calculate distance between two points (Links to an external site.).   For example, let's say we have instantiated a Circle object named myCircle which has x=2.0, y=3.0, and radius=2.0.   myCircle.containsPoint(2.0, 4.0) should return true because (2.0, 4.0) is contained in myCircle.   myCircle.containsPoint(2.0, 10.0) should return false because (2.0, 10.0) is not contained in myCircle. Write a main function that tests your class.  It should instantiate a number of circle objects with different radius values and centers.  You should test all your member functions until you are confident that they work.  At minimum, make sure you try each of the following and provide sample output for each of the below test cases: Create a local circle object and set its x, y, and radius. Verify that its area is calculated correctly. Create a circle pointer, and point it at your local circle object.  Use this pointer to set its x, y, and radius values to new values. Using your pointer, verify that your containsPoint() function works by trying a point which is in fact in your circle, and showing it returns true.  Also, try a different point which is not in your circle and show it returns false. Implement the Circle class in separate .h and .cpp files.  Circle.h contains your class declaration and Circle.cpp contains your class implementation, i.e. the member function implementations.  Don't forget the #ifndef and #define preprocessor directives as necessary.  Put your main program into a separate file as well called main.cpp, and put your sample output at the end of main.cpp. To summarize, at the end of the assignment you should have three files with the following names: Circle.h Circle.cpp main.cpp

Database System Concepts
7th Edition
ISBN:9780078022159
Author:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Chapter1: Introduction
Section: Chapter Questions
Problem 1PE
icon
Related questions
Question

USING C++

 

Write a simple class named Circle, with three private variables: doubles named x, y and radius.  The center of the circle is denoted by coordinates (x,y), and the radius of the circle is denoted by radius.  It should have public member functions with the following signatures:

void setRadius(double r)
void setX(double value)
void setY(double value)
double getRadius()
double getX()
double getY()
double getArea()
bool containsPoint(double xValue, double yValue)

The first six member functions are straightforward functions to set and get the private member variables.

double getArea()

This member function should return the area of the circle.  When you are calculating the area you can use 3.14 for pi.  The formula is radius * radius * pi.  

bool containsPoint(double xValue, double yValue)

This member function should return true if the point at (xValue, yValue) is contained in the circle, and false if not.  You can determine whether or not a point is in a circle by calculating the distance from the center of the circle (its x and y coordinates) to the point (parameters xValue, yValue).  If this distance is less than or equal to the radius then the point is inside the circle.  For your reference, here is how to calculate distance between two points (Links to an external site.).  

For example, let's say we have instantiated a Circle object named myCircle which has x=2.0, y=3.0, and radius=2.0.  

  • myCircle.containsPoint(2.0, 4.0) should return true because (2.0, 4.0) is contained in myCircle.  
  • myCircle.containsPoint(2.0, 10.0) should return false because (2.0, 10.0) is not contained in myCircle.

Write a main function that tests your class.  It should instantiate a number of circle objects with different radius values and centers.  You should test all your member functions until you are confident that they work.  At minimum, make sure you try each of the following and provide sample output for each of the below test cases:

  • Create a local circle object and set its x, y, and radius. Verify that its area is calculated correctly.
  • Create a circle pointer, and point it at your local circle object.  Use this pointer to set its x, y, and radius values to new values.
  • Using your pointer, verify that your containsPoint() function works by trying a point which is in fact in your circle, and showing it returns true.  Also, try a different point which is not in your circle and show it returns false.

Implement the Circle class in separate .h and .cpp files.  Circle.h contains your class declaration and Circle.cpp contains your class implementation, i.e. the member function implementations.  Don't forget the #ifndef and #define preprocessor directives as necessary.  Put your main program into a separate file as well called main.cpp, and put your sample output at the end of main.cpp.

To summarize, at the end of the assignment you should have three files with the following names:

  • Circle.h
  • Circle.cpp
  • main.cpp
Expert Solution
trending now

Trending now

This is a popular solution!

steps

Step by step

Solved in 2 steps with 2 images

Blurred answer
Knowledge Booster
Class
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
Database System Concepts
Database System Concepts
Computer Science
ISBN:
9780078022159
Author:
Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:
McGraw-Hill Education
Starting Out with Python (4th Edition)
Starting Out with Python (4th Edition)
Computer Science
ISBN:
9780134444321
Author:
Tony Gaddis
Publisher:
PEARSON
Digital Fundamentals (11th Edition)
Digital Fundamentals (11th Edition)
Computer Science
ISBN:
9780132737968
Author:
Thomas L. Floyd
Publisher:
PEARSON
C How to Program (8th Edition)
C How to Program (8th Edition)
Computer Science
ISBN:
9780133976892
Author:
Paul J. Deitel, Harvey Deitel
Publisher:
PEARSON
Database Systems: Design, Implementation, & Manag…
Database Systems: Design, Implementation, & Manag…
Computer Science
ISBN:
9781337627900
Author:
Carlos Coronel, Steven Morris
Publisher:
Cengage Learning
Programmable Logic Controllers
Programmable Logic Controllers
Computer Science
ISBN:
9780073373843
Author:
Frank D. Petruzella
Publisher:
McGraw-Hill Education