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

Can anyone see who posts the question Can anyone see who posts the question Can

ID: 3744337 • Letter: C

Question

Can anyone see who posts the question Can anyone see who posts the question Can anyone see who posts the question Can anyone see who posts the question Can anyone see who posts the question #include estdlib> #include #include using namespace std; This program reads a width and height of a rectangle. It computes and prints the area, perimeter and length of the diagonal of the rectangle. Written by: Your name here Date written: Current date here void compute_rectangle (double width, double height); int main() double width, height, area, perimeter, diagonal; II width of the rectangle entered by the user II height of the rectangle entered by the user I/ area of the given rectangle II perimeter of the given rectangle diagonal of the given rectangle cout width; cout height; compute rectangle (width, height); cout

Explanation / Answer

Q1.

Enter the width of the rectangle: 10.0

Enter the height of the rectangle: 10.0

The area is: 0

The perimeter is: 0

The diagonal is: 0

In this case function compute_rectangle(double ,double) couldn’t store any values and not return any values. All the changes are done only inside the compute_rectangle(double,double) this function only not outside the function.

————————————————————————————————————————————

Q2.Following outputs are generated as required changes are done as per question no2.

For Area Output is :

Enter the width of the rectangle: 10.0

Enter the height of the rectangle: 10.0

The area is: 100

The perimeter is: 0

The diagonal is: 0

For Perimeter OutPut is :

Enter the width of the rectangle: 10.0

Enter the height of the rectangle: 10.0

The area is: 0

The perimeter is: 40

The diagonal is: 0

For Diagonal OutPut is :

Enter the width of the rectangle: 10.0

Enter the height of the rectangle: 10.0

The area is: 0

The perimeter is: 0

The diagonal is: 14.1421

Ans:

This strategy never work for this function cause any function will return

only one values but in our case it returns three values so this case other

parameter values are zero.

—————————————————————————————————————————————

Q3.

#include <cstdlib>

#include <cmath>

#include <iostream>

using namespace std;

void compute_rectangle(double, double, double&, double&, double& );

int main()

{

double width,height,area,perimeter,diagonal;

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

cin>>width;

cout<<"Enter the height of the rectangle: ";

cin>>height;

compute_rectangle(width,height,area,perimeter,diagonal);

cout<<" The area is: "<<area;

cout<<" The perimeter is: "<<perimeter;

cout<<" The diagonal is: "<<diagonal;

return 0;

}

void compute_rectangle(double width,double height,double& area,double& perimeter,double& diagonal )

{

area = width*height;

perimeter=width*2+height*2;

diagonal=sqrt(width*width+height*height);

}

OutPut:

Enter the width of the rectangle: 10.0

Enter the height of the rectangle: 10.0

The area is: 100

The perimeter is: 40

The diagonal is: 14.1421

—————————————————————————————————————————————

Q.4

The height and width parameters be any call by values or call by reference.

Same values are used for three functions which are area ,perimeter and diagonal but

there are the R-Values not L-Values.

Q5.

The function call the arguments are name formal and actual binds with eatch other and

The call by reference the what erver chages are done in formal paramertes all changes are done in

actual parameter.

Outputs are same in this case also.

Program:

#include <cstdlib>

#include <cmath>

#include <iostream>

using namespace std;

void compute_rectangle(double&, double&, double&, double&, double& );

int main()

{

   double width,height,area,perimeter,diagonal;

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

   cin>>width;

   cout<<"Enter the height of the rectangle: ";

   cin>>height;

   compute_rectangle(width,height,area,perimeter,diagonal);

   cout<<" The area is: "<<area;

   cout<<" The perimeter is: "<<perimeter;

   cout<<" The diagonal is: "<<diagonal;

   return 0;

}

void compute_rectangle(double& width,double& height,double& area,double& p,double& diagonal )

{

//   double area ,perimeter,diagonal;

   area = width*height;

   p=width*2+height*2;

   diagonal=sqrt(width*width+height*height);

}

OutPut:

Enter the width of the rectangle: 10.0

Enter the height of the rectangle: 10.0

The area is: 100

The perimeter is: 40

The diagonal is: 14.1421

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