Task 1: 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....


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()andGet()methods for each of the data members.

  4. A function to display the data members of the class.

  5. A functionenlargeCirlce(int); which increases the radius of the circle by the factor passed as input to the For example, if “c” is an object of classCircle, the statementc.enlargeCircle(2);should double the radius of the circle.

  6. A functionmoveHorizontal(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 fuctionmoveVertical(int);similar to themoveHorizontal(int);function.


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



Code:


#include
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=""><><" is=""><><" and="" circumference="" of="" circle="" is=""><><>
    }
};

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;
}

Jun 08, 2022
SOLUTION.PDF

Get Answer To This Question

Related Questions & Answers

More Questions »

Submit New Assignment

Copy and Paste Your Assignment Here