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 member. 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. 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 using namespace std; //Class which holds properties and methods of a class class Circle { private: int radius; int x; int y; public: //Parameterized constructor that creates an object Circle(int r=0, int xc=0, int yc=0) { radius=r; x=xc; y=yc; } //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 "<
Output not showing fix it.
Need output of this code only.
Tasks which i perform already :
- 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 member.
- 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.
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;
int x;
int y;
public:
//Parameterized constructor that creates an object
Circle(int r=0, int xc=0, int yc=0)
{
radius=r;
x=xc;
y=yc;
}
//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;
}
//set methods
void setRadius(int r)
{
radius=r;
}
void setX(int xc)
{
x=xc;
}
void setY(int yc)
{
y=yc;
}
//get methods
int getRadius()
{
return radius;
}
int getX()
{
return x;
}
int getY()
{
return y;
}
void enlargeCircle(int c)
{
radius=c*radius;
}
void moveHorizontal(int c)
{
x=x+c;
}
void moveVertical(int c)
{
y=y+c;
}
//Member function to display data members
void printMembers()
{
cout << "x coordinate: " << x << endl;
cout << "y coordinate: " << y << endl;
cout << "Radius: " << radius << endl;
}
};
int main()
{
Circle c1(49),c2(61); //Creating two objects of class circle
if(c1.getRadius()<c2.getRadius()) //if c1 has smaller radius
c1.enlargeCircle(2); //enlarge it by 2
else if(c2.getRadius()<c1.getRadius()) //if c2 has smaller radius
c2.enlargeCircle(2); //enlarge it by 2
return 0;
}
Step by step
Solved in 3 steps with 1 images