|
|
|
|
|
|
|
PrintName(ch);
}
//******************************************************************
void FindLast( /* out */ char& ch ) // First character of last name
// Scans the input stream for the first letter of a person's last
// name by skipping the nonblank characters in the first name,
// then skipping the blanks between the first and last name
// Precondition: Exercise
// Postcondition: Exercise
{
cin.ignore(100, ); // Ignore all characters up to
// (and including) a blank
cin >> ch; // Input first letter of last name,
} // ignoring blanks along the way
//******************************************************************
void PrintName( /* in */ char ch ) // First character of last name
// Prints a person's last name by printing the incoming
// parameter and then reading and echoing each character
// until a newline is found
// Precondition: Exercise
// Postcondition: Exercise
{
while (ch != \n)
{
cout << ch;
cin.get (ch);
}
} |
|
|
|
|
|
|
|
|
Testing: The test data for the Transpose program should include names of different lengths, ranging from a single character to many characters. Some of the names should be preceded by one or more blanks, and the number of blanks separating the two names should be varied. It also would be instructive to try the program with some invalid data, such as a line with no names, one name, more than two names, and so on. |
|
|
|
|
|