1: //splitnames.cpp 2: //Separates initials from last names. 4: #include <iostream> 5: #include <string> 6: using namespace std; 9: void DisplayUsage(); 10: /**< 11: Display information on program usage. 12: @return void 13: @pre None. 14: @post Information on program usage has been displayed. 15: */ 18: int main(int argc, char* argv[]) 19: { 20: if (argc == 1) 21: { 22: DisplayUsage(); 23: cout << "Press Enter to continue ... "; cin.ignore(80, '\n'); 24: return 1; 25: } 27: cout << "\nInitials: "; 28: for (int i=1; i<argc; i++) 29: cout << argv[i][0] << " "; 30: //The above line could be replaced by the one below. 31: //cout << *argv[i] << " "; 32: cout << endl; 34: cout << "\nLast Names: "; 35: for (int i=1; i<argc; i++) 36: cout << argv[i]+1 << " "; 37: cout << endl << endl; 38: } 41: void DisplayUsage() 42: { 43: string blankLinesBefore(15, '\n'); 44: string blankLinesAfter(6, '\n'); 45: cout << blankLinesBefore 46: << "\nThis program requires one or more parameters.\nEach " 47: "parameter is assumed to be a concatenated first initial " 48: "and last name.\nThe program separates the inititals from " 49: "the last names and displays two lines\nof output, with " 50: "the initials on the first line and the names on the " 51: "second.\n\n" 52: "\nTypical usage:\n" 53: "\nprompt> split_names PScobey PLingras SKonstantinidis\n" 54: "\nThe output would be the following two lines:" 55: "\nInitials: P P S" 56: "\nLast Names: Scobey Lingras Konstantinidis" 57: << blankLinesAfter; 58: }