CS 12 - Assignment 6 - Strings
CS 12 Homepage
Due Friday, February 20th, 11pm, electronic turnin
Collaboration Policy:
This program is designed in part for us to determine how well you
are able to program. Thus, every part of the program should be your own
original work, and should not be substantially similar to other students'
code, or code from books, previous solutions, the web, etc. -- like other
skills (e.g., surgery), the only way to really learn programming is to
do it yourself. Some collaboration is OK, including discussing the general
solution method, and some debugging assistance after a student has tried
hard to solve the bug him/herself. We DO encourage you to work with
others nearby, so if you get stuck, you can get help. But you should
not show your code to another student in order to help that student.
The bottom line is you can talk about the code as much as you like,
but you may not write any code for another student, or let another student
copy your code.
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.
The class must be built in separate header and implementation files.
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.
Overloaded operators:
istream& >> - the input must provide three strings, to be treated as in the final constructor above.
ostream& << - 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 == - two objects of type FullName will be equal ONLY if first_name, middle_initial
and last_name are ALL equal
bool < - 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 > - ditto
Write a driver to illustrate and test your class.
Bonus - 1 point
Make an input file of at least 10 names, and use it to populate an array of FullName objects.
Sort the array in alphabetical order, and output the sorted names to the screen, one per line.