Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Your program will include four classes: DigitalTime, TimeInterval, DaysOfWeek, and Course. The header files for DigitalTime and TimeInterval are provided. Note A description of the

Your program will include four classes: DigitalTime, TimeInterval, DaysOfWeek, and Course. The header files for DigitalTime and TimeInterval are provided. Note A description of the DaysOfWeek and Course classes are provided below. You will need to implement all four classes, and write the header file for DaysOfWeek and Course. Finally, you will write a main program that uses a vector of Course objects to implement the application described below. You will submit a tar file (or zip file) containing the 4 header files and the 5 source files and a make file. More information on using the Unix tar utility will be provided during lab. A brief description of how to use tar for this assignment appears at the bottom of this document.

The Course class

The Course class represents a single course entry in a schedule of classes. Its member variables should include:

A course code (a string of alpha-numeric characters such as COMPSCI337)

A section, which is a string of 3 numeric characters

The days of the week the course meets (such as MW, TR, MWF, etc.). This is a DaysOfWeek object

The time the course meets (such as 09:30-10:45 or 17:00-19:50). This is a TimeInterval object

The instructor, a string of alphabetic characters which uniquely identifies an instructor

Besides the normal set/get member which you will need to implement for the Course class, and any constructors yo wish to use, you will also need to implement 2 additional member functions:

An isOverlap member function, which takes a second course object. If the 2 courses have the same instructor and overlapping times, the isOverlap member function returns true. Times a and b overlap if the start of a is less than or equal to the end time of b and the end time of a is greater than or equal to the start time of b. Otherwise, it returns false.

An isMatch member function, which takes a second course object. If the 2 courses have the same course code and section, the isMatch member function returns true. Otherwise, it returns false.

Use isOverlap to overload the && operator. Use isMatch to overload the == operator.

The DaysOfWeek class

Logically, a DaysOfWeek object is a six element Boolean array. Each of the days of the week, except for Sunday, is represented by a letter code: M=Monday, T=Tuesday, W=Wednesday, R=Thursday, F=Friday, S=Saturday. Each day is either present(on), or absent (off). It is possible to have a DaysOfWeek object with no days present, and such an object is produced by the default constructor for the class.

In addition, you should implement a constructor and a set function that takes a string and, for each day of the week, sets that day to be present if its code letter (in upper or lower case) appears in the input string, and absent otherwise.

The get member function returns a string of code letters for each day present in the object, all uppercase, in chronological order (i.e. MTWRFS).

The input member function takes an istream object, removes the first whitespace delimited token, and sets the object using this token as input.

The output member function takes an ostream object, and sends the results of get to that ostream.

The isEqual member function returns true for if the host object and DaysOfWeek argument have identical present days, false otherwise.

The isOverlap function member function returns true for if the host object and DaysOfWeek argument have at least one common present day, false otherwise. Note that this means that 2 DaysOfWeeks objects with no present days do not overlap (online courses).

Finally, you should overload the &&, ==, and != operators as non-member functions using isOverlap for && and isEqual to implement == and !=.

Functional Requirements

Your program will be driven by a command line prompt. The valid commands are add, clear, import, export, remove, and validate. Command parameters are denoted by < >.

add

If any of the inputs are not valid, the program responds with an error message. If an course with the same course code and section already exists an error is displayed. Otherwise the course is added to the schedule. For example: add MW 09:30 10:45 COMPSCI337 401 ROCK The letter O is used to denote an empty set of days of the week. For example, add O 00:00 00:00 COMPSCI140 901 ROCK This would be useful for online courses, which have no set meeting time.

clear Delete all courses from the current schedule.

export Save the contents of the schedule vector to an output file only if the schedule can be validated. If the schedule is not valid, error messages are displayed describing the problem(s) (see validate below). If the given file name is invalid (file exists, bad path, no permissions, etc.) an error message is displayed. Otherwise, the file is created and filled with the courses from the schedule in the schedule file format (SFF) described below.

For example: export class.txt

import Read the contents of the given file assuming it is a valid SFF If a line of the input file contains an invalid SFF course entry, and error message displays the line number and contents of the line and identifies which field triggered the error, then file processing continues with the next line. If a course with the same course code and section already exists an error message is displayed and file processing continues with the next line. Otherwise the course is added to the schedule and processing continues with the next line. The SFF file format is described below. For example: import class.txt

