0% found this document useful (0 votes)
6 views2 pages

Back up project 1

The document is a C++ program that calculates the area or perimeter of a rectangle or square based on user input. The user is prompted to select a shape and then choose whether to calculate area or perimeter, followed by inputting the necessary dimensions. The program outputs the calculated area or perimeter accordingly.

Uploaded by

fahdadams6
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
6 views2 pages

Back up project 1

The document is a C++ program that calculates the area or perimeter of a rectangle or square based on user input. The user is prompted to select a shape and then choose whether to calculate area or perimeter, followed by inputting the necessary dimensions. The program outputs the calculated area or perimeter accordingly.

Uploaded by

fahdadams6
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
You are on page 1/ 2

#include <iostream>

#include <cmath>

using namespace std;

int main()
{
int shape_number;
cout << "Enter shape number: \n1.Rectangle \n2.Square \n";
cin >> shape_number;

switch(shape_number)
{
case 1:
{
int area_or_perimeter;
cout << "\nArea or Perimeter? \n1.Area \n2.Perimeter \n";
cin >> area_or_perimeter;

double length;
double breadth;
double area;
double perimeter;

if(area_or_perimeter == 1)
{
cout << "\nEnter the leangth: ";
cin >> length;
cout << "\nEnter the breadth: ";
cin >> breadth;

area = length * breadth;


cout << "\nThe area of the rectange is " << area;
break;
}

else if(area_or_perimeter == 2)
{
cout << "\nEnter the leangth: ";
cin >> length;
cout << "\nEnter the breadth: ";
cin >> breadth;

perimeter = 2 * (length + breadth);


cout << "The perimeter of the recteangle is " <<
perimeter;
break;
}

else;
cout << "Not an option";

case 2:
{
int area_or_perimeter;
cout << "\nArea or Perimeter? \n1.Area \n2.Perimeter \n";
cin >> area_or_perimeter;
double length;
double area;
double perimeter;

if(area_or_perimeter == 1)
{
cout << "\nEnter the leangth of side: ";
cin >> length;

area = length * length;


cout << "\nThe area of the square is " << area;
break;
}

else if(area_or_perimeter == 2)
{
cout << "\n Enter the leangth: ";
cin >> length;

perimeter = length * 4;
cout << "The perimeter of the square is " <<
perimeter;
break;
}

else;
cout << "Not an option";

}
}

You might also like