Extend the “Circle” class to have the following features. Two additional data members (integers) to store the x and y coordinate of the center of the Circle. A parameterized constructor. Set() and Get() methods for each of the data members. A function to display the data members of the class. A function enlargeCirlce(int); which increases the radius of the circle by the factor passed as input to the For example, if “c” is an object of class Circle, the statement c.enlargeCircle(2); should double the radius of the circle. A function moveHorizontal(int); which should move the center of the circle in the horizontal direction. For example, if “c” is a circle with center at (5,10), moveHorizontal(3); should move the center to position (8,10). A fuction moveVertical(int); similar to the moveHorizontal(int); function.

C++ Programming: From Problem Analysis to Program Design
8th Edition
ISBN:9781337102087
Author:D. S. Malik
Publisher:D. S. Malik
Chapter11: Inheritance And Composition
Section: Chapter Questions
Problem 5PE: Using classes, design an online address book to keep track of the names, addresses, phone numbers,...
icon
Related questions
Question

Task 1:

Extend the “Circle” class to have the following features.

  1. Two additional data members (integers) to store the x and y coordinate of the center of the Circle.
  2. A parameterized constructor.
  3. Set() and Get() methods for each of the data members.
  4. A function to display the data members of the class.
  5. A function enlargeCirlce(int); which increases the radius of the circle by the factor passed as input to the For example, if “c” is an object of class Circle, the statement c.enlargeCircle(2); should double the radius of the circle.
  6. A function moveHorizontal(int); which should move the center of the circle in the horizontal direction. For example, if “c” is a circle with center at (5,10), moveHorizontal(3); should move the center to position (8,10).
  7. A fuction moveVertical(int); similar to the moveHorizontal(int); function.

In the main program, create two objects of class Circle. Find which of the two circles is smaller (by comparing their radii) and enlarge the smaller circle by a factor of 2.

Code:

#include<iostream>
using namespace std;
  

//Class which holds properties and methods of a class
class Circle {
private:
    int radius;
public:

    //Parameterized constructor that creates an object
    Circle(int r=0)  {radius=r;}
      

    //Member function to find area
    int area(){
        return 22*radius*radius/7;
    }
    

    //Member function to find circumference
    int circumference(){
        return 2*22*radius/7;
    }
    

    //Member function to print results
    void print(int ar, int cf)
    {
        cout<<"Area of circle with radius "<<radius<<" is "<<ar<<" and circumference of circle is "<<cf<<endl;
    }
};
  
int main()
{
    Circle c1(49),c2(61);     //Creating two objects of class circle
    
    int ar1=c1.area();
    int cf1=c1.circumference();
    c1.print(ar1,cf1);
    
    int ar2=c2.area();
    int cf2=c2.circumference();
    c2.print(ar2,cf2);
    
    return 0;
}

Expert Solution
steps

Step by step

Solved in 2 steps

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
C++ Programming: From Problem Analysis to Program…
C++ Programming: From Problem Analysis to Program…
Computer Science
ISBN:
9781337102087
Author:
D. S. Malik
Publisher:
Cengage Learning