// Oldham, Jeffrey D. // 1999 Oct 20 // CS1320 // Frame Name Program #include #include // has setw() #include // has toupper() // Function Declarations void obtainName(char name[], const int nameLength); void upperCase(char name[]); void printFramedName(const char name[]); int stringLength(const char name[]); void printStarLine(const int width); void printFrameEdgeLine(const int width); void printCenteredLine(const char name[]); void printRepeatedChar(const char c, const int width); int main() { const int nameLength = 1000; char name[nameLength]; // Input obtainName(name, nameLength); // Processing upperCase(name); // Output printFramedName(name); return 0; } // preconditions: nm = array to hold a name // nmLength = nm's length void obtainName(char name[], const int nameLength) { cout << "Please enter your name: "; cin >> setw(nameLength) >> name; return; } // precondition: nm holds a null-terminated string // postcondition: string has all uppercase characters void upperCase(char name[]){ int index; for (index = 0; name[index] != '\0'; ++index) name[index] = toupper(name[index]); return; } // precondition: name has a null-terminated string in uppercase // postcondition: printed frame and centered name void printFramedName(const char name[]) { int width = 4 + stringLength(name); printStarLine(width); printFrameEdgeLine(width); printCenteredLine(name); printFrameEdgeLine(width); printStarLine(width); return; } // precondition: width = desired number of asterisks // postcondition: line with "width" asterisks is printed void printStarLine(const int width) { printRepeatedChar('*', width); cout << endl; return; } // precondition: width is positive integer // postcondition: line starting and ending with * with length // equaling "width" void printFrameEdgeLine(const int width) { cout << "*"; printRepeatedChar(' ', width-2); cout << "*" << endl; return; } // precondition: name = null-terminated string // postcondition: prints "* name *" void printCenteredLine(const char name[]) { cout << "* " << name << " *" << endl; return; } // precondition: name = null-terminated string // postcondition: returns the number of characters in name int stringLength(const char name[]) { int index; for (index = 0; name[index] != '\0'; ++index) ; return index; } // precondition: width = nonnegative integer // postcondition: "num" copies of "c" printed void printRepeatedChar(const char c, const int width) { int index; for (index = 0; index < width; ++index) cout << c; return; }