Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

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

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Database Systems For Advanced Applications 15th International Conference Dasfaa 2010 Tsukuba Japan April 2010 Proceedings Part 1 Lncs 5981

Authors: Hiroyuki Kitagawa ,Yoshiharu Ishikawa ,Wenjie Li ,Chiemi Watanabe

2010th Edition

3642120253, 978-3642120251

More Books

Students also viewed these Databases questions