Note- can you rewrite the code in C++ if there is any existing code. Can you not use arrow -> operator.
Write a circle class that has the following member variables:
• radius: a double
• pi: a double initialized with the value 3.14159
The class should have the following member functions:
• Default Constructor. A default constructor that sets radius to 0.0.
• Constructor. Accepts the radius of the circle as an argument .
• setRadius. A mutator function for the radius variable.
• getRadius. An acccssor function for the radius variable
. • getArea. Returns the area of the circle, which is calculated as area = pi * radius * radius
• getDiameter. Returns the diameter of the circle, which is calculated as diameter = radius * 2
• getcircumforence. Returns the circumference of the circle, which is calculated as circumference = 2 * pi * radius
Write a program that demonstrates the circle class by asking the user for the circle's radius, creating a circle object, and then reporting the circle's area, diameter, and circumference.
CPP program :
//These are header files
#include <iostream>
using namespace std;
//CPP class
class circle{
//member variables
double radius;
double pi=3.14159;
public:
//Default Constructor
circle()
{
//A default constructor that sets radius to 0.0.
radius=0.0;
}
//Constructor. Accepts the radius of the circle as an argument
.
circle(double r)
{
radius=r;
}
//setRadius. A mutator function for the radius variable.
void setRadius(double r)
{
radius=r;
}
//getRadius. An acccssor function for the radius variable
double getRadius()
{
return radius;
}
//getArea. Returns the area of the circle, which is calculated as
area = pi * radius * radius
double getArea()
{
return pi*radius*radius;
}
//getDiameter. Returns the diameter of the circle, which is
calculated as diameter = radius * 2
double getDiameter()
{
return radius*2;
}
// getcircumforence. Returns the circumference of the circle, which
is calculated as circumference = 2 * pi * radius
double getcircumforence()
{
return 2*pi*radius;
}
};
//main() method
int main()
{
//This variable will store radius
double radius;
//This line will ask user radius
cout<<"Enter radius : ";
cin>>radius;//reading radius
//This line will create object of circle class
circle c;
//This line will call method to set the radius
c.setRadius(radius);
//This line will call method and display area of circle
cout<<"Area of circle with radius
"<<c.getRadius()<<" is
"<<c.getArea()<<endl;
//This line will call method and display diameter of circle
cout<<"Diameter of circle with radius
"<<c.getRadius()<<" is
"<<c.getDiameter()<<endl;
//This line will call method and display circumference of
circle
cout<<"Circumference of circle with radius
"<<c.getRadius()<<" is
"<<c.getcircumforence()<<endl;
return 0;
}
======================================
Output :
Note- can you rewrite the code in C++ if there is any existing code. Can you...
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)...
Given the below UML diagram, convert the diagram into working java code. Pay attention to the constructors of the class "Circle". Circle radius: 2 pi Circle() circle (float) getRadius(): float getArea(): float getDiameter(): float 1. The no-argument constructor initiates "pi" to 3.14 2. The one argument constructor initiates variable "radius" to the value of parameter passed 3. getRadius (), returns the radius of the Circle. 4. get Area (), returns the area of the Circle. 5. getDiameter(), returns the diameter...
Write a Java console application that prompts the user to enter the radius of a circle, then prints its radius, diameter, circumference, and area. Write a JavaFX GUI application to do the same calculation, and draw the circle. The Console Output Enter the radius of the circle: 1.2 The radius is 1.2 The diameter is 2.4 The circumference is 7.5398223686155035 The area is 4.523893421169302 Write and document your program per class coding conventions. Add an instance variable double radius. Generate...
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...
Create a class named Circle with fields named radius, diameter, and area. Include a constructor that sets the radius to 1 and calculates the other two values. Also include methods named setRadius() and getRadius(). The setRadius() method not only sets the radius, but it also calculates the other two values. (The diameter of a circle is twice the radius, and the area of a circle is pi multiplied by the square of the radius. Use the Math class PI constant...
#include <iostream> using namespace std; class Circle{ // private member variable named radius private: double radius; // get function for radius public: double getRadius(){ return radius; } // set function for radius void setRadius(double rad){ radius=rad; } // returning area = 3.14159 * radius * radius double getArea(){ return (3.14159 * radius * radius); } }; // Sample run int main() { // Declaring object of Circle Circle myCircle; myCircle.setRadius(5); // printing radius of circle cout<<"Radius of circle is: "<<(myCircle.getRadius())<<endl;...
CODE IN C++Write a class declaration named Circle with a private member variable named radius. Write set and get functions to access the radius variable, and a function named getArea that returns the area of the circle. The area is calculated as 3.14159 * radius * radius. Add a default constructor the Circle class. The constructor should initialize the radius member to 0. Add an overloaded constructor to the Circle class. The constructor should accept an argument and assign radius...
in C++ Write a class declaration named Circle with a private member variable named radius. Write set and get functions to access the radius variable, and a function named getArea that returns the area of the circle. The area is calculated as 3.14159*radius*radius. Add a default constructor to the Circle class. The constructor should initialize the radius member to 0. Add an overloaded constructor to the Circle class. The constructor should accept an argument and assign its value to the radius...
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. ...
C++ Could you check my code, it work but professor said that there are some mistakes(check virtual functions, prin() and others, according assignment) . Assignment: My code: #include<iostream> #include<string> using namespace std; class BasicShape { //Abstract base class protected: double area; private: string name; public: BasicShape(double a, string n) { area=a; name=n; } void virtual calcArea()=0;//Pure Virtual Function virtual void print() { cout<<"Area of "<<getName()<<" is: "<<area<<"\n"; } string getName(){ return name; } }; class Circle : public...