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
Consider two different versions of algorithm for finding gcd of two numbers (as given below), Estimate how many times faster it
juin [17]

Answer:

Explanation:

Step 1:

a) The formula for compute greatest advisor is

     gcd(m,n) = gcd (n,m mod n)

the gcd(31415,14142) by applying Euclid's algorithm is

    gcd(31,415,14,142) =gcd(14,142,3,131)

                                  =gcd=(3,131, 1,618)

                                   =gcd(1,618, 1,513)

                                   =gcd(1,513, 105)

                                   =gcd(105, 43)

                                    =gcd(43, 19)

                                     =gcd(19, 5)

                                      =gcd(5, 4)

                                      =gcd(4, 1)

                                      =gcd(1, 0)

                                      =1

STEP 2

b)  The number of comparison of given input with the algorithm based on  checking consecutive integers and Euclid's algorithm is

     The number of division using Euclid's algorithm =10 from part (a)

      The consecutive integer checking algorithm:

      The number of iterations =14,142 and 1 or 2 division of iteration.

        14,142 ∠= number of division∠ = 2*14,142

         Euclid's algorithm is faster by at least 14,142/10 =1400 times

          At most 2*14,142/10 =2800 times.

5 0
3 years ago
MODIFIED-BOTTOM-UP-CUT-ROD(p, n, c) to return not only the value but the actual solution, too. Hint: It is similar to how array
Vaselesa [24]

Answer:

b.

Matrix chain multiplication

M[i,j] = M[i,k] + M[(k+1),j] + p[i-1]*p[k]*p[j] i<=k<j

p[] = {5,10,3,12,5,50}

M[0][0] = 0,M[1][1] = 0,M[2][2] = 0,M[3][3] = 0,M[4][4] = 0,M[5][5] = 0,

M[1][2] = M[1][1]+M[2][2]+p[0]*p[1]*p[2] = 0+0+5*10*3 = 150

M[2][3] = M[3][3]+M[2][2]+p[1]*p[2]*p[3] = 0+0+10*3*12 = 360

M[3][4] = M[3][3]+M[4][4]+p[2]*p[3]*p[4] = 0+0+3*12*5 = 180

M[4][5] = M[4][4]+M[5][5]+p[3]*p[4]*p[5] = 0+0+12*5*50 = 3000

M[1][3] = min{M[1][1]+M[2][3]+p[0]*p[1]*p[3] , M[1][2]+M[3][3]+p[0]*p[2]*p[3]}

= {0 + 360 + 600 , 150+0+180} = {960,330} = 330

M[2][4] = min{M[2][2]+M[3][4]+p[1]*p[2]*p[4] , M[2][3]+M[4][4]+p[1]*p[3]*p[4]}

= {0 + 180 + 150 , 360+0+600} = {960,330} = 330

M[3][5] = min{M[3][3]+M[4][5]+p[2]*p[3]*p[5] , M[3][4]+M[5][5]+p[2]*p[4]*p[5]}

= {0 + 3000 + 1800 , 180+0+750} = {4800,930} = 930

M[1][4] = min{M[1][1] + M[2][4] +p[0]*p[1]*p[4] ,M[1][2] + M[3][4] +p[0]*p[2]*p[4] ,

M[1][3] + M[4][4] +p[0]*p[3]*p[4]}

{0+330+250 , 150+180+75 , 330+0+300} = 405

M[2][5] = min{M[2][2] + M[3][5] +p[1]*p[2]*p[5] ,M[2][3] + M[4][5] +p[1]*p[3]*p[5] ,

M[2][4] + M[5][5] +p[1]*p[4]*p[5]}

{0+930+1500 , 360+3000+6000,330+0+2500} = 2430

M[1][5] = min{M[1][1] +M[2][5]+p[0]*p[1]*p[5] , M[1][2] +M[3][5]+p[0]*p[2]*p[5],

M[1][3] +M[4][5]+p[0]*p[3]*p[5] , M[1][4] +M[5][5]+p[0]*p[4]*p[5]}

{0+2430+2500 , 150+930+750 , 330+3000+3000 , 405+0+1250} = 1655

(a)

MemoizedCutRod(p, n)

r: array(0..n) := (0 => 0, others =>MinInt)

return MemoizedCutRodAux(p, n, r)

MemoizedCutRodAux(p, n, r)

if r(n) = 0 and then n /= 0 then -- check if need to calculate a new solution

q: int := MinInt

for i in 1 .. n loop

q := max(q, p(i) + MemoizedCutRodAux(p, n-i, r))

end loop

end if

r(n) := q

end if

return r(n)

8 0
3 years ago
Carl why is there a dead man in the living room?
scoray [572]
You always need some company
3 0
3 years ago
A 5-mm-thick stainless steel strip (k = 21 W/m•K, rho = 8000 kg/m3, and cp = 570 J/kg•K) is being heat treated as it moves throu
Drupady [299]

Answer:

The temperature of the strip as it exits the furnace is 819.15 °C

Explanation:

The characteristic length of the strip is given by;

L_c = \frac{V}{A} = \frac{LA}{2A} = \frac{5*10^{-3}}{2} = 0.0025 \ m

The Biot number is given as;

B_i = \frac{h L_c}{k}\\\\B_i = \frac{80*0.0025}{21} \\\\B_i = 0.00952

B_i < 0.1,  thus apply lumped system approximation to determine the constant time for the process;

\tau = \frac{\rho C_p V}{hA_s} = \frac{\rho C_p L_c}{h}\\\\\tau = \frac{8000* 570* 0.0025}{80}\\\\\tau = 142.5 s

The time for the heating process is given as;

t = \frac{d}{V} \\\\t = \frac{3 \ m}{0.01 \ m/s} = 300 s

