Question

Hello! This is C++. Q3. Write a program Define a Super class named Point containing: An...

Hello! This is C++.

Q3. Write a program

Define a Super class named Point containing:

An instance variable named x of type int.

An instance variable named y of type int.

Declare a method named toString() Returns a string representation of the point.

Constructor that accepts values of all data members as arguments.

Define a Sub class named Circle. A Circle object stores a radius (double) and inherit the (x, y) coordinates of its center from its super class Point. Each Circle object should have the following public methods:

Circle(x, y, radius)
Constructs a new circle with a center specified by the given coordinators x,y and with the given double radius.

getArea()
Returns the area occupied by the circle, using the formula ?r2.

getCircumference()
Returns the circle's circumference (distance around the circle), using the formula 2?r.

toString()
Returns a string representation of the circle, such as "Circle[center=(75, 20); radius=30]".

Write an application class where you construct objects from subclass and print the result on the screen.

0 0
Add a comment Improve this question Transcribed image text
Answer #1

#include <bits/stdc++.h>
using namespace std;
double pi=3.14159265358979323846;
class Point
{
public:
int x,y;
Point(int a,int b)
{
x=a;
y=b;
}
  
string toString()
{
string temp="Point[x=" + to_string(x)+",y="+to_string(y)+"]";
return temp;
}
  
};

class Circle: public Point
{
public:
double radius;
Circle(int a, int b, double Radius) : Point(a,b)
{
radius=Radius;
}
double getArea()
{
return pi*radius*radius;
}
double getPerimeter()
{
return 2*pi*radius;
}
string toString()
{
string temp="Circle[center=(" + to_string(x)+","+to_string(y)+"); radius="+to_string(radius)+"]";
return temp;
}
};
int main(void)
{
Point p(3,4);
cout<<p.toString()<<endl;
Circle c(3,4,5);
cout<<c.getArea()<<endl;
cout<<c.getPerimeter()<<endl;
cout<<c.toString()<<endl;
return 0;
}

Add a comment
Know the answer?
Add Answer to:
Hello! This is C++. Q3. Write a program Define a Super class named Point containing: An...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • Question 11 (20 points) Given the class Point below, define a class Circle that represent a...

    Question 11 (20 points) Given the class Point below, define a class Circle that represent a circle with a given center and radius. The circle class should have a center attribute named center as well as a floating point radius attribute. The center is a point object, defined by the class Point. The class should also have these members: the constructor of the class, which should take parameters to initialize all attributes - a getter for center a setter for...

  • Using separate files, write the definition for a class called Point and a class called Circle. Th...

    Using separate files, write the definition for a class called Point and a class called Circle. The class point has the data members x (double) and y (double) for the x and y coordinates. The class has the following member functions: a) void set_x(double) to set the x data member b) void set_y(double) to set the y data member c) double get_x() to return the the x data member d) double get_y() to return the the y data member e)...

  • Design and implement class Circle to represent a circle object. The class defines the following attributes...

    Design and implement class Circle to represent a circle object. The class defines the following attributes (variables) and methods: 1.      A private variable of type double named radius to represent the radius. Set to 1. 2.      Constructor Methods: •        Python : An overloaded constructor method to create a default circle. •        C# & Java: Default Constructor with no arguments. •        C# & Java: Constructor method that creates a circle with user-specified radius. 3.      Method getRadius() that returns the radius. 4.     ...

  • Write an ADT named circle in java containing the following. Include data: radius (double) Include methods:...

    Write an ADT named circle in java containing the following. Include data: radius (double) Include methods: A no-argument constructor A constructor that sets the data to passed values Getters and setters for each piece of data getArea (Math.PI * radius * radius … try using a Math method here) getDiameter (radius * 2) getCircumference (2 * Math.PI * radius) A toString( ) method to display the object data Include Javadoc comments for the class and every method, and generate the...

  • A general shape class is shown below. Shape has a dimension. It also defines constructors, getters,...

    A general shape class is shown below. Shape has a dimension. It also defines constructors, getters, setters and a toString method. class Shape{ int dimension; public Shape(){} public Shape(int newDimension){ dimension = newDimension; } public int getDimension(){ return dimension; } public void setDimension(int newDimension){ dimension = newDimension; } public String toString(){ return "Shape has dimension "+dimension; } } a. Define classes Circle and Square, which inherit from Shape class. b. Both classes must have two constructors similar to Shape class....

  • Create a class Circle with one instance variable of type double called radius. Then define an...

    Create a class Circle with one instance variable of type double called radius. Then define an appropriate constructor that takes an initial value for the radius, get and set methods for the radius, and methods getArea and getPerimeter. Create a class RightTriangle with three instance variables of type double called base, height, and hypotenuse. Then define an appropriate constructor that takes initial values for the base and height and calculates the hypotenuse, a single set method which takes new values...

  • U8ing separate files, write th definition for a clas called Poit and a class called Cirele...

    U8ing separate files, write th definition for a clas called Poit and a class called Cirele 1. The class point has the data members (double) and y (double) for the x and y coordinates The class has the following ember functions a) void set x (double) to set the x data member b) void set y(double) to set the y data member c) double get-x() to return th the data member d) double get yO to zeturn the the y...

  • Complete the following coding in java Create a class Circle that represents a round moving dot....

    Complete the following coding in java Create a class Circle that represents a round moving dot. A circle object needs to contain double variables to store the: Current X location of the circle's center Current Y location of the circle's center Radius of the circle Direction of the circle's movement in radians Speed of the circle's movement . . The Circle class must contain a constructor Circle double x, double y, double radius) that initializes the circles center x, y...

  • Java code for the following inheritance hierarchy figure.. 1. Create class Point, with two private instance...

    Java code for the following inheritance hierarchy figure.. 1. Create class Point, with two private instance variables x and y that represented for the coordinates for a point. Provide constructor for initialising two instance variables. Provide set and get methods for each instance variable, Provide toString method to return formatted string for a point coordinates. 2. Create class Circle, its inheritance from Point. Provide a integer private radius instance variable. Provide constructor to initialise the center coordinates and radius for...

  • please write in Java and include the two classes Design a class named Fan (Fan.java) to...

    please write in Java and include the two classes Design a class named Fan (Fan.java) to represent a fan. The class contains: An int field named speed that specifies the speed of the fan. A boolean field named fanStatus that specifies whether the fan is on (default false). A double field named radius that specifies the radius of the fan (default 5). A string field named color that specifies the color of the fan (default blue). A no-arg (default) constructor...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT