203: Rectangle Area: Define a struct to represent a rectangle with attributes length and width. Write a program to calculate and display the area of a given rectangle.
// Rectangle Area: Define a struct to represent a rectangle with attributes length and width.
// Write a program to calculate and display the area of a given rectangle.
#include <iostream>
using namespace std;
struct Rectangle
{
int length, width;
};
Rectangle add_rect();
int main()
{
Rectangle rect1 = add_rect();
Rectangle rect2 = add_rect();
Rectangle rect3 = add_rect();
system("cls");
cout << "Area of rectangle 1 is: " << rect1.length * rect1.width << endl;
cout << "Area of rectangle 2 is: " << rect2.length * rect2.width << endl;
cout << "Area of rectangle 3 is: " << rect3.length * rect3.width << endl;
return 0;
}
Rectangle add_rect()
{
system("cls");
Rectangle x;
cout << "Enter the length of rectangle: ";
cin >> x.length;
cout << "Enter the width of rectangle: ";
cin >> x.width;
return x;
}
Comments
Post a Comment