Computer Science 2210

Total Page:16

File Type:pdf, Size:1020Kb

Computer Science 2210

Computer Science 2210 Homework Exercise 1

Purpose Write, test, and run a C++ program. The program will use a menu-driven approach and give you experience working with the Standard Template Library’s string class. Significant use of the help files will be necessary to learn to use the full capabilities of the STL string class.

Specification Write, debug, test, and run a C++ program that use create and manipulate string objects appropriately in solving this problem. The program will display a menu similar to the following one. Main Menu – Homework One 1. Input a Name 2. Display the Name with the Last Name First 3. Display the Name with the Last Name Last 4. Display the Name as Originally Entered 5. Quit

The name may be entered in any form typically used for names. Examples include the following. Will E. Makit I. M. Smart Chauncey C. Chauncey, III Betty Wont Kute, U. R. Morton Downey, Jr Ima Raven Nutt Colder, I. Ben McPherson Mack Pherson, MD Thayer B. Fuddled Badly, He Wuz Claude Sue N. Lawyer, JD U. Ara Nice Pursun Dr. Heza Dummox I. N. Stein, PhD

Menu choice 2 should result in the name being displayed in a form illustrated by the examples below. Makit, Will E. Smart, I. M. Chauncey, Chauncey C., III Wont, Betty Kute, U. R. Downey, Morton, Jr. Nutt, Ima Raven Colder, I. Ben Pherson, McPherson Mack, MD Fuddled, Thayer B. Badly, He Wuz Claude Lawyer, Sue N., JD Pursun, U. Ara Nice Dummox, Dr. Heza Stein, I. N., PhD

Menu choice 3 should result in the name being displayed in a form illustrated by the examples below. Will E. Makit I. M. Smart Chauncey C. Chauncey, III Betty Wont U. R. Kute Morton Downey, Jr. Ima Raven Nutt I. Ben Colder McPherson Mack Pherson, MD Thayer B. Fuddled He Wuz Claude Badly Sue N. Lawyer, JD U. Ara Nice Pursun Dr. Heza Dummox I. N. Stein, PhD

If the user selects items 2, 3, or 4 before item 1 is selected for the first time, a message should be displayed notifying the user that a name must be entered before it may be displayed. When choice 1 is selected, the program should dynamically create a new Name object with the string representing a name entered by the user as its value. After processing any of items 1 – 4 on the menu, the menu should be redisplayed allowing the user to make another selection. This process should continue until the user selects choice five. At that point, the program should be terminated. For this program and every lab done for this course, your program should initially display a “Welcome Screen” that identifies the program, the author, the author’s e-mail address, the course, and the assignment. It should also contain a paragraph or so describing the purpose of the program and giving any specific information the user needs in order to interact with the program effectively. When the program is being terminated, it should display an “Exit Screen” containing an appropriate message along with any final totals, statistics, or other information that make sense for the project. Both the Welcome and Exit screens should be formatted attractively, be easy to read, and clearly convey the necessary information. You are to develop a Name class that keeps track of the name and its components, and it should provide the functionality to display any name in any of the various forms. The constructor function should accept a string representing a name in any permissible format and decompose it appropriately into its components. When designing a program, one should remember that a function should address only one cohesive issue. For example, a function that reads a set of records into an array, sorts the array, processes the data in each individual record, and prints a report is not well conceived.

Hint One approach one may try is to divide the name into 3 parts (LastName, Suffix, and RestOfName). The Suffix represents items such as Jr., III, PhD, and MD. The RestOfName represents all of the remaining parts of the name not represented by the other two items. It may consist of a first name, a first name and middle initial, two initials, a first initial and a middle name, and many other combinations. These components may be reassembled in the desired order. To determine whether the name is typed in a “lastname, rest” format or in a “rest lastname” format (regardless of suffix), a possible approach is to locate the first comma in the name (if any) and to locate the first space in the name (all leading and trailing spaces should be removed as soon as the name is read). If the first comma comes before the first space, the last name is first. Otherwise, the last name follows the first name. Always use the member functions of the string class to assist in the task of decomposing and recomposing the string, and do NOT try to do everything by brute force.

Deliverables Turn in a CD (formatted with Roxio’s DirectCD or DragtoDisc) or a zip disk with the source code and the executable (.exe file) for the assignment in a directory named HW1. The name of the executable should be HW1.exe. Also, turn in a hard copy (printed) of listings of all of the source code modules that you wrote or modified.

Documentation Follow the course documentation standards for this and every other programming assignment. Every source code or header file and every function (free or member) must be documented according to standards. The content of the documentation should be clear, concise, a complete. Proper documentation that is clear, concise, and complete is worth 25% of your final grade for an assignment.

Recommended publications