Comp 272 Program 1 Dordal Sept 9, 2002 Due: Setp 20, 2002 Note that the due date is a Friday; programs must be emailed to me by then. All you should send is your enroll.cpp file, and optionally any output. I don't need your project (.dsw) file, or the ParseLine or Date files. Your program is to read in a sequence of records, in text format. Each record consists of one line, containing a name and a date. You will then create an object for each record processed, put each such object into a vector, and then sort everything by date. In other words, this assignment is intended to familiarize you with classes, constructors, Horstmann's Date class, strings, vectors, and miscellaneous other C++ details. We shall assume that the dates represent enrollment dates, in some sort of database. Records are in the following format; items in brackets are optional. [firstname [middlename]] lastname [month day year] Names have only letters a-z,A-Z in them; the date fields have only digits. You can identify name fields because they begin with letters. Only the last name is required. ; if there is only one name field it is lastname. If there are two namefields they are "firstname lastname". If all three were included, then middlename was provided. The logic for dates is a little simpler: either there is a full date provided, or nothing. Here are some examples peter lars dordal 1 27 1999 fred smith 2 13 2000 // no middlename bush 4 1 2000 // no first or middle name sauron // no month or day or year phoebe b beebee // full name but no date j fred muggs 3 14 1842 // another full name + date Note that it is illegal to have four or more name fields, or for the number of date fields to be 1, 2, or >=4. Note also that you have to read all the names before you can figure out which is the lastname; the ParseLine class will help you here. If the date fields are missing entirely, then today's date is to be used. The Date class contains a static today() function for obtaining this date: d = Date::today(); Your program is to * read in the records * for each record construct an object of class type Enroll, below * correctly handle all the cases of potentially missing optional data * store all the Enroll records in a Vector * sort the records by date * print them out The biggest single step is the constructor for Enroll. To help you here, I am in the process of writing a ParseLine(istream & in) function, that reads a line from the input file and returns a Vector of String, one String for each whitespace-delimited "word" in the input line. Thus, if the input line is peter lars dordal 1 27 2002 then ParseLine(cin) returns a vector 0 "Peter" 1 "Lars" 2 "Dordal" 3 "1" 4 "27" 5 "2002" Note that the numbers are represented in *string* format; you will need to convert them to numbers to create Date objects. I've provided int atoi(string s) for this conversion. You can tell how many strings were read in by looking at the .size() value of the vector returned. You will still have some logic to implement to figure out when the names stop and the dates begin, and what values are missing, but this should be relatively straightforward based on examiningthe first character of each string and checking whether it is a letter or number. The utility functions isalpha(char ch) and isdigit(char ch) will be useful here. You will also need to copy the date.h, ParseLine.cpp, date.cpp, and setup.h files; you can either #include "date.h" // note "" instead of <> and add date.cpp to your project, or just #include "date.cpp" and ignore date.h and separate compilation. You will need a class Name, to hold the name fields (anything not provided is to be represented as the empty string), and a class Enroll, containing the Name and Date. Here are the class definitions; note that they consist of constructors and (field) accessors only. class Name { private: string _fname; string _mname; string _lname; public: Name(string first, string mid, string last) : _fname(first), _mname(mid), _lname(last) {} string fname() {return _fname;} string mname() {return _mname;} string lname() {return _lname;} }; class Enroll { private: Name _name; Date _enrolldate; public: Enroll(Name n, Date d) : _name(n), _enrolldate(d) {}; Enroll(string fname, string mname, string lname, Date d) : _name(fname, mname, lname), _enrolldate(d) {} Enroll(vector v); // this is the one you actually *use* string fname() {return _name.fname();} string mname() {return _name.mname();} string lname() {return _name.lname();} Date enrolldate () {return _enrolldate;} }; The function Date::today() returns todays' date. If d1 and d2 are dates, d1.compare(d2) returns a value <0 if d1 comes before d2, and a value >0 if d1 comes after d2, and the value 0 if d1=d2. Note that you can *not* write "d1 #include #include using namespace std; #include "date.cpp" #include "parseline.cpp" class Name { private: string _fname; string _mname; string _lname; public: Name(string f, string m, string l) : _fname(f), _mname(m), _lname(l) {} Name() {_fname = _mname = _lname = "";} string fname() {return _fname;} string mname() {return _mname;} string lname() {return _lname;} }; class Enroll { private: Name _name; Date _enrolldate; public: Enroll(Name n, Date d) : _name(n), _enrolldate(d) {} Enroll(vector v); // the big one string fname() {return _name.fname();} string mname() {return _name.mname();} string lname() {return _name.lname();} Date enrolldate () {return _enrolldate;} }; // error is handy for printing errors void error(string mesg, vector v) { cout << "Format error: " << mesg << endl; cout << "Line: \"" ; int i=0; while (i A; while (true) { vector v = ParseLine::parseline(cin); if (v.size() == 0) break; // true at end of file A.push_back(Enroll(v)); // slick, huh? } // now sort it and print it out } One last thing: a basic example of a simple sort (selection sort). Here we're sorting a vector of numbers, not classes; you will have to make appropriate modifications: void sort (vector &A) { int i, j, indexofsmallest; for (i=0;i