1: //say_hi4.cpp
2: //Displays a greeting to an individual, using his or her
3: //initials, and (possibly) indented from the left margin.
5: #include <iostream>
6: #include <iomanip>
7: using namespace std;
10: void DescribeProgram();
11: void GetPosition(int& column);
12: void GetInitials(char& firstChar, char& lastChar);
13: void DisplayGreeting(int column, char firstChar, char lastChar);
16: int main()
17: {
18: int column;
19: char firstChar;
20: char lastChar;
22: DescribeProgram();
24: GetPosition(column);
25: GetInitials(firstChar, lastChar);
27: DisplayGreeting(column, firstChar, lastChar);
29: cout << endl;
30: }
33: void DescribeProgram()
34: //Pre: The cursor is at the left margin.
35: //Post: The program description has been displayed,
36: // preceded and followed by at least one blank line.
37: {
38: cout << "\nThis program displays a greeting to some individual, "
39: "using his or her initials\nand positioned at a location on "
40: "the output line chosen by the user.\n\n";
41: }
44: void GetPosition(/* out */ int& column)
45: //Pre: none
46: //Post: "column" contains an integer from 1 to 68 (inclusive)
47: // entered by the user, and the input line has been cleared.
48: {
49: cout << "Enter column (1 to 68) where greeting is to start: ";
50: cin >> column; cin.ignore(80, '\n'); cout << endl;
51: }
55: void GetInitials(/* out */ char& firstChar, /* out */ char& lastChar)
56: //Pre: none
57: //Post: "firstChar" and "lastChar" each contain a capital letter
58: // entered by the user, and the input line has been cleared.
59: {
60: cout << "Enter the (capital) initials of the person to greet: ";
61: cin >> firstChar >> lastChar; cin.ignore(80, '\n'); cout << endl;
62: }
65: void DisplayGreeting(/* in */ int column,
66: /* in */ char firstChar,
67: /* in */ char lastChar)
68: //Pre: "column", "firstChar" and "lastChar" have been initialized, with
69: // 1<=column<=68, 'A'<=firstChar<='Z', and 'A'<=lastChar<='Z'.
70: //Post: A greeting has been displayed, using the initials in
71: // "firstChar" and "lastChar", starting in position "column",
72: // and preceded and followed by at least one blank line.
73: {
74: cout << endl;
75: cout << setw(column-1) << ""
76: << "Hi there, " << firstChar << lastChar << "!\n\n";
77: }