Signature block

For C++ class we were assigned to write a simple introductory C++ program.
One of the requirements was that a signature block be included with the output of the program. Here is what I came up with:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
#include <iostream>
#include <string>
using namespace std;

int main()
{
	// signature block
	cout << "-----------------------------" << endl;
	cout << "Jim Jones" << endl;
	cout << "[email protected]" << endl;
	cout << "C++ Programming" << endl;
	cout << "Fall 2013" << endl;
	Cout << "-----------------------------" << endl << endl;
	
	// request user's name and store in a variable
	string name;
	cout << "What is your name? ";
	getline( cin, name );
	
	// print "Hello" and the user's name
	cout << "Hello, " << name << "!" << endl;
		
	return 0;
}


I lost points on the signature block portion. Here are the comments I got with my grade:

"Signature block implementation should be separate file. Good job using getline. Use strings or single formatted line for signature block instead of line-by-line outputs."

Being new to C++, I'm not sure exactly what the instructor is looking for. There were no specific instructions on how to implement the signature block and, after I emailed my instructor requesting more info, he has not written back.

So, I was hoping someone on this forum could provide some insight. How can I implement the signature block in a separate file? Should I create a signature block class and create a new signature block object in the main function?

Thanks for any suggestions.
Last edited on
The instructor means that you have to put your signature in a file that can be included in your program, so that, for example, in a work environment, not all people will be stuck with your signature, and will only have to change a single file to change the signature. So first, put your signature in function:

1
2
3
4
5
6
7
8
9
void DoSign()
{
	cout << "-----------------------------" << endl;
	cout << "Jim Jones" << endl;
	cout << "[email protected]" << endl;
	cout << "C++ Programming" << endl;
	cout << "Fall 2013" << endl;
	cout << "-----------------------------" << endl << endl;
}


And then put all that in a separate file, say "JimSignature.h", and in your main.cpp:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
#include <iostream>
#include <string>

using namespace std;

#include "JimSignature.h"

int main()
{
	// signature block
        DoSign();
	
	// request user's name and store in a variable
	string name;
	cout << "What is your name? ";
	getline( cin, name );
	
	// print "Hello" and the user's name
	cout << "Hello, " << name << "!" << endl;
		
	return 0;
}


So now if another person takes over your program, they could just change the include file "JimSignature.h" and they'll have a different signature.

Of course, this is not the proper way to do signatures, but it's just for learning purposes.
Last edited on
Nice. Thanks for the help.

The instructor also didn't seem to like how I used multiple cout lines. In the comments with my grade he wrote, "Use strings or single formatted line for signature block instead of line-by-line outputs."

Does he mean just put the entire message into a string variable?
1
2
3
4
cout << 
  "-------------------\n"
  "Jimtastically Done!\n"
  "-------------------\n";

All one string.

[edit] You could also make your function just return the string itself:

1
2
3
4
5
6
7
const char* JimSignature()
{
  return
    "-------------------\n"
    "Jimtastically Done!\n"
    "-------------------\n";
}
 
cout << JimSignature();


Hope this helps.
Last edited on
That helps a lot. Thanks! The newline character looks much neater and I'm assuming its cheaper than multiple calls to cout.
Topic archived. No new replies allowed.