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

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
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...
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 -/+
Given the following Java code: class C { public int foo(C p) { return 1; }...
Given the following Java code: class C { public int foo(C p) { return 1; } } class D extends C { public int foo(C p) { return 2; } public int foo(D p) { return 3; } } C p = new C(); C q = new D(); D r = new D(); int i = p.foo(r); int j = q.foo(q); int k = q.foo(r); (Remember that in Java every object is accessed through a pointer and that methods...
write pseudocode for the following problems not c code Pseudocode only Write a C program to...
write pseudocode for the following problems not c code Pseudocode only Write a C program to print all natural numbers from 1 to n. - using while loop Write a C program to print all natural numbers in reverse (from n to 1). - using while loop Write a C program to print all alphabets from a to z. - using while loop Write a C program to print all even numbers between 1 to 100. - using while loop...
Represent following LEGv8 machine code into assembly instruction. 0x784302CD
Represent following LEGv8 machine code into assembly instruction. 0x784302CD
Directions: You are to write a C++ program that meets the instruction requirements below. Deliverables: ·...
Directions: You are to write a C++ program that meets the instruction requirements below. Deliverables: · Your C++ source code file. (The file with the .CPP extension).No other files will be accepted. A screenshot of your program running. Program Instructions: Consider the following incomplete C++ program: #include int main() { … } 1. Write a statement that includes the header files fstream, string, and iomanip in this program. 2. Write statements that declare inFile to be an ifstream variable and...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT