Prerequisites, Goals, and Outcomes
Prerequisites: Students should have mastered the following prerequisite skills.
• Control Structures - For-loops and if-else statements
• Arrays - Access and modification of array elements
• Console I/O - Definition of operator << for class output
• Class Specification - Definition of class member functions given a full class declaration
• Preprocessor - Inclusion of library and header files
Goals: This assignment is designed to help bridge the gap between Java and C++. It emphasizes
the use of C++ header files, basic C++ syntax, and stream-based I/O.
Outcomes: Students successfully completing this assignment would master the following outcomes.
• Understand basic C++ syntax
• Use basic C++ control structures
• Use arrays for sequential access
• Create classes that properly separate definition and declaration into header and
• Use the preprocessor to perform file inclusion
Homework assignments are part of any typical college or university course. This assessment
asks you to construct a simple software tool for maintaining a list of homework assignments.
The program produced in this exercise maintains a list of homework assignments. Using this
program, a user can add homework assignments to the program maintained list. The user can then
view all assignments or assignments due on, before, or after a specific date. The program interacts
with the user through a menu that displays these options. The following screen shot depicts the
program during execution.
A typical use of the application is as follows. The user enters the menu item corresponding to the
task they wish to perform. Depending on the task, the user may have to enter additional input. For
example, to add a homework assignment, the user first enters the menu item number corresponding
to the "add" operation. This is the number 1. Once the user presses the Enter key, the program
prompts the user for the name of the assessment. Once this input is received, the program prompts
the user for the date assigned and then the date due. This completes the addition of the homework.
Each time an operation completes, the program displays another instance of the menu. This loop
continues until the user chooses to quit.
This program includes separate classes for modeling a date, an individual assignment, and a
collection of assignments.
Class date models a calendar date. A date, in this context, includes the day, month, and year. Class
date contains the following members.
• date ();
Default constructor that initializes day, month, and year all to zero
• date (int day, int month, int year);
Three parameter constructor that initializes the day, month, and year to more meaningful
• int compareTo (date another_date);
Function that compares two dates
Class date also dictates how its object instances appear when they are sent to an output stream.
The insertion operator outputs a date using the "mm/dd/yyyy" format. This method declaration
friend ostream& operator<< (ostream <stream, date d);
Class homework models a homework assignment. For each homework assignment, this program
maintains the assignment name, the date assigned, and the date due. Class homework contains the
• homework ();
Default constructor that initializes name to the empty string and the assigned and due dates
to their default values
• homework (string name, date assigned_date, date due_date);
Three parameter constructor that initializes the assignment name, assigned date, and due
• int compareTo (homework another_homework);
Function that compares two homework objects
Similar to class date, class homework also dictates how its object instances are displayed when
they are sent to an output stream. The insertion operator outputs a homework object using the
name: assigned date - due date
This method declaration appears below.
friend ostream &operator<< (ostream &stream, homework h);
Class homeworklist models a list of homework assignments. Class homeworklist maintains this
list of assignments internally using an array. This class limits the number of assignments that it can
store to 50.
Class homeworklist contains the following members.
• homeworklist ();
Default constructor that initializes the size of the list to zero
• bool add (homework h);
This method adds an assignment. It returns true if the add operation succeeds and false
if the maximum number of assignments is already stored.
• homeworklist dueafter (date d);
Returns a new homeworklist containing only those homeworks due after, but not on, the
• homeworklist duebefore (date d);
Returns a new homeworklist containing only those homeworks due before, but not on, the
• homeworklist dueon (date d);
Returns a new homeworklist containing only those homeworks due exactly on the specified
date, but not before or after
Class homeworklist also defines how instances of this class appear when they are sent to an
output stream. The following method outputs each homework object stored in the private array on a
friend ostream &operator<< (ostream &stream, homeworklist hl);
Note to users of Microsoft Visual C++ 6.0:
Certain versions of Microsoft Visual C++ 6.0 incorrectly report an error during the compilation of a
class, when a "using namespace std" directive is placed before a friend operator declaration. The
compiler will incorrectly report that the function, despite being designated as a "friend", cannot
access the private data members of the class. A full description of the problem and a workaround
appears in Q192539. This bug was corrected in Visual Studio 6.0 Service Pack 3. For more
information about Visual Studio service packs, please see the following articles in the Microsoft
194022 INFO: Visual Studio 6.0 Service Packs, What, Where, Why
194295 HOWTO: Tell That Visual Studio 6.0 Service Packs Are Installed
Following is a list of files needed to complete this assessment.
• ae1.rar contains all of the following necessary files:
o solution.exe - This is a sample solution.
o date.h - This file contains the class date declaration. Do not modify this file.
o homework.h - This file contains the class homework declaration. Do not modify
o homeworklist.h - This file contains the class homeworklist declaration. Do not
modify this file.
o main.cpp - This file contains the interactive menu implementation. Function main
exists in this file. Do not modify this file.
To complete this assessment, you will finish the definitions of the three classes date, homework,
and homeworklist. Your implementation of the methods for each class should be placed in
implementation files named date.cpp, homework.cpp, and homeworklist.cpp, respectively.
To begin, verify the files needed for this assessment.
1. Extract the archive to retrieve the files needed to complete this assessment.
2. Run the sample executable by issuing the following command at the command prompt.
3. Interact with the sample executable to become familiar with the expected program
Following is an ordered list of steps that serves as a guide to completing this assessment. Work and
test incrementally. Save often.
1. First, complete the constructors for class date. The default constructor should initialize all
private data members to zero. The other constructor should initialize the private data
members to the corresponding parameter of the constructor. Remember to use initializer
2. Next, complete the class date member function compareTo. This function compares two
date objects. It returns zero if the objects are equal, a negative value if the invoking object
is less than the date given in the parameter, and a positive value if the invoking object is
greater than the date given in the parameter.
3. Then, complete the definition of the insertion operator. This function should output a date
object in the form "mm/dd/yyyy". This completes the implementation of class date.
4. For class homework, begin by implementing the constructors. These implementations
resemble what you did in class date.
5. Next, implement the member function compareTo. To compare two homework objects, you
need only compare their due dates.
6. Then, complete the definition of the insertion operator for objects of type homework. This
function should output a homework object in the form "<name>: <assigned date> - <due
date>". This completes the implementation of class homework.
7. Begin the implementation of class homeworklist by completing the default constructor.
This method only needs to initialize the private data member current_size to zero.
8. Next, complete the implementation of the member function add. Do not allow the method
to store more than the maximum number of homeworks.
9. Then, complete methods duebefore, dueon, and dueafter. Each of these methods
returns a homeworklist object containing a subset of homeworks. These subsets contain
all homeworks due before, on, or after a specified date. The single parameter for each of
these functions specifies the date.
10. Finally, finish the implementation of the insertion operator defined for class
homeworklist. This method should iterate through the array of homework objects,
outputting each on a separate line.
Submit only the following.