Answer to Question #163528 in C++ for Muhammad Adil

Question #163528

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.


1
Expert's answer
2021-02-15T14:16:04-0500
#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;
}

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be the first!

Leave a comment