Hello, OnlineGDB Q&A section lets you put your programming query to fellow community users. Asking a solution for whole assignment is strictly not allowed. You may ask for help where you are stuck. Try to add as much information as possible so that fellow users can know about your problem statement easily.

pls explain this program

0 votes
asked May 20, 2018 by Mahmud Muhammad (230 points)
#include <iostream>

using namespace std;

int main()
{
    int Menu;
    double pi = 3.14159265;
    double A, r, h, g, a, b;
    // A = Area
    // r = radius
    // h = height
    // g = baseline of the Triangle
    // a = 1st side of the Rectangle
    // b = 2nd side of the Rectangle
    
    do{
        
        
        cout << "\nChoose an option: ";
        cout << "";
        cout << " 1 = Circle";
        cout << " 2 = Rectangle ";
        cout << " 3 = Triangle  ";
        cout << " 4 = End       ";
        cout << "" << endl;
        cin >> Menu;
        
        if(Menu == 1){
            cout << "\nCalculate the Area of a circle";
            cout << "\nType in the value for r: ";
            cin >> r;
            A = r * r * pi;
            cout << "The Area of the circle is: " << A;
        }
                
        if(Menu == 2){
            cout << "\nCalculate the Area of a rectangle: ";
            cout << "\nType in the value of a: ";
            cin >> a;
            cout << "Type in the value of b: ";
            cin >> b;
            A = a * b;
            cout << "The Area of the rectangle is: " << A;
        }
                
        if(Menu == 3){
            cout << "\nCalculate the Area of a Triangle: ";
            cout << "\nType in the value for the height h: ";
            cin >> h;
            cout << "Type in the value for g: ";
            cin >> g;
            A = 0.5 * g * h;
            cout << "The Area of the triangle is: " << A;
        }
                
        if(Menu == 4){
            cout << "\nThe End!";
        }    
        
        if(Menu > 4){
            cout << "Error! Not a valid option!";
        }
        
    }while(Menu != 4);

    return 0;
}

1 Answer

0 votes
answered May 22, 2018 by chandni23 (180 points)
Hello,

It is a very simple program.

coding language is c++. Based on the user input snippet will calculate the area of  circle,rectangle,Triangle.
commented May 22, 2018 by muha
#include <iostream>
//-> including the standard libraries

using namespace std;
//-> this is useful for beginners you dont need to write std:: e.g.: std::cout<<" ";



int main()  //-> this is where your main function starts all your code goes inside of it you will learn more about functions as you progress
{
    int Menu;                   //Variable for the Menu
    double pi = 3.14159265;     //Variable for pi
    double A, r, h, g, a, b;
    // Variable for:
    // A = Area
    // r = radius
    // h = height
    // g = baseline of the Triangle
    // a = 1st side of the Rectangle
    // b = 2nd side of the Rectangle
    
    do{             //-> this starts a loop as long as the user doesnt input 4 for the variable Menu it will always stay in this loop see the while statement at the end
        
        //cout is printing the following lines to the console window
        cout << "\nChoose an option: ";
        cout << "";
        cout << " 1 = Circle";
        cout << " 2 = Rectangle ";
        cout << " 3 = Triangle  ";
        cout << " 4 = End       ";
        cout << "" << endl;
        cin >> Menu;        //cin reads an input from the console to a variable (here the Variable is Menu)
        
        if(Menu == 1){
            //if Variable Menu has the Value 1 (if the user inputs 1), it will run the following code:
            cout << "\nCalculate the Area of a circle";
            cout << "\nType in the value for r: ";
            cin >> r;
            A = r * r * pi;
            cout << "The Area of the circle is: " << A;
            //Calculates the Area of a circle and prints the result onto the screen
        }
                
        if(Menu == 2){
            //if Variable Menu has the Value 2 (if the user inputs 2), it will run the following code:
            cout << "\nCalculate the Area of a rectangle: ";
            cout << "\nType in the value of a: ";
            cin >> a;
            cout << "Type in the value of b: ";
            cin >> b;
            A = a * b;
            cout << "The Area of the rectangle is: " << A;
            //Calculates the Area of a rectangle and prints the result onto the screen
        }
                
        if(Menu == 3){
            //if Variable Menu has the Value 3 (if the user inputs 3), it will run the following code:
            cout << "\nCalculate the Area of a Triangle: ";
            cout << "\nType in the value for the height h: ";
            cin >> h;
            cout << "Type in the value for g: ";
            cin >> g;
            A = 0.5 * g * h;
            cout << "The Area of the triangle is: " << A;
            //Calculates the Area of a triangle and prints the result onto the screen
        }
                
        if(Menu == 4){
            //if Variable Menu has the Value 4 (if the user inputs 4), it will run the following code:
            cout << "\nThe End!";
            //Prints The End to the Screen
        }    
        
        if(Menu > 4){
            //if Variable Menu is bigger than 4 (if the user inputs something bigger than 4), it will run the following code:
            cout << "Error! Not a valid option!";
            //this part is basic error handling
        }
        
    }while(Menu != 4);
    //the code in the do{}while(); will run as long as the user doenst input the value 4 for the Variable Menu

    return 0;
}
Welcome to OnlineGDB Q&A, where you can ask questions related to programming and OnlineGDB IDE and and receive answers from other members of the community.
...