Question

Lab 5 Areas.cpp Marisol Castellanos villa #include # include using nanespace std; int main // ?NCLUDE ANY NEEDED FILES HERE ciostrean cmath.ho const double PI 3.14159 DEFINE THE NAMED CONSTANT PI HERE AND SET ITS VALUE TO 3.14159 oat c radius, c area; loat s side, s area float t-height, tvidth, tarea; int choice: char ch; de // DECLARE ALL NEEDED VARIABLES HERE. GIVE EACH ONE A DESCRIPT?VE /I NAME AND AN APPROPRIATE DATA TYPE coutecProgran to calculate areas of objects scendl; coutsc 1 coutss 2 square ecendl; circle <xendl WRITE STATEMENTS HERE TO DISPLAY THE 4 MENU CHOICES coutee 4..quit ecendt: coutee Enter the option to perfors the action: cin » choice; if (choicem1) WRITE A STATEMENT HERE TO INPUT THE USERS MENU CHOICE // USE AN IF/ELSE IF STATEMENT TO OBTA?N ANY NEEDED INPUT ?NFORMATION coutsc\nEnter the Length of the side of the square: cimo s side; s areaus side side; coutec Areaees areakcendl: s else if (choices2) coutec\nRadius of the circle: cin-c radius c area PIc radius c radius; coutee Area eec areaccendl: else if (choices3) coutsc\nEnter the height of the right triangle: cino t height: couteeEnter the width of the right triangle:: cinos t width t area.5 t height t width; cout<cArea <ct areaccendl; else if (choicess4) exit(0) before entering 4 to quit.

0 0
Add a comment Improve this question Transcribed image text
Answer #1

#include <iostream>
#include <math.h>
using namespace std;

//prototypes
void display();
void findSquareArea();
void findCircleArea();
void findTriangleArea();
const double PI = 3.14159;
int main() {
int choice;

do
{
display();
cout<<"Enter the option to perform the action";
cin>>choice;
if(choice == 1)
{
findSquareArea();
}
else if(choice == 2)
{
findCircleArea();
}
else if(choice == 3)
{
findTriangleArea();
}

else if(choice == 4)
exit(0);
}while(choice != 4);
return 0;
}
//function definitions
void display()
{
cout<<"program to calculate area of objects "<<endl;
cout<<"1.........Square"<<endl;
cout<<"2.........Circle"<<endl;
cout<<"3.........Right Triangle"<<endl;
cout<<"4.........Quit"<<endl;
}
void findSquareArea()
{
  float s_side,s_area;
  cout<<"\nEnter the length of the side of the square : ";
  cin>>s_side;
  s_area = s_side*s_side;
  cout<<"\nArea = "<<s_area<<endl;
}
void findCircleArea()
{
float c_radius,c_area;
cout<<"\nEnter the radius of the circle : ";
  cin>>c_radius;
  c_area = PI*c_radius*c_radius;
  cout<<"\nArea = "<<c_area<<endl;
}
void findTriangleArea()
{
  float t_height,t_width,t_area;
  cout<<"\nEnter the height of the right triangle : ";
  cin>>t_height;
  cout<<"\nEnter the width of the right triangle : ";
  cin>>t_width;
  t_area = 0.5 * t_height * t_width;
  cout<<"\nArea = "<<t_area<<endl;
}

Output:

program to calculate area of objects
1.........Square
2.........Circle
3.........Right Triangle
4.........Quit
Enter the option to perform the action 1
Enter the length of the side of the square :3.4
Area = 11.56
program to calculate area of objects
1.........Square
2.........Circle
3.........Right Triangle
4.........Quit
Enter the option to perform the action 2
Enter the radius of the circle :4.1
Area = 52.8101
program to calculate area of objects
1.........Square
2.........Circle
3.........Right Triangle
4.........Quit
Enter the option to perform the action 3
Enter the height of the right triangle :5.6
Enter the width of the right triangle :2.9
Area = 8.12
program to calculate area of objects
1.........Square
2.........Circle
3.........Right Triangle
4.........Quit
Enter the option to perform the action 4

Do ask if any doubt. Please upvote.

Add a comment
Know the answer?
Add Answer to:
Lab 5 Areas.cpp Marisol Castellanos villa #include # include using nanespace std; int main // ?NCLUDE...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • Create a menu-driven program (using the switch) that finds and displays areas of 3 different objects....

    Create a menu-driven program (using the switch) that finds and displays areas of 3 different objects. The menu should have the following 4 choices: 1 -- rectangle 2 -- circle 3 -- triangle 4 -- quit If the user selects choice 1, the program should find the area of a rectangle. rectangle area = length * width If the user selects choice 2, the program should find the area of a circle. circle area = PI * radius * radius...

  • Menu-driven programs will display the menu options to the user and then prompt them for a...

    Menu-driven programs will display the menu options to the user and then prompt them for a menu choice. This program will display the following menu in the following format: Calculator Options: Calculate the area of a circle Calculate the area of a rectangle Calculate the area of a triangle Calculate the area of a trapezoid Calculate the area of a sphere Exit Enter your choice (1-6) Once the user enters a choice for the menu, the program should use a...

  • write a completed program (included the main) for the Q: add an equals method to each...

    write a completed program (included the main) for the Q: add an equals method to each of the Rectangle circle and triangle classes introduced in this chapter. two shapes are considered equal if their fields have equivalent values. based on public class Circle implements Shape f private double radius; // Constructs a new circle with the given radius. public Circle (double radius) f this.radius - radius; // Returns the area of this circle. public double getArea) return Math.PI *radius *...

  • Watermelon Problem: The answer should not include any whitespace. #include<iostream> using namespace std; int main() {...

    Watermelon Problem: The answer should not include any whitespace. #include<iostream> using namespace std; int main() {     double distance, gravity =9.8, height;     int time, t=0;     cout<<"Please input the time of fall in seconds:"<<endl;     [ A ] // Get the user input of the time of fall in seconds (Use cin>> method)     cout<<endl;     cout<<"Please input the height of the bridge in meters:"<<endl;     [ B ] // Get the user input of the height of the bridge in meters (Use cin>>...

  • I am trying to write a Geometry.java program but Dr.Java is giving me errors and I...

    I am trying to write a Geometry.java program but Dr.Java is giving me errors and I dont know what I am doing wrong. import java.util.Scanner; /** This program demonstrates static methods */ public class Geometry { public static void main(String[] args) { int choice; // The user's choice double value = 0; // The method's return value char letter; // The user's Y or N decision double radius; // The radius of the circle double length; // The length of...

  • #include <iostream> #include <sstream> #include <string> using namespace std; int main() {    const int index...

    #include <iostream> #include <sstream> #include <string> using namespace std; int main() {    const int index = 5;    int head = 0;    string s[index];    int flag = 1;    int choice;    while (flag)    {        cout << "\n1. Add an Item in the Chores List.";        cout << "\n2. How many Chores are in the list.";        cout << "\n3. Show the list of Chores.";        cout << "\n4. Delete an...

  • Skills Needed: cin, cout, constants, arithmetic expressions, rounding, int main, meaningful variable names, spacing, indentation, documentation,...

    Skills Needed: cin, cout, constants, arithmetic expressions, rounding, int main, meaningful variable names, spacing, indentation, documentation, output. Computing Basic Geometric Formulas Write a program to compute answers to some basic geometry formulas. The program prompts the user to input a length (in centimeters) specified as a floating point value. The program then echoes the input and computes areas of squares and circles and the volume of a cube. For the squares, you will assume that the input length value is...

  • Using C++, Write a program that will provide the user a menu from which the user...

    Using C++, Write a program that will provide the user a menu from which the user may select to calculate the area of one of four geometric shapes: a circle, a rectangle, a triangle, and a trapezoid. You should use the most appropriate SWITCH block for this program. The user will input all data needed to calculate the area. The program should output all data input by the user, the calculated area, and the geometric shape selected. Run this program...

  • Project Objectives: To develop ability to write void and value returning methods and to call them...

    Project Objectives: To develop ability to write void and value returning methods and to call them -- Introduction: Methods are commonly used to break a problem down into small manageable pieces. A large task can be broken down into smaller tasks (methods) that contain the details of how to complete that small task. The larger problem is then solved by implementing the smaller tasks (calling the methods) in the correct order. This also allows for efficiencies, since the method can...

  • C++ programming For this assignment, write a program that will act as a geometry calculator. The...

    C++ programming For this assignment, write a program that will act as a geometry calculator. The program will be menu-driven and should continue to execute as long as the user wants to continue. Basic Program Logic The program should start by displaying a menu similar to the following: Geometry Calculator 1. Calculate the area of a circle 2. Calculate the area of a triangle 3. Quit Enter your choice(1-3): and get the user's choice as an integer. After the choice...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT