Question: I have the following given code (c++), when I enter the length and width I'd like to use, the program executes/quits completly, and I am

I have the following given code (c++), when I enter the length and width I'd like to use, the program executes/quits completly, and I am not understanding what I did wrong to make it do this:

#include

using namespace std;

namespace cm

{

double area(double length, double width);

}

namespace meter

{

double area(double length, double width);

}

double area_km(double length, double width);

int main()

{

double length, width; // dimension of a rectangle

double A; // area of a rectangle

cout << "Enter the length and the width of the rectangle. ";

cout << "Assuming unit is meter ";

cin >> length >> width;

{

using namespace cm;

A = area(length, width);

cout << "Area is: " << A << endl;

}

{

using namespace meter;

A = area(length, width);

cout << "Area is: " << A << endl;

}

A = area_km(length, width);

cout << "Area is: " << A << endl;

return 0;

}

namespace cm

{

double area(double length, double width)

{

cout << "From namespace cm, I am sending area in cm^2 back ";

return (length * 100)*(width * 100);

}

}

namespace meter

{

double area(double length, double width)

{

cout << "From namespace meter, I am sending area in m^2 back ";

return length * width;

}

}

double area_km(double length, double width)

{

cout << "From std namespace, I am sending area in km^2 back ";

return (length / 1000)*(width / 1000);

}

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!