Apply the lumped system approximation relation to determine the temperature of the strip as it exits the furnace;

T(t) = T_{ \infty} + (T_i -T_{\infty})e^{-t/ \tau}\\\\T(t) = 930 + (20 -930)e^{-300/ 142.5}\\\\T(t) = 930 + (-110.85)\\\\T_{(t)} = 819.15 \ ^0 C

Therefore, the temperature of the strip as it exits the furnace is 819.15 °C

5 0
3 years ago
Consider an ideal cogeneration steam plant to generate power and process heat. Steam enters the turbine from the boiler at 7 Mpa
igomit [66]

Answer:

1. The diagram T-s or H-s is attached to this answer.

2. The fraction of the steam extracted is 4.088Kg/s

3. The net Power produced per kg of steam exiting the boiler is 1089.5KJ/Kg.

4. The mass flow rate of steam supplied by the boiler is 16.352Kg/s

5. the net power produced by the plant is 11016.2KJ/s.

6. The utilization factor is 0.218.

Explanation:

To analyze this problem we need to find all the thermodynamic coordinates of the system. In the second image attached to this answer, we can see the entire ideal cogeneration steam plant system.

From a water thermodynamic properties chart, we can obtain the information for each point.

+ Steam enters the turbine from the boiler at 7 Mpa and 500 degrees C:

h₆=3410.56KJ/Kg

s₆=6.7993 KJ/Kg

This is an ideal cogeneration steam system, therefore: s₆=s₇=s₈

+One-fourth of the steam is extracted from the turbine at 600-kPa:

h₇(s₇) = 2773.74 KJ/Kg (overheated steam)

+The remainder of the steam continues to expand and exhausts to the condenser at 10 kPa.

h₈(s₈)=2153.58 KJ/Kg (this is wet steam with title X=0.8198)

h₁(P=10Kpa)= 191.83 KJ/Kg (condensed water) s₁=0.64925KJ/Kg

-This flow is pumped to 600KPa, so:

s₂=s₁

h₂(s₂)=192.585KJ/Kg

+The steam extracted for the process heater is condensed in the heater:

h₃(P=600KPa)=670.42KJ/Kg (condensed water)

+The steam extracted for the process heater is condensed in the heater and mixed with the feed-water at 600 kPa:

The mixing process of the flow of point 2 and 3 is an adiabatic process, therefore:

\dot{Q}_4=\dot{Q}_2+\dot{Q}_3=\dot{m}_2 h_2+\dot{m}_3h_3\\\dot{m}_4 h_4=\dot{m}_2 h_2+\dot{m}_3h_3=\dot{m}_2 0.75h_4+\dot{m}_30.25h_4\\h_4=0.75h_2+0.25h_3=312.043KJ/Kg

s₄=1.02252

+the mixture is pumped to the boiler pressure of 7 Mpa:

s₅=s₄

h₅(s₅)=323.685KJ/Kg

1)Now we have all the thermodynamic coordinates and we can draw the diagram of the system.

2) To determine the fraction of steam, the mass flow that is extracted from the turbine at state 7, we use the information that this flow is used to generate 8600KJ/s in a process of heat. Therefore:

P=8600KJ/s=\dot{m}_{3-7}(h_7-h_3)\\\dot{m}_{3-7}=8600KJ/s/(h_7-h_3)=4.088Kg/s

3)The net power produced per kg of steam exiting the boiler can be obtained as the rest between all the power obtained in the turbine less the power used in the pumps:

P_{turb}/Kg=(h_6-h_7)+0.75(h_7-h_8)=1101.94KJ/Kg\\P_{pump1}/Kg=h_2-h_1=0.755KJ/kg\\P_{pump2}/kg=h_5-h_4=11.642KJ/Kg\\P_{net}/kg=P_{turb}-P_{pump1}-P_{pump2}=1089.543KJ/Kg

4) To determine the mass flow rate of steam that must be supplied by the boiler, we only have to remember that the flow used in point 2) is a fourth of the total flow. therefore:

0.25\dot{m}_{tot}=\dot{m}_{3-7}\\\dot{m}_{tot}=4\dot{m}_{3-7}=16.352Kg/s

5)The net power supplied by the plant is the net power calculated in point 3) less the power used in the heat process 7-3:

P_{net sys}=P_{net}/kg \cdot \dot{m}_t-6800Kj/s=11016.2KJ/s

6) The utilization factor is obtained as the division between net power supplied by the plant and the power used to heat the steam. In this case:

UF=P_{net sys}/P_{boil}=P_{net sys}/[\dot{m}_t(h_6-h_5)]=0.21

3 0
3 years ago
Other questions:
  • You are designing a system for a real-time application in which specific deadlines must be met. Finishing the computation faster
    10·1 answer
  • Nicholas wants to verify whether a file is a hard link to a file within the same directory. Which of the following commands coul
    6·1 answer
  • How are the fuel gas and oxygen cylinders fastened to the cutting outfit or portable truck​
    13·1 answer
  • In a manufacturing process, long aluminum rods of square cross section with d = 25 mm are cooled from an initial temperature of
    12·2 answers
  • How does a beam deform when it is subjected to an upward load in the middle and supported at both ends? a. Both the top and bott
    9·1 answer
  • An important material for advanced electronic technologies is the pure silicon.a)-True b)-False
    9·1 answer
  • Water flows through a Xylan tube at 300 K temperature and 0.5 kg/s flow rate. The inner and outer radii of the Xylan tube is 20
    15·1 answer
  • The insulation resistance of a motor operated by an electronic drive is to be tested using a megger. What precaution should you
    5·1 answer
  • The compression ratio of most small gasoline engines falls between_______and________.
    13·2 answers
  • Consider a cup on a dinning table half filled with water.
    13·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!