Exercise 9.2   A student has found a summer job in a painting company. He is to estimate the amount of paint that the company needs to paint rectangular fields of different sizes. On average, a) 0.2 kg (kilogram) of paint is needed to paint a one square meter area (0.2 kg/m2). b) 22 mg (milligram) of paint is needed to paint a one square centimetres area (22 mg/cm2). c) 19.6 T (Ton) of paint is needed to paint a one square km area (19.6 T/km2). Use the below program to estimate the amount of paint required to paint a rectangle with the length and width that the user will enter from the keyboard. You need to compute the amount of paint in three different units (kg, mg, and Ton).   Use the below program to estimate the amount of paint required to paint a rectangle with the length and width that the user will enter from the keyboard. You need to compute the amount of paint in three different units (kg, mg, and Ton).   // P92.cpp - This program illustrates the use of namespaces         #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. \n";          cout << "Assuming unit is meter \n";          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\n"; 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\n"; return length*width;        }       }       double area_km(double length, double width)       {        cout << "From std namespace, I am sending area in km^2 back\n"; return (length/1000)*(width/1000);        }       In the above program we have asked the user to input the length and width of a rectangle in meters. Then, we have used different name spaces to compute the area of THE rectangle using three different units. As you have noticed, the program that computes the area in namespace cm and meter are both called area, but they perform different computations depending on their definitions in their respective namespace.

Database System Concepts
7th Edition
ISBN:9780078022159
Author:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Chapter1: Introduction
Section: Chapter Questions
Problem 1PE
icon
Related questions
Question
100%

Exercise 9.2

 

A student has found a summer job in a painting company. He is to estimate the amount of paint that the company needs to paint rectangular fields of different sizes. On average, a) 0.2 kg (kilogram) of paint is needed to paint a one square meter area (0.2 kg/m2). b) 22 mg (milligram) of paint is needed to paint a one square centimetres area (22 mg/cm2). c) 19.6 T (Ton) of paint is needed to paint a one square km area (19.6 T/km2). Use the below program to estimate the amount of paint required to paint a rectangle with the length and width that the user will enter from the keyboard. You need to compute the amount of paint in three different units (kg, mg, and Ton).

 

Use the below program to estimate the amount of paint required to paint a rectangle with the length and width that the user will enter from the keyboard. You need to compute the amount of paint in three different units (kg, mg, and Ton).

 

// P92.cpp - This program illustrates the use of namespaces  

 

 

 

#include<iostream>  

 

 

 

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. \n";  

 

 

 

 cout << "Assuming unit is meter \n";  

 

 

 

 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\n"; 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\n"; return length*width;

 

 

 

 }

 

 

 

}

 

 

 

double area_km(double length, double width)

 

 

 

{

 

 

 

 cout << "From std namespace, I am sending area in km^2 back\n"; return (length/1000)*(width/1000);

 

 

 

 }

 

 

 

In the above program we have asked the user to input the length and width of a rectangle in meters. Then, we have used different name spaces to compute the area of THE rectangle using three different units. As you have noticed, the program that computes the area in namespace cm and meter are both called area, but they perform different computations depending on their definitions in their respective namespace.   

Expert Solution
trending now

Trending now

This is a popular solution!

steps

Step by step

Solved in 2 steps with 1 images

Blurred answer
Knowledge Booster
Topological Sort
Learn more about
Need a deep-dive on the concept behind this application? Look no further. Learn more about this topic, computer-science and related others by exploring similar questions and additional content below.
Similar questions
Recommended textbooks for you
Database System Concepts
Database System Concepts
Computer Science
ISBN:
9780078022159
Author:
Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:
McGraw-Hill Education
Starting Out with Python (4th Edition)
Starting Out with Python (4th Edition)
Computer Science
ISBN:
9780134444321
Author:
Tony Gaddis
Publisher:
PEARSON
Digital Fundamentals (11th Edition)
Digital Fundamentals (11th Edition)
Computer Science
ISBN:
9780132737968
Author:
Thomas L. Floyd
Publisher:
PEARSON
C How to Program (8th Edition)
C How to Program (8th Edition)
Computer Science
ISBN:
9780133976892
Author:
Paul J. Deitel, Harvey Deitel
Publisher:
PEARSON
Database Systems: Design, Implementation, & Manag…
Database Systems: Design, Implementation, & Manag…
Computer Science
ISBN:
9781337627900
Author:
Carlos Coronel, Steven Morris
Publisher:
Cengage Learning
Programmable Logic Controllers
Programmable Logic Controllers
Computer Science
ISBN:
9780073373843
Author:
Frank D. Petruzella
Publisher:
McGraw-Hill Education