Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

C++ Structures. Would someone be able to help me with this? Any help is apprecia

ID: 3671228 • Letter: C

Question

C++ Structures. Would someone be able to help me with this? Any help is appreciated.

#include <iostream>

#include <iomanip>

using namespace std;

// This program uses a structure to hold data about a rectangle

// PLACE YOUR NAME HERE

// Fill in code to declare a structure named rectangle which has

// members length, width, area, and perimeter all of which are floats

int main()

{

       // Fill in code to define a rectangle variable named box

       cout << "Enter the length of a rectangle: ";

       // Fill in code to read in the length member of box

       cout << "Enter the width of a rectangle: ";

       // Fill in code to read in the width member of box

       cout << endl << endl;

       // Fill in code to compute the area member of box

       // Fill in code to compute the perimeter member of box

       cout << fixed << showpoint << setprecision(2);

       // Fill in code to output the area with an appropriate message

       // Fill in code to output the perimeter with an appropriate message

       return 0;

}

Also, add code to the program above so that the modified program will determine whether or not the rectangle entered by the user is a square. Thank you in advance.

Explanation / Answer

Answer -

#include <iostream>
#include <iomanip>
using namespace std;
struct rectangle // Fill in code to declare a structure named rectangle which has
{
float length,width,area,perimeter;// members length, width, area, and perimeter all of which are floats
};
int main()
{
rectangle box;// Fill in code to define a rectangle variable named box
cout << " Enter the length of a rectangle: ";// Fill in code to read in the length member of box
cin>>box.length;
cout << " Enter the width of a rectangle: ";
cin>>box.width;// Fill in code to read in the width member of box
cout << endl << endl;
box.area=box.length*box.width; // Fill in code to compute the area member of box
box.perimeter=2*(box.length+box.width); // Fill in code to compute the perimeter member of box
cout << fixed << showpoint << setprecision(2);
cout << " Area of a rectangle: "<<box.area;// Fill in code to output the area with an appropriate message
cout << " Perimeter of a rectangle: "<<box.perimeter;// Fill in code to output the perimeter with an appropriate message
if(box.length==box.width)
{
cout << " Entered Rectangle is SQUARE";
}
else
{
cout << " Entered Rectangle is NOT SQUARE";
}
return 0;
}

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote