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
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started