Write a program that uses three structures Dimensions, Results and Rectangle. The Dimension structure stores length and width, Result structure stores area and perimeter and Rectangle stores two variables of Dimension and Results. The program declares a variable of type Rectangle, inputs length, width, calculates area and width and then displays the result.
#include <iostream>
using namespace std;
struct Dimension
{
int length;
int width;
};
struct Results
{
int area;
int perimeter;
};
struct Rectangle
{
Dimension dimension;
Results results;
};
int main()
{
Rectangle a;
cout << "Enter length: ";
cin >> a.dimension.length;
cout << "Enter width: ";
cin >> a.dimension.width;
a.results.area = a.dimension.length * a.dimension.width;
a.results.perimeter = 2 * (a.dimension.length + a.dimension.width);
cout << "The area is equal to " << a.results.area
<< "\nThe perimeter is equal to " << a.results.perimeter << endl;
return 0;
}
Comments
Leave a comment