CIS 459.22 LAB4
*************************************
Assigned:
Due:
*************************************
Goal
·
To use simple
operator overloading and friend function
Points
This lab is worth 100 points.
Description
First level main menu:
1. Date Operations
2. Time Operations
3. Quit
The program should proceed based on the user’s choice.
a) If the user chooses “1” (Date Operations), the program
enters the 2nd level menu
1. Enter two new Date object
2. Add days to the 1st Date object
3. Add days to the 2nd Date object
4. Assign the 2nd Date object to the 1st one
5. Print the 1st and 2nd Date objects
6. Back to main menu
b) If the user chooses “2” (Time Operations), the program
enters the 2nd level menu
1. Enter two new Time objects
2. Add hours to the 1st Time object
3. Add hours to the 2nd Time object
4. Assign the 2nd Time object to the 1st one
5. Print the 1st and 2nd Time objects
6. Back to main menu
c) If the user chooses “3” (Quit), exit from the program.
1. Add operator = to do assignment
2. Add operator += to add days to a Date object
3. Add operator << to print out a Date object
4. Add operator >> to read in a Date object
The interface of class Date is given as
follows.
class Date
{
protected:
unsigned day;
unsigned month;
unsigned year;
//display an error message if the date format
given by the user is invalid
void errmsg(const char* msg);
//set this
object to the specified date
<return type> set(const char* mmddyy);
public:
Date() ;
// default constructor should set the Date object to
Date(const Date
&d); // copy constructor should also
print "The Date copy constructor is called now"
Date(const char *mm_dd_yy); //
constructor that initializes with the characters input
//
destructor also should print "The Date destructor is called now."
Date& operator= (const Date &d);
// performs assignment between two
Date objects
Date& operator+= (int
days); // adds days to the current Date
object
// Note: 1. We should take care of the fact that
we are only dealing with dates between
// Note: 2. Be careful about going beyond the
month. For example, August 31th plus one day gives
September 1st, and the special case with leap year (adding one day
to 02/28/04 gives us 02/29/04, while adding one
day to 02/28/03 leads to 03/01/03)
// Note: 3. Be careful about going beyond the
year. For example,
friend istream&
operator>> (istream &in, Date &d);
// reads "mm/dd/yy"
from cin and sets the Date object to that value if
correct
friend ostream& operator<< (ostream
&out, const Date &d);
// formats
and prints the Date object to out as mm/dd/yyyy in
place of display function
};
NOTE: Please pay attention to the members written
in bolds, which identify the extensions from the Date
class in lab3.
class Time : public
Date
{
protected:
int
hours;
int minutes;
int seconds;
//set this
object to the specified time according to the
input string
<return type> set(const char* inputTime);
public:
Time(); // default constructor
should set the Time object to
Time(const Time
&t); // copy constructor should also
print "The Time copy constructor is called now."
Time(const char *inputTime);
// constructor that initializes with the characters input
// destructor
also should print "The Time destructor is called now."
Time& operator= (const Time &t); // performs the assignment
between two Time objects
Time& operator+= (int hours); //
adds hours to the time, taking care of the validity of the time after
addition
friend istream& operator>> (istream
&in, Time &t);
// reads "hh:mm:ss
mm/dd/yy" from cin and
sets the time to that value if correct
friend ostream& operator<< (ostream
&out, const Time &t);
//
formats and prints the Time object to out as "hh:mm:ss
mm/dd/yyyy" in place of display function
};
NOTE: Please pay
attention to the members written in bolds, which identify the extensions from
the Time class in lab3.
o class Date: date.cpp for class implementation of class Date; date.h for class interface definition
o class Time: time.cpp for class implementation of class Time; time.h for class interface definition
o lab4.cpp for main function
g++ -o
lab4 lab4.cpp time.cpp date.cpp <return>
Remove all compilation errors
and warning messages before running the program. Recompile each time you make a change to the
program. By finishing, your program should compile and return to the prompt
without displaying any error messages.
lab4 <return>
Test your program with several
cases you may think of, such as "
· You SHOULD also test your program using a script similar to the sample grading script
create a file called gradingLab4 similar to the sample grading script
create a file called testCasesLab4 similar to sample testCases with different sample inputs
chmod +x gradingLab4
You can then test your program by typing ./gradingLab4 at the command prompt
The various inputs will automatically be taken from the testCasesLab4 file
Sample output is given in sample output
Submission
submit classname labname files-to-submit
where,
classname is the name of the CIS 459.22 section that you are enrolled in. Your classname is c459.22ab .
labname is the lab you are working on (lab1, lab2, etc.). For this lab, labname is lab4 .
files-to-submit is a list of files that make up the lab. For now, it contains lab4.cpp, time.cpp, time.h, date.cpp, and date.h.
NOTE:
1. All of the files in a lab MUST be submitted using one
command. If you use two submit
commands, the second one erases the files from the first submission.
2. Your programs MUST be submitted in source code form. Make sure that you submit the source files only. Do not submit the object file. If you submit the object code, your lab submission will be considered as invalid.
3. Each submit command MUST be entered on one line without pressing Enter. If the line you are entering is too long, it wraps onto the next line.
Submitting Lab4
To submit your lab for grading, use the following command from the directory which contains all files for this lab:
submit c459.22ab lab4 lab4.cpp time.cpp time.h date.cpp date.h