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]
4 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]4 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
Which of the following is NOT associated with Urban Sprawl?
pochemuha

The option that is not associated with the given term called urban sprawl is; Option A: Blocking high views

What is Urban Sprawl?

Urban sprawl is defined as the rapid expansion of the geographic boundaries of towns and cities which is often accompanied by low-density residential housing and increased reliance on the private automobilefor movement.

Looking at the given options, "blocking high views" is the option that is not typically a problem associated with urban sprawl because urbanization usually takes place on relatively flat levels.

The missing options are;

a. blocking high views

b. destroying animal habitats

c. overrunning farmland

d. reducing green space

Read more about urban sprawl at; brainly.com/question/504389

8 0
2 years ago
Technician A says that a radio may be able to receive AM signals, but not FM signals if the antenna is defective. Technician B s
DIA [1.3K]

The response to whether the statements made by both technicians are correct is that;

D: Neither Technician A nor Technician B are correct.

<h3>Radio Antennas</h3>

In radios, antennas are the means by which signals to the sought frequency be it AM or FM are received.

Now, if the antenna is bad, it means it cannot pick any radio frequency at all and so Technician A is wrong.

Now, most commercial antennas usually come around a resistance of 60 ohms and so it is not required for a good antenna to have as much as 500 ohms resistance and so Technician B is wrong.

Read more about Antennas at; brainly.com/question/25789224

3 0
2 years ago
Typically each development platform consists of the following components, except:Select one:a.Operating systemb.System softwarec
damaskus [11]

Typically each development platform consists of the following components except compilers and assemblers

  • The platform development simply means the development of the fundamental software which is vital in making hardware work.

  • Operating system: This refers to the low-level software that communicates with the hardware so that other programs can be able to run.

  • System software: This is the software that's designed in order to provide a platform for the other software. Examples include search engines, Microsoft Windows, etc.

  • Compilers and assemblers: Compliers are sued in converting source code to a machine-level language. Assembler is used in converting assembly code to machine code.

  • Hardware platform: This is a set of hardware where the software applications are run.

In conclusion, the correct option is Compilers and assemblers.

Read related link on:

brainly.com/question/21650058

4 0
3 years ago
State two disadvantages and two advantages of a simple manometer.<br>​
Savatey [412]
Advantages include;

1. Easy to fabricate and relatively inexpensive.
2. Good accuracy.


Disadvantages include;
1. It is large in size and bulky.
2. It needs leveling.
3 0
3 years ago
Question 5 Value of the impulse function at t - O is defined as​
Lady_Fox [76]
The problem of the Graduation date about the cover was that we had a new name on the back of the earth lol but
4 0
3 years ago
Other questions:
  • With thermodynamics, one cannot determine ________.
    14·1 answer
  • Please perform 100 searches on Twitter using keyword "Lebron". Please print out the the number of tweets returned that were in E
    9·1 answer
  • Transmission cleaners are used: A) Only in conjunction with fuel system cleanersB) Only in the colder monthsC) By themselvesD) I
    13·2 answers
  • When you first start a car after it has been sitting for more than an hour, it pollutes up to ......times more than when the eng
    7·2 answers
  • We know that passengers can be either helpful or harmful to a driver. Describe a pro and a con of having passengers in your car.
    9·2 answers
  • The value of universal gas constant is same for all gases?<br> a) yes<br> b)No
    15·1 answer
  • A glass plate is subjected to a tensile stress of 40 MPa. If the specific surface energy is 0.3 J/m2 and the modulus of elastici
    11·1 answer
  • QUESTION 6
    10·1 answer
  • Why data structure is important
    5·1 answer
  • How much does it cost to repair a broken train? (Fill in the blanks)
    9·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!