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
A liquid jet vj of diameter dj strikes a fixed cone and deflects back as a conical sheet at the same velocity. find the cone ang
dmitriy555 [2]

Answer:

lol i cant real it sorry

Explanation:

7 0
2 years ago
Calculate the differential pressure in kPa across the hatch of a submarine 320m below the surface of the sea. Assume the atmosph
kicyunya [14]

Answer:

The pressure difference across hatch of the submarine is 3217.68 kpa.

Explanation:

Gauge pressure is the pressure above the atmospheric pressure. If we consider gauge pressure for finding pressure differential then no need to consider atmospheric pressure as they will cancel out. According to hydrostatic law, pressure varies in the z direction only.  

Given:

Height of the hatch is 320 m

Surface gravity of the sea water is 1.025.

Density of water 1000 kg/m³.

Calculation:

Step1

Density of sea water is calculated as follows:

S.G=\frac{\rho_{sw}}{\rho_{w}}

Here, density of sea water is\rho_{sw}, surface gravity is S.G and density of water is \rho_{w}.

Substitute all the values in the above equation as follows:

S.G=\frac{\rho_{sw}}{\rho_{w}}

1.025=\frac{\rho_{sw}}{1000}

\rho_{sw}=1025 kg/m³.

Step2

Difference in pressure is calculated as follows:

\bigtriangleup p=rho_{sw}gh

\bigtriangleup p=1025\times9.81\times320

\bigtriangleup p=3217680 pa.

Or

\bigtriangleup p=(3217680pa)(\frac{1kpa}{100pa})

\bigtriangleup p=3217.68 kpa.

Thus, the pressure difference across hatch of the submarine is 3217.68 kpa.

6 0
3 years ago
A 35 ft long solid steel rod is subjected to a load of 8,000 lb. This load causes the rod to stretch 0.266 in. The modulus of el
solong [7]

Answer:

53.67

Explanation:

3 0
3 years ago
If you are a mechanical engineer answer these questions:
Natasha_Volkova [10]

Answer:

1. Yes, they are all necessary.

2. Both written and verbal communication skills are of the utmost importance in business, especially in engineering. Communication skills boost you or your teams' performance because they provide clear information and expectations to help manage and deliver excellent work.

3 0
3 years ago
Air enters a diffuser operating at steady state at 540°R, 15 lbf/in.2, with a velocity of 600 ft/s, and exits with a velocity of
yKpoI14uk [10]

Answer: Hello the question is incomplete below is the missing part

Question:  determine the temperature, in °R, at the exit

answer:

T2= 569.62°R

Explanation:

T1 = 540°R

V2 = 600 ft/s

V1 = 60 ft/s

h1 = 129.0613  ( value gotten from Ideal gas property-air table )

<em>first step : calculate the value of h2 using the equation below </em>

assuming no work is done ( potential energy is ignored )

h2 = [ h1 + ( V2^2 - V1^2 ) / 2 ] * 1 / 32.2 * 1 / 778

∴ h2 = 136.17 Btu/Ibm

From Table A-17

we will apply interpolation

attached below is the remaining part of the solution

8 0
3 years ago
Other questions:
  • You find a publication from a research laboratory that identifies a new catalyst for ammonia synthesis. The article contains the
    6·1 answer
  • What is a coarse-grained rock composed of intermediate plagioclase feldspar and pyroxene? a. graniteb. gabbro c. andesited. peri
    9·1 answer
  • Your manager has asked you to research and recommend a writing guide that examiners in your digital forensics company can use fo
    8·1 answer
  • Amplifiers are extensively used in the baseband portion of a radio receiver system to condition the baseband signal to produce a
    5·1 answer
  • After adjusting your seat, your___ should be as closest possible to the back rest.
    14·1 answer
  • In addition to passing an ASE certification test, automotive technicians must have __________ year(s) of on the job training or
    15·1 answer
  • How could increasing the budget for testing have prevented the problem experienced by the mars orbiter?
    7·1 answer
  • which of the following tools is used for measuring small diameter holes which a telescoping gauge cannot fit into? A. telescopin
    13·1 answer
  • How many squares titles (20cm x 20cm) are needed to coat the sides and base of a pool which is 10m long, 6 meter wide and 3m dee
    8·1 answer
  • Select three types of lines that engineers use to help represent the shape of a design in a sketch.
    14·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!