Question: C++ Write a function that receives a phone number, a name, an email, and an ostream object and writes a single, formatted line to the
C++
Write a function that receives a phone number, a name, an email, and an ostream object and writes a single, formatted line to the ostream object. The ostream object is where you want the data to be written to.
Using ostream for the last parameter allows you to send cout or an ofstream object. This makes it easy to test this function with cout before you try it with a file. The ostream object must be passed by reference.
The format of the output is very specific. Use setw to make sure everything fits as expected on the line. Each line is to contain the following.
- a phone number
- lines up on the right
- uses 16 spaces
- two blank spaces
- a name
- lines up on the left
- uses 19 spaces
- when a name is longer than 19 characters, print the first 16 characters of the name followed by three dots (...).
- two blank spaces
- an email
- lines up on the left
- a carriage return (\ or endl)
Add the function prototype in the directories.h file.
void WriteFormatted(std::string phone, std::string name, std::string email, std::ostream& out);
Write the function definition in the directories.cpp file.
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
