Answered step by step
Verified Expert Solution
Link Copied!

Question

00
1 Approved Answer

Based on the answer below. Extend the program you wrote in P1 in a way that calculate the perimeter or circumference of each shape as

image text in transcribed

Based on the answer below. Extend the program you wrote in P1 in a way that calculate the perimeter or circumference of each shape as well.

% display the menu of shapes

fprintf("Select the shape from the following shapes: ");

fprintf("1. Square " + ...

"2. Circle " + ...

"3. Rectangle " + ...

"4. Sector of circle " + ...

"5. Triangle " + ...

"6. Ellipse " + ...

"7. Equilateral triange " + ...

"8. Annulus " + ...

"9. Trapezoid " + ...

"10. Regular Polygon " + ...

"11. Parallelogram ");

% read user input for shape

shape = input("Enter the option number: ");

% check what shape user has selected and read the corresponding data from

% user and calculate the area and display it

if shape == 1

s = input('Enter the side: ');

area = s*s;

fprintf("Area = %f", area);

elseif shape == 2

r = input("Enter radius: ");

area = pi * r * r;

fprintf("Area = %f", area);

elseif shape == 3

l = input("Enter length: ");

b = input("Enter breath: ");

area = l*b;

fprintf("Area = %f", area);

elseif shape == 4

r = input("Enter radius: ");

theta = input("Enter the value of angle(radians): ");

area = (1/2) * theta * r * r;

fprintf("Area = %f", area);

elseif shape == 5

b = input('Enter base: ');

h = input('Enter height: ');

area = (1 / 2) * b * h;

fprintf("Area = %f", area);

elseif shape == 6

a = input("Enter semimajor axis: ");

b = input('Enter semiminor axis: ');

area = pi * a * b;

fprintf("Area = %f", area);

elseif shape == 7

s = input('Enter side: ');

area = (sqrt(3) / 4) * s*s;

fprintf("Area = %f", area);

elseif shape == 8

r = input('Enter inner radius: ');

R = input('Enter outer radius: ');

area = pi * (R*R - r*r);

fprintf("Area = %f", area);

elseif shape == 9

a = input('Enter smaller base: ');

b = input('Enter bigger base: ');

h = input('Enter height: ');

area = (1 / 2) * (a + b) * h;

fprintf("Area = %f", area);

elseif shape == 10

s = input('Enter side: ');

n = input('Enter number of sides: ');

area = (1 / 2) * n * s * s * (1 / tan(pi / n));

fprintf("Area = %f", area);

elseif shape == 11

b = input('Enter base: ');

h = input('Enter height: ');

area = b * h;

fprintf("Area = %5f", area);

% if user inputs an invalid option

else

disp('Invalid input.');

end

SQUARE s = side Area: A=s? Perimeter: P = 4s CIRCLE r = radius, d = diameter Diameter: d=2r Area: A= r Circumference: C=2 =nd RECTANGLE I = length = width Area: A=Ine Perimeter: P = 22 + 2 SECTOR OF CIRCLE r = radius. 8 = angle in radians Area: A = 10,2 Are Length: s=or TRIANGLE b = base, h = height Area: A = oh Perimeter: P= a + b + c ELLIPSE a= semimajor axis b = seriminor axis Area: A=Tab Circumference: CA3(a+h)-Va+36)(b + 3a) EQUILATERAL TRIANGLE S = side Height: h= Area: A=74 ANNULUS r=inner radius, R= outer radius Average Radius: p= }(r+R) Width: w = R -T Area: A = (R? - 2) or A = 2x pee PARALLEL OG RAM b = base, h = height, = side Area: A bh Perimeter: P = 2a + 2b TRAPEZOID a.b = bases: h = height: e, d = sides Area: A = (a + b Perimeter: P = a +b+c+d REGULAR POLYGON s=side length. 11 = number of sides Circumradius: R= is cs() Area: A = ins-cot ) or A = Rasin()

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access with AI-Powered Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Students also viewed these Databases questions