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...
**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 =...
Can someone please write me a header file in c++ using the quadratic probing hash method...
Can someone please write me a header file in c++ using the quadratic probing hash method that will work with this program? #include "hash.h" #include <algorithm> #include <cstdlib> #include <ctime> #include <iostream> #include <list> using namespace std; const size_t KEYS_COUNT = 1000; // Number of keys to generate for testing string random_key(); class HashCheck { private: size_t count; Hash hash; public: HashCheck(Hash& h) { count = 0; hash = h; } void operator() (const string key) { if (hash[key] !=...
Study the file polygon.h. It contains the header file for a class of regular polygons. Implement...
Study the file polygon.h. It contains the header file for a class of regular polygons. Implement the methods, and provide a driver to test it. It should be in C++ polygon.h file- #ifndef POLY_RVC_H #define POLY_RVC_H #include <iostream> using namespace std; class Polygon { public:    Polygon();    Polygon(int n, double l);    //accessors - all accessors should be declared "const"    // usually, accessors are also inline functions    int getSides() const { return sides; }    double getLength()...
Create a Word file containing the following: The full name of the “test subject” The test...
Create a Word file containing the following: The full name of the “test subject” The test subject is a person, not yourself, who can say the names of the products. The best test subject is one who is adamant about being an expert who can distinguish brand A from B. You cannot be the test subject because you generate the sequence, and the test subject cannot see it for an unbiased test. Pets and babies are not allowed as they...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT