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

Write a program that asks the user to choose from the following options: Triangl

ID: 670384 • Letter: W

Question

Write a program that asks the user to choose from the following options: Triangle (Area = 1/2 Times b Times h, b = base, h = vertical height) Square (Area = a Times a, a = length of side) Rectangle (Area = w Times h, w = width, h = height) Parallelogram (Area = b Times h, b = base, h = vertical height) Circle (Area = pi Times r Times r, r = radius) Depending on the option chosen, the user must be prompted to enter the required parameters to calculate the Area of the shape. Once the Area is calculated the output should be printed on to the output console and also be written into a file named "output, txt". Example output (user input is bold): This is a program to calculate the area of different 2D shapes. Please choose from below: Triangle Square Rectangle Parallelogram Circle You have chosen to calculate the area of parallelogram. Please enter the required parameters base (b) and height (h): The area of the parallelogram with b = 10.0 and h = 5.0 is given as b Times h = 50.0 Notes and Hints: Don't forget to submit the *.c/*.cpp file which contains your source code! NO NEED TO SUBMIT THE OUTPUT.TXT If the user enters any value other than (1 - 5), the output should be "Invalid Option". Look at the lecture notes for help and make sure this is taken care of. Define a constant for tt as 3.14 You need to use if-else statements and file input/output options.

Explanation / Answer

#include<iostream>

using namespace std;

int main(){
  
   cout<<"1. Triangle"<<endl;
   cout<<"2. Square"<<endl;
   cout<<"3. Rectangle"<<endl;
   cout<<"4. Parallelogram"<<endl;
   cout<<"5. Circle"<<endl;
   int choice;
   cin >> choice;
   switch(choice){
       case 1:
           int b,h;
           cin>>b>>h;
           cout<<"Area: "<<0.5*b*h'
           break;
       case 2:
           int a;
           cin>>a;
           cout<<"Area: "<<a*a;
           break;
       case 3:
           int l,b
           cin>>l>>b;
           cout<<"Area: "<<l*b;
           break;
       case 4:
           int b,h;
           cin>>b>>h;
           cout<<"Area: "<<b*h;
           break;
       case 5:
           int r;
           cin>>r;
           cout<<"Area "<<3.14*r*r;
           break;
   }
  
   return 0;
}

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