#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;
// printing area of circle
cout<<"Area of circle is:
"<<(myCircle.getArea())<<endl;
return 0;
}
1. Write a statement that defines an array of five objects of the Circle class in the above statement. Let the default constructor execute for each element of the array.
Please find the required code below.
Cricle myCircles[5];
This statement will create an array of five objects of Circle class. And, by default, the default constructor is called for each of the Circle object.
#include <iostream> using namespace std; class Circle{ // private member variable named radius private: double radius;...
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...
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...
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...
Keep getting this error message when trying to compile in main1.cpp. Need help figuring out how to make it compile. Thank you for your time. Error Message: main.cpp:(.text+0x13): undefined reference to `circle::circle()' main.cpp:(.text+0x32): undefined reference to `circle::circle(double)' main.cpp:(.text+0x3e): undefined reference to `circle::getArea() const' main.cpp:(.text+0x53): undefined reference to `circle::getRadius() const' main.cpp:(.text+0xb3): undefined reference to `circle::getArea() const' main.cpp:(.text+0xc8): undefined reference to `circle::getRadius() const' main.cpp:(.text+0x157): undefined reference to `circle::setRadius(double)' main.cpp:(.text+0x163): undefined reference to `circle::getArea() const' main.cpp:(.text+0x178): undefined reference to `circle::getRadius() const' main.cpp:(.text+0x207): undefined...
C++ 8. Circle Class 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 accessor function for the radius variable. • getArea. Returns the area...
Please add //comments to the header file below. #ifndef CIRCLE_H_INCLUDED #define CIRCLE_H_INCLUDED #include <iostream> using namespace std; class Circle { private: double radius; // declaration of public methods in header file public: Circle() { // default value radius = 1; } void input() { cout << "Enter radius: "; cin >> radius; } void print() { double PI = 3.14159; double area = PI * radius * radius; double circumference = 2 * PI * radius; cout << "Circle with...
Pure Abstract Base Class Project. Define a class called BasicShape which will be a pure abstract class. The class will have one protected data member that will be a double called area. It will provide a function called getArea which should return the value of the data member area. It will also provide a function called calcArea which must be a pure virtual function. Define a class called Circle. It should be a derived class of the BasicShape class. This...
// This program uses the programmer-defined Rectangle class. #include "Rectangle.cpp" #include <iostream> using namespace std; int main() { Rectangle rectangle1; Rectangle rectangle2; rectangle1.setLength(10.0); rectangle1.setWidth(5.0); rectangle2.setLength(7.0); rectangle2.setWidth(3.0); cout << "Perimeter of rectangle1 is " << rectangle1.calculatePerimeter() << endl; cout << "Area of rectangle1 is " << rectangle1.calculateArea() << endl; cout << "Perimeter of rectangle2 is " << rectangle2.calculatePerimeter() << endl; cout << "Area of rectangle2 is " << rectangle2.calculateArea() << endl;...
C++ Class and Operator Overloading part 1 The source file contains a C++ program that declares and initializes an array of Circles. The program is using a for loop statement to find the largest circle in the array and display it on the output screen. However, the program is currently not working. The problem is the program uses logical operator ' > ' for comparison of circles and it is not working unless we overload such operator for the class...
C++ problem 11-3 Chapter 10 defined the class circleType to implement the basic properties of a circle. (Add the function print to this class to output the radius, area, and circumference of a circle.) Now every cylinder has a base and height, where the base is a circle. Design a class cylinderType that can capture the properties of a cylinder and perform the usual operations on the cylinder. Derive this class from the class circleType designed in Chapter 10. Some...