Write a C++ program to implement a class called Borewell that has member variables for radius of the well. Include member function outside the class to calculate the borewell area and circumference.Create object and call the member function and print the results.Sample Input3Sample Output28.2618.84
Question
Write a C++ program to implement a class called Borewell that has member variables for radius of the well. Include member function outside the class to calculate the borewell area and circumference.Create object and call the member function and print the results.Sample Input3Sample Output28.2618.84
Solution
Sure, here is a simple C++ program that implements a class called Borewell. This program calculates the area and circumference of the borewell based on the radius provided.
#include<iostream>
#include<cmath>
#define PI 3.14159
using namespace std;
class Borewell {
public:
float radius;
Borewell(float r) {
radius = r;
}
float calculateArea();
float calculateCircumference();
};
float Borewell::calculateArea() {
return PI * pow(radius, 2);
}
float Borewell::calculateCircumference() {
return 2 * PI * radius;
}
int main() {
float radius;
cout << "Enter the radius of the borewell: ";
cin >> radius;
Borewell b(radius);
cout << "Area of the borewell: " << b.calculateArea() << endl;
cout << "Circumference of the borewell: " << b.calculateCircumference() << endl;
return 0;
}
In this program, we first define a class Borewell with a member variable radius. We also declare two member functions calculateArea() and calculateCircumference().
In the main() function, we ask the user to input the radius of the borewell. We then create an object b of the class Borewell with the input radius. We call the member functions calculateArea() and calculateCircumference() on the object b and print the results.
Similar Questions
ClassCreate a class named Circle. This class will represent a circle and hold its properties and functionalities.In the class Circle, create a double-type variable named radius to represent the circle's radius.Create a method named setRadius that takes a double parameter representing the radius value and assigns it to the radius member variable.Create a method named calculateArea that takes no arguments and returns a double value.Inside the calculateArea method, use the formula area = Math.PI * radius * radius to calculate the area based on the stored radius value.
Write a C++ program to create a class called Garden with :A default constructor to read the length and breadtha method called Area() that will calculate the area of a rectangular garden. Create a subclass called Pond that overrides the Area() method to calculate the area of the circular pond .Also define a default constructor that will read the radius of the pond.Sample Input233Sample OutputLength of garden:2Breadth of garden:3Radius of pond:3Area of garden:6Area of pond:28.26
Main MethodCreate a main method in the same class:This method will be the entry point for your program and allow user interaction.Inside the main method:Create a Scanner object to read user input.Prompt the user to enter the circle's radius using System.out.print.Use the Scanner object's nextDouble method to read the user-entered radius and store it in a variable.Create a Circle object.Call the setRadius method of the Circle object, passing the user-entered radius as an argument.Call the calculateArea method of the Circle object and store the returned area value in a variable.Print the calculated area to the console using System.out.printlnSubmit the following: Screenshot of source code and output, and Java source code file.
Implement the abstract class Shape with the abstract method calculateArea.Create the derived classes Circle and Rectangle that extend Shape and implement the calculateArea method according to the formulas for each shapeWrite a main program that reads inputs for creating a circle and a rectangle, calculates their areas, and prints the results.Input2 //number of objectsC 10 //Circle with radousR 10 10 //Rectangle with width and height....Output2 lines display the respective area and circumference314.0 62.8100 40Input3C 100R 5 5R 10 10oUTPUT31400.0 62825 20100 40uSE iNHERITANCE WITH ABSTRACT CLASS SHAPE// Find area and Find circumference must be abstract methods Circle and Rectangle should be sub classes
Create a 2 separate Classes CIRCLE with private data members - Radius and Area, and RECTANGLE with private data members - Length, Breadth and Area. In each of these classes declare and define the member methods putData() [ To display Area ] and computeArea()[ To Compute Area ] are the private and getData() as public member method to read Radius or Length and Breadth based on the choice('C' or 'R'). As a programmer, Write a java program and subsequent pseudocode, to find the area of circle/rectangle using class CIRCLE/RECTANGLE which have following details:getData() to read either radius or lenght and breadth based on the choice 'C' or 'R'Calculate the area using computeArea()Display the Area using putData().Note :Radius is always +Ve, otherwise print "Invalid Radius"Length and Breadth are +Ve, otherwise print "Invalid Length(if Length is -VE) or Invalid Breadth(if Breadth is -VE) or "Invalid Length and Breadth"Input : First line Read the type ('C' or 'R')Second line onwards read Radius(if Type = 'C') or Length and Breadth (if Type = 'R')Output : print Area
Upgrade your grade with Knowee
Get personalized homework help. Review tough concepts in more detail, or go deeper into your topic by exploring other relevant questions.