Question

In: Computer Science

Create a Namespaces.h header file containing a namespace declaration yourname. The declaration should include: a method...

  1. Create a Namespaces.h header file containing a namespace declaration yourname. The declaration should include:

    1. a method with the signature void message (string, ostream &) that prints a string to the output stream.

    2. a method with the signature void message (double, ostream &) that prints a double to the output stream.

  2. Create a testNamespaces.cpp that uses the yourname namespace, and invokes the message() string method with a message of your choice and cout as input parameters, and invokes the message double method with a double of your choice and cout as input parameter.

    NOTE: You should not use the “using namespace” directive in your header file.

  3. Modify Namespaces.h to define PI as 3.14159, and MYNAME as your name, outside of the yourname namespace.  

  4. Modify your testNamespaces.cpp and add a new message method that has the signature void message(double, ostream &). This message should also print the message that it is the message function in testNamespaces.cpp.

  5. In addition to the previous calls to message, call this new message function with PI and cout as input parameters, and call message with MYNAME and cout as input parameters.

Solutions

Expert Solution

Solution :

Given below is the code for the question.
In both the files, replace all occurences of the word YOURNAME with your actual name (for e.g. John). Let me know if you have any issues.
Please do rate the answer if it was helpful. Thank you


Namespaces.h
------

#ifndef Namespaces_h
#define Namespaces_h
#include <iostream>

#define PI 3.1415
#define MYNAME "YOURNAME"

namespace YOURNAME{
void message(std::string str, std::ostream &out){
out << str << std::endl;
}
  
void message(double val, std::ostream &out){
out << val << std::endl;
}
  
}
#endif /* Namespaces_h */

testNamespaces.cpp
--------------
#include <iostream>
#include "Namespaces.h"

using namespace std;

int main(){
YOURNAME::message("hello world", cout);
YOURNAME::message(PI, cout);
YOURNAME::message(MYNAME, cout);
return 0;
}


output
-----
hello world
3.1415
YOURNAME

Thank you...!


Related Solutions

Create a header file, iofunctions.h, containing the following function prototypes. (don't forget to follow the coding...
Create a header file, iofunctions.h, containing the following function prototypes. (don't forget to follow the coding style) int readfile( struct pokemon pokearray[ ], int* num, char filename[ ] ); int writefile( struct pokemon pokearray[ ], int num, char filename[ ] ); Then, create a source file, iofunctions.c, defining the functions above. Specifications The readfile function will read the data from a text file and store it in the array called by pokearray. It must not load the pokemons more than...
using the header: #include <pthread.h> // This is a header file for a Read/Right Lock Library....
using the header: #include <pthread.h> // This is a header file for a Read/Right Lock Library. Your C code //SHOULD access your routines using these exact function // prototypes typedef struct RW_lock_s { } RW_lock_t; void RW_lock_init(RW_lock_t *lock); /* This routine should be called on a pointer to a struct variable of RW_lock_t to initialize it and ready it for use. */ void RW_read_lock(RW_lock_t *lock); /* This routine should be called at the beginning of a READER critical section */...
Given the header file (grid.h) and the source file,(grid.cpp) create the file trap.cpp. Here are the...
Given the header file (grid.h) and the source file,(grid.cpp) create the file trap.cpp. Here are the requirements for trap.cpp: Write a main program in a file called trap.cpp that solves the following scenario, using your Grid class: Giant Mole People have risen from their underground lairs and are taking over the world. You have been taken prisoner and placed in an underground jail cell. Since the Mole People are blind and don't know how to build doors, your cell has...
Create a program that: 1. Has a main() 2. Includes the proper header and namespace declarations...
Create a program that: 1. Has a main() 2. Includes the proper header and namespace declarations 3. Create a program using the following requirements:     a. Request a 7-character telephone number from the user using an informational prompt         and translate the characters into a 7-digit telephone number.                The user will not enter the dash, the program will format the telephone number properly.         For example, aaadddd would translate to 222-3333.                Do not code anything for...
Using C++ Create the UML, the header, the cpp, and the test file for an ArtWork...
Using C++ Create the UML, the header, the cpp, and the test file for an ArtWork class. The features of an ArtWork are: Artist name (e.g. Vincent vanGogh or Stan Getz) Medium (e.g. oil painting or music composition) Name of piece (e.g. Starry Night or Late night blues) Year (e.g. 1837 or 1958)
The requirements for this program are as follows: Create a header file named “Employee.h”. Inside this...
The requirements for this program are as follows: Create a header file named “Employee.h”. Inside this header file, declare an Employee class with the following features: Private members a std::string for the employee’s first name a std::string for the employee’s last name an unsigned int for the employee’s identification number a std::string for the city in which the employee works Public members A constructor that takes no arguments A constructor that takes two arguments, representing: the employee’s first name the...
**C++ program** Please provide a header file(bubble_sort.h) and a program file(bubble_sort.cpp). Also include notes to explain...
**C++ program** Please provide a header file(bubble_sort.h) and a program file(bubble_sort.cpp). Also include notes to explain code and output screenshots. Please use Bubble Sort code provided. Write a program for sorting a list of integers in ascending order using the bubble sort algorithm. Requirements Implement the following functions: Implement a function called readData int readData( int *arr) arr is a pointer for storing the integers. The function returns the number of integers. The function readData reads the list of integers...
Complete the task below C++ This header file declares the Comp315Array Class **************************/ //Include the libraries...
Complete the task below C++ This header file declares the Comp315Array Class **************************/ //Include the libraries #include <iostream> //Allow the use of cin and cout //Declare namespace std for using cin and cout using namespace std; //Class declaration class Comp315Array{ //Public members public: /**************** Default Constructor Task: assign 0 to the array size *********/ Comp315Array(); /**************** Constructor Task: Define an int array of size n *********/ Comp315Array(int n); /***************** getSize method Task: return the array size ******************/ int getSize(); /*****************...
Write a C++ program based on the cpp file below ++++++++++++++++++++++++++++++++++++ #include using namespace std; //...
Write a C++ program based on the cpp file below ++++++++++++++++++++++++++++++++++++ #include using namespace std; // PLEASE PUT YOUR FUNCTIONS BELOW THIS LINE // END OF FUNCTIONS void printArray(int array[], int count) {    cout << endl << "--------------------" << endl;    for(int i=1; i<=count; i++)    {        if(i % 3 == 0)        cout << " " << array[i-1] << endl;        else        cout << " " << array[i-1];    }    cout...
C++ exercise: The statements in the file main.cpp are in incorrect order. using namespace std; #include...
C++ exercise: The statements in the file main.cpp are in incorrect order. using namespace std; #include <iostream> int main() { string shape; double height; #include <string>    cout << "Enter the shape type: (rectangle, circle, cylinder) "; cin >> shape; cout << endl;    if (shape == "rectangle") { cout << "Area of the circle = " << PI * pow(radius, 2.0) << endl;    cout << "Circumference of the circle: " << 2 * PI * radius << endl;...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT