1answer.
Ask question
Login Signup
Ask question
All categories
  • English
  • Mathematics
  • Social Studies
  • Business
  • History
  • Health
  • Geography
  • Biology
  • Physics
  • Chemistry
  • Computers and Technology
  • Arts
  • World Languages
  • Spanish
  • French
  • German
  • Advanced Placement (AP)
  • SAT
  • Medicine
  • Law
  • Engineering
slega [8]
3 years ago
15

Write a program to calculate the area of circle, rectangle using a class. The program would prompt a user to select (1) circle o

r (2) rectangle followed by asking the necessary dimensions. Once the user enters the valid input, the program then calculates the area and prints the final value. The set()/get() methods must include data validation.
Engineering
1 answer:
cricket20 [7]3 years ago
3 0

Answer:

The following program written in c++:

#include <iostream>

using namespace std;

class Circle   //define class

{

private :      //access modifier

double pi, radius, area;    // set double type variables

public :

Circle (double radius = 0.0)    //define constructor

{

pi = 3.1415;

this->radius = radius;

}

void setRadius (double radius)     // define void type method

{

if (radius < 0){      // if the radius is negative don't take it

cout << "Radius can't be negative." << endl;

return;

}

this->radius = radius;

}

double getArea ()        // define double type method

{

area = pi * radius * radius;

return area;

}

};

class Rectangle      //define class

{

private:       //access modifier

double length ,breadth ,area; // set double type private data types

public:

Rectangle (double length = 0.0, double breadth = 0.0) // define constructor

{

this->length = length;

this->breadth = breadth;

}

void setDimension (double length , double breadth ) // define void type method

{

if (length < 0 || breadth < 0){ //set if condition, if the dimensions is negative than don't take it

cout << "Dimensions can't be negative." << endl;

return;

}

this->length = length;

this->breadth = breadth;

}

double getArea ()      // define double type method

{

area = length * breadth;

return area;

}

};

int main()      //main function

{

int choice;      //integer type variable

double radius, length, breadth;

Circle c;

Rectangle r;

cout << "Select ( 1 ) Circle or select ( 2 ) Rectangle : "; // get the choice of user

cin >> choice;

switch (choice)

{

case 1 : cout << "Enter radius of circle : ";

cin >> radius;

c.setRadius(radius);

cout << "Area of circle is : " << c.getArea();

break;

case 2 : cout << "Enter dimensions of rectangle : ";

cin >> length >> breadth;

r.setDimension(length,breadth);

cout << "Area of rectangle is : " << r.getArea();

break;

default : cout << "Invalid Selection...";

}

return 0;

}

Explanation:

Here, we define two classes "Circle" and "Rectangle"

Then, we create first two function which get the value from the user.

Then, we create the second two functions which return the calculation of the following formulas.

You might be interested in
⦁ An ideal Otto cycle has a compression ratio of 8. At the beginning of the compression process, air is at 95 kPa and 27°C, and
Anon25 [30]

Answer:

<u><em>note:</em></u>

<u><em>solution is attached in word form due to error in mathematical equation. furthermore i also attach Screenshot of solution in word due to different version of MS Office please find the attachment</em></u>

Download docx
8 0
4 years ago
Please help me bro come on
melomori [17]
Answer:

12

Explanation:

5 • 3 = 15
3 • 3 = 9
4 • 3 = 12
6 0
3 years ago
Read 2 more answers
g A heat exchanger is designed to is to heat 2,500 kg/h of water from 15 to 80 °C by engine oil. The configuration of the heat e
sergey [27]

Answer:

See explaination

Explanation:

Please kindly check attachment for the step by step solution of the given problem.

The attached file gave a detailed solution of the problem.

8 0
3 years ago
1. There are two categories (shapes) for the Virginia driver's license. The ________________________ shape license represents th
dolphi86 [110]

Answer:

Vertical; horizontal.

Explanation:

The Virginia Department of Motor Vehicles started issuing sets of newly designed driver's licenses to drivers in 2009. Although, the cards that were issued to drivers prior to the introduction of the new cards remained valid until they were expired.

There are two categories (shapes) for the Virginia driver's license. The vertical shape license represents the driver who is under the age of 21, and the horizontal shaped license represents the driver who is over the age of 21.

Additionally, the Virginia's driver license (vertical in shape) issued to drivers who are under the age of 21 has a background image of a dogwood flower while the horizontal shaped license issued to drivers who are over the age of 21 has a background image of the state capitol.

5 0
3 years ago
What is the first thing a person must do before anything can be done today corroded area
melamori03 [73]

Answer:

Explanation:

We have learned that three things are required for the anodic and cathodic steps of corrosion to occur: an electrolyte, an exposed metal surface, and an electron acceptor. It follows, then, that we can prevent corrosion by removing one of these essential conditions.

8 0
2 years ago
Other questions:
  • Tech A says that the brake pedal uses leverage to multiply foot pressure. Tech B says that when braking hard while moving
    13·1 answer
  • Fatigue failure occurs under the condition of (a) High elastic stress (b) High corrosivity (c) High stress fluctuations (d) High
    9·1 answer
  • The design specifications of a 1.2-m long solid circular transmission shaft require that the angle of twist of the shaft not exc
    15·1 answer
  • A 450 MWt combined cycle plant has a Brayton cycle efficiency of 24% and a Rankine cycle efficiency of 29% with no heat augmenta
    6·1 answer
  • the AADT for a section of suburban freeway is 150000 veh/day. Assuming this is an urban radial facility, what range of direction
    7·1 answer
  • You talk with the owner and he likes the idea of using two large glulam beams as shown to carry the joist loads. Design the glul
    5·1 answer
  • Design drawings use line styles of up to eight different varieties to communicate important information about the item. true or
    7·1 answer
  • A college student volunteers with the elderly in a hospice program and discovers her clients complain of dry skin. She has an id
    13·2 answers
  • PLEASE FIX THIS LUA SCRIPT
    12·2 answers
  • How frequently should vehicle registration be renewed?
    6·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!