0% found this document useful (0 votes)
3 views

Program 8.12 New

Uploaded by

zumar7956
Copyright
© © All Rights Reserved
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
3 views

Program 8.12 New

Uploaded by

zumar7956
Copyright
© © All Rights Reserved
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
You are on page 1/ 4

ASSIGNMENT

Submitted By

Name Hafiz Umar Farooq

Class BBIT (evening)

Roll No F23-BBIT-5043

Subject OOP

Semester 3rd

Submitted To Prof. Faisal Zulfiqar


Write a program that uses three structures Dimension,
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
{
double length;
double width;
};
struct Results
{ double area;
double perimeter;
};
struct Rectangle
{
Dimension dim;
Results res;};
int main()
{
Rectangle rect;
cout << "Enter the length of the rectangle: ";
cin >> rect.dim.length;
cout << "Enter the width of the rectangle: ";
cin >> rect.dim.width;
rect.res.area = rect.dim.length * rect.dim.width;
rect.res.perimeter = 2 * (rect.dim.length + rect.dim.width);
cout << "\nRectangle Details:\n";
cout << "Length: " << rect.dim.length << "\n";
cout << "Width: " << rect.dim.width << "\n";
cout << "Area: " << rect.res.area << "\n";
cout << "Perimeter: " << rect.res.perimeter << "\n";
return 0;
}

You might also like