remove

Deletes the given course from the schedule. If the course does not exist, an error message is displayed and no changes are made to the schedule.

For example: remove COMPSCI337 401 validate Check the current schedule to determine whether any instructor is teaching 2 courses at the same time. If there are course overlaps, each should be noted with a separate error message. quit End the program.

SFF Format

An SFF file contains a course entry on each line. Each course entry is of the form:

For example: MW 09:30 10:45 COMPSCI337 401 ROCK

The letter O is used to denote an empty set of days of the week. For example, O 00:00 00:00 COMPSCI140 901 ROCK This would be useful for online courses, which have no set meeting time.

//Header file timeInterval.h: This is the INTERFACE for the class TimeInterval. //startTime must be less than or equal to endTime

#ifndef TIMEINTERVAL_H #define TIMEINTERVAL_H

#include "dtime.h" #include using namespace std;

class TimeInterval { public: TimeInterval( ); //Initializes the interval to [0:00, 0:00].

TimeInterval(const DigitalTime& a, const DigitalTime& b); //Initializes the interval to [a, b], if a <= b. Otherwise intialize to [0:00, 0:00]

void setInterval(const DigitalTime& a, const DigitalTime& b); //Initializes the interval to [a, b], if a <= b. Otherwise leave host unchanged

DigitalTime getStart() const; DigitalTime getEnd() const;

void output(ostream& outs) const; //Outputs the interval in the form a - b. For example, 9:30 - 10:45 //Precondition: If outs is a file output stream, then outs has already been //connected to a file. private: DigitalTime startTime; DigitalTime endTime; };

bool operator&&(const TimeInterval& a, const TimeInterval& b); //Returns true if a and b overlap, false otherwise

ostream& operator<<(ostream& outs, const TimeInterval& d); //Use the output member funtion to implement stream insertion for TimeInterval

#endif //TIMEINTERVAL_H

//Header file dtime.h: This is the INTERFACE for the class DigitalTime.

//Values of this type are times of day. The values are input and output in

//24 hour notation as in 9:30 for 9:30 AM and 14:45 for 2:45 PM.

#ifndef DTIME_H

#define DTIME_H

#include

using namespace std;

class DigitalTime

{

public:

bool isEqual(const DigitalTime& time1) const;

//Returns true if time1 and host represent the same time;

//otherwise, returns false.

bool isLess(const DigitalTime& time1) const;

//Returns true if host is strictly less than time1;

//otherwise, returns false.

DigitalTime(int the_hour, int the_minute);

//Precondition: 0 <= the_hour <= 23 and 0 <= the_minute <= 59.

//Initializes the time value to the_hour and the_minute.

DigitalTime( );

//Initializes the time value to 0:00 (which is midnight).

bool input(istream& ins);

//Reads a white-space delimited token from ins. If the token is of the form

//hh:mm where hh is an integer from 0 to 23 (inclusive) and mm is an integer

//from 0 to 59 (inclusive), host is set to these values and the function returns true.

//Otherwise host is left unchanged and the function returns false.

//Precondition: If ins is a file input stream, then ins has already been

//connected to a file.

void output(ostream& outs) const;

//Outputs digital time in the form hour:minute

//Precondition: If outs is a file output stream, then outs has already been

//connected to a file.

int getHour() const;

int getMinute() const;

void set(int hour, int minute);

//If : is valid, the digitalTime is set to that value. If either hour

//or minute is not valid, the host object is unchanged.

private:

int hour;

int minute;

};

bool operator<(const DigitalTime& a, const DigitalTime& b);

bool operator>(const DigitalTime& a, const DigitalTime& b);

bool operator<=(const DigitalTime& a, const DigitalTime& b);

bool operator>=(const DigitalTime& a, const DigitalTime& b);

bool operator==(const DigitalTime& a, const DigitalTime& b);

bool operator!=(const DigitalTime& a, const DigitalTime& b);

//Use the member functions isEqual and isLess to implement each of the operators above.

istream& operator>>(istream& ins, DigitalTime& d);

//Use the input member funtion to implement stream extraction for DigitalTime

ostream& operator<<(ostream& outs, const DigitalTime& d);

//Use the output member funtion to implement stream insertion for DigitalTime

#endif //DTIME_H

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image_2

Step: 3

blur-text-image_3

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

More Books

Students also viewed these Databases questions