Question

In: Computer Science

---------------------------------------------------------------------------------------------------------------- C++ //code a program for the following the given Instruction. Geometry Calculator 1. Calculate the...

----------------------------------------------------------------------------------------------------------------

C++

//code a program for the following the given Instruction.

Geometry Calculator

1. Calculate the Area of a Circle

2. Calculate the Area of a Rectangle

3. Calculate the Area of a Triangle

4. Quit

Enter your choice (1-4):

If the user enters 1, the program should ask for the radius of the circle and then display its area. Use 3.14159 for pi.

#03   If the user enters 2, the program should ask for the length and width of the rectangle, and then display the rectangle's area.

#04   If the user enters 3, the program should ask for the length of the triangle's base and its height, and then display its area.

#05   If the user enters 4, the program should end.

#06   Input validation: Accept only values 1-4 for the menu and only positive values for the other user inputs.

--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------

Solutions

Expert Solution

#include<iostream>
using namespace std;
int main(){
   int ch;
   float r, len , width, height;
  
   do{ // repeat until user not enter 4
       cout<<"\nGeometry Calculator"<<endl;
       cout<<"1. Calculate the Area of a Circle"<<endl;
       cout<<"2. Calculate the Area of a Rectangle"<<endl;
       cout<<"3. Calculate the Area of a Traingle"<<endl;
       cout<<"4. Quit"<<endl;
       cout<<"Enter your choice (1-4): ";
       cin >> ch;
       if(ch < 0 || ch > 4){ // input validation
           cout <<"\nInvalid Input\n";
       }else{
           switch(ch){
               case 1: cout<<"Enter radius of Circle: ";
                       cin >> r;
                       // to print with 2 decimal places
                       printf("Area of Circle: %.2f",3.14159*r*r);
                       break;
               case 2: cout<<"Enter the length and width of the rectangle: ";
                       cin >> len >> width;
                       printf("Area of Rectangle: %.2f",len*width);
                       break;
               case 3: cout<<"Enter the length and height of the triangle: ";
                       cin >> len >> height;
                       printf("Area of Rectangle: %.2f",((float)1/2)*len*height);
                       break;
           }
       }  
   }while(ch!=4);
  
}

/* OUTPUT */

/* PLEASE UPVOTE */


Related Solutions

C++ Write a program that displays the follow menu: Geometry Calculator    1. Calculate the Area...
C++ Write a program that displays the follow menu: Geometry Calculator    1. Calculate the Area of a Circle 2. Calculate the Area of a Rectangle    3. Calculate the Area of a Triangle 4. Quit Enter your choice (1-4): If the user enters 1, the program should ask for the radius of the circle then display it's area using the following formula: area = PIr2 Use 3,14159 for PI and the radius of the circle for r. If the...
Assignment #3 – Geometry Calculator Assignment Objectives Task #1 void Methods 1. Name the program file...
Assignment #3 – Geometry Calculator Assignment Objectives Task #1 void Methods 1. Name the program file Geometry.java. 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 it. 2. Below the main method, but in the Geometry class,create a static method called printMenu that has no parameter list...
Ch 4 Program 3  – Geometry Calculator Please adhere to the Standards for Programming Assignments and the...
Ch 4 Program 3  – Geometry Calculator Please adhere to the Standards for Programming Assignments and the Java Coding Guideline. : List of source code with comments to document Test output listed as comments at the end of your program GeometryCalculator.java (15 pts) Write a program that displays the following menu: Calculate the area of a circle Calculate the area of a rectangle Calculate the area of a triangle Calculate the volume of a cylinder Quit Prompt the user to enter...
Consider the following C code: (10 marks) // write a MIPS instruction to initialize s0 to...
Consider the following C code: // write a MIPS instruction to initialize s0 to 6 t0 = ((s03 - 93)2 + s0 ) << 2 t1 = t0 / 4 Q2.1: Write a MIPS program that performs the operation of the above C program. Q2.2: What is the value of $t0 and $t1 after running your MIPS program (write your answer in a comment at the end of the code). Submit your answer to Q2 in a file named A2_Q2.asm
2. Given the Instruction sets for Machine-1, Machine-2 and Machine-3, write programs to calculate: P= ((B×C)...
2. Given the Instruction sets for Machine-1, Machine-2 and Machine-3, write programs to calculate: P= ((B×C) + (A +D)) / (E - C × D) and comment on relative efficiency. Machine-1: One address instructions Machine-2: Two address instructions Machine-3: Three address instructions STORE X ; X<― [AC] LOAD X ; AC<― [X] MPY X ; AC<― [AC x X] DIV X ; AC<― [AC / X] ADD X ; AC<― [AC + X] SUB X ; AC<― [AC -X] X...
I. Design the C++ code for a program which will use the Pythagorean Theroem to calculate...
I. Design the C++ code for a program which will use the Pythagorean Theroem to calculate and display the length of a right triangle hypotenuse,c, given the lengths of its adjacent sides: a and b.. (hint: a^2 + b^2 = c^2) II. Design the C++ code for a program which will calculate and display the roots of a quadratic equation of the form ax^2 + bx + c = 0, given its coefficients, a, b, and c.
1. Specification Write a C program to implement a simple calculator that accepts input in the...
1. Specification Write a C program to implement a simple calculator that accepts input in the following format and displays the result of the computation: calc [operand_1] [operator] [operand_2] The operands operand_1 and operand_2 are non-negative integers. The operator is one of the following: addition (+), subtraction (-), multiplication (x), division (/) and modulo (%). Note: For the multiplication operator, use letter ‘x’. If you use the asterisk ‘*’, your program will not work properly 2. Implementation • The program...
Need C++ code for following with a document describing the code as well: Write a program...
Need C++ code for following with a document describing the code as well: Write a program to implement the game of Tic Tac Toe Four. The game is played on a 4 × 4 chessboard, within 2 players. The player who is playing "X" always goes first. Players alternate placing Xs and Os on the board until either one player has four in a row, horizontally, vertically, or diagonally; or all 16 squares are filled(which is a draw). The program...
implement a Message Authentication Code program in either C/C++ or Python. See the following steps. 1....
implement a Message Authentication Code program in either C/C++ or Python. See the following steps. 1. Accept a message as keyboard input to your program. 2. Accept a secret key for the sender/recipient as keyboard input to your program. 3. Your hash function H() is simply the checksum. To compute the checksum, you add all the characters of the string in ASCII codes. For example, the checksum of a string "TAMUC" would be 84 + 65 + 77 + 85...
Parse string java code Write a recursive program that can calculate the value of a given...
Parse string java code Write a recursive program that can calculate the value of a given polynomial in a string, which is not more than the tenth order, for the given x. The polynomial will be given in the following format and should display the value of the polynomial for spaced-out x Using index of for -/+
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT