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 */...
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...
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...
In a header file Record.h, create a Record structure that contains the following information: recordID, firstName,...
In a header file Record.h, create a Record structure that contains the following information: recordID, firstName, lastName, startYear. recordID is an integer. In testRecord, first create a record (record1) using “normal” pointers. Set the values to 1001, Fred, Flintstone, 1995 In testRecord, create a new record (record2) using a unique smart pointer. Set the values to 1002, Barney, Rubble, 2000 Create a function (or functions) that will print the records to any output stream. Since the print function does not...
// File name: Person.h // Person class declaration. Person is the base class. #pragma once #include...
// File name: Person.h // Person class declaration. Person is the base class. #pragma once #include <iostream> using namespace std; class Person { private:         string fName;         string lName;         int birthYear;         int birthMonth;         int birthDay; public:         Person();         void setName(string, string);         void setBirthDate(int, int, int);         string getFullName();         string getBirthDate(); }; // File name: Person.cpp // Person class definition. Person is the base class. #include "Person.h" Person::Person() { fName = ""; lName =...
Using C++ In a separate header file: Create a new type called "Patient" - you must...
Using C++ In a separate header file: Create a new type called "Patient" - you must use a  class. Give your "Patient" type at least five (5) member elements of your choosing, and at least one member function. You should have member elements to hold patient name, and visitReason (which can change), and other items of your choosing. In your cpp file: Create at least one instance of Patient type (example: CurrentPatient ). Create a menu-driven program OF YOUR OWN DESIGN...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT