#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.
Lab 5 Areas.cpp Marisol Castellanos villa #include # include using nanespace std; int main // ?NCLUDE...
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 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 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 *...
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...
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>>...
#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...
JAVA Code Requried Copy the file java included below. This program will compile, but, when you run it, it doesn’t appear to do anything except wait. That is because it is waiting for user input, but the user doesn’t have the menu to choose from yet. We will need to create this. Below the main method, but in the Geometry class, create a static method called printMenu that has no parameter list and does not return a value. It will...
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 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 -- 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...