CS 12 - Assignment 5 - A class for names
CS 12 Homepage
Due via e-turnin by Saturday 5/1, 11pm
Collaboration Policy:
Collaboration on home programming assignments is strictly FORBIDDEN.
Programs must represent YOUR OWN original work.
Sharing code or team-coding are not allowed. Copying code from ANY source
(any book, current or past students, past solutions, the web, etc.) is not allowed.
Cooperation to the extent of helping to debug, or discussing the general
approach to solving the problem is encouraged, but should never involve
communicating code or even pseudo-code or explicit algorithms. Your code must be unique.
Make sure you review ALL of Chapter 11.2 before you start this assignment.
You may also find it helpful to refer to the cctype functions given
in appendix 4, p. 962.
These functions take a char argument, and require #include<cctype>
in the header.
Display 11.8 (pages 679 to 682) is also very helpful.
Write a class called FullName to handle people's names.
Private mebers: first_name, middle_initial, last_name (all strings) e.g. "Bilbo", "H", "Baggins"
Constructors:
default (no arguments): 3 empty strings
argument of one string: assumed to be last name; leave first_name and middle_initial as empty strings.
argument of two strings: assumed to be in order first name, last name; leave middle_initial
string empty.
argument of string, char, string: assumed to be first name, middle initial (convert from char
to string), and last name.
argument of three strings: assumed to be first name, middle name, last name; extract middle
initial from middle name.
e.g. if "Bilbo", "Harold", "Baggins" are the three arguments, the values stored will be the three strings
"Bilbo", "H", "Baggins"
In all cases, the arguments provided may be any mixture of upper and lower case; you must provide
a helper function (it may be a private member or a non-member function) that converts a mixed-case
string into a proper-case string (i.e. a string whose leading character is upper case, and all the
rest are lower case); of course, the middle initial must be upper case.
Interface functions:
void input(...) - the input must provide three strings, to be treated as in the final constructor above.
void output(...) - the name must be output in my favorite format: Last Name, First Name Middle Initial.
e.g. "Bilbo" "H" "Baggins" would be output as "Baggins, Bilbo H." (note the comma, space and period in
appropriate places)
bool isEqual(...) - two objects of type FullName will be equal ONLY if first_name, middle_initial
and last_name are ALL equal
bool isLessThan(...) - first test last_name; if the two last names are equal, then test first_name;
if they are also equal, then test middle_initial.
bool isGreaterThan(...) - ditto
Make sure you specify clearly in the interface the order of comparison.
Write a driver to illustrate and test your class.
Bonus - 1 point
Use the input file names.txt to populate an array of FullName objects.
Sort the array in alphabetical order, and output the sorted names to the screen, one per line.
NOTE: the linux command line for running your executable (named assn5), and reading the file
names.txt as though it came from the keyboard is
./assn5 < names.txt