Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

1. Write a Matlab program that will allow the user to find area and circumferenc

ID: 666397 • Letter: 1

Question

1. Write a Matlab program that will allow the user to find area and circumference of a circle. Selections and data entry will be done by presenting the user with a menu (using menu function) and provide her/him with the following choices:

Enter the radius

Display the area

Display the circumference

Exit

Other Requirements:

Selecting choice 2 or 3 before entering the radius will result in an error message. The program will terminate only when Exit has been selected

Calculations will be done by functions.

Function circleInfo() will ask for the radius and will return it.

Function circleArea() will accept a parameter, the radius, and returns the area.

Function circleCircum() will accept a parameter, the radius, and returns the circumference.

Results are displayed with 2 decimal place accuracy.

Partial Help with the menu:

flag =0;

%Calculation

while (1) choice=menu('Circle and Cylinder', 'Enter the radius','Display the area', 'Display the circumference','Exit'); switch(choice)

case 1

r=circleInfo();

flag=1;

case 2 if (flag==0)

disp('you need to enter the radius first');

else

area=circleArea(r);

end

Explanation / Answer

% circleInfo:

function radius = circleInfo()
radius = input('Enter the radius')

% circleArea:

function area = circleArea(radius)
area = 3.14 * radius * radius
  

% circleCircum

function circum = circleCircum(radius)
circum = 2 * 3.14 * radius
  

% main.m

flag = 0;
while (1)
choice=menu('Circle and Cylinder', 'Enter the radius','Display the area', 'Display the circumference','Exit');
switch(choice)
case 1
r=circleInfo();
flag=1;
case 2
if (flag==0)
disp('you need to enter the radius first');
else
area=circleArea(r);
end
end

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote