write a program that manages a schedule of classes for a college. Your program w
ID: 3821333 • Letter: W
Question
write a program that manages a schedule of classes for a college.
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. 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 <days> <start time> <end time> <course code> <section> <instructor
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 <file name>
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 <file name>
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 <course code> <section>
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:
<days> <start time> <end time> <course code> <section> <instructor>
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.
Explanation / Answer
#include <iomanip>
#include <iostream>
#include <string>
using namespace std;
string class_name[4];
int class_options[4], class_amount, loop = 1, class_day_amount[4][4];
char class_days[4][4][4];
int main()
{
cout << "****************************************" << endl
<< "* Scheduler v1.0 ---------------------- *" << endl
<< "****************************************" << endl << endl;
cout << "This program will give you all possibilities of a schedule." << endl << endl;
cout << "Number of classes being taken: ";
cin >> class_amount; // Amount of classes being taken.
while(loop == 1) // Checks for incorrect input.
{
if(class_amount > 5 || class_amount < 2)
{
cout << "The amount you entered was not operable, choose from 2 to 5 classes, try again: " << endl;
cin >> class_amount;
}
else
{
loop = 0;
}
}
loop = 1; // Resets while loop.
for(int m = 0; m < class_amount; m++) // Retrieves the names of all the classes.
{
cout << "Name of class #" << m + 1 << ": ";
cin >> class_name[m];
}
//cout << endl << "The " << class_amount << " classes you are taking this semester are: " << endl;
//for(int m = 0; m < class_amount; m++)
// {
// cout << "#" << m + 1 << ": " << class_name[m] << endl;
// }
cout << endl;
for(int m = 0; m < class_amount; m++) // Retrieves the number of options for each class.
{
cout << "Number of different options for class #" << m + 1 << " (" << class_name[m] << "): ";
cin >> class_options[m];
while(loop == 1) // Checks for incorrect input.
{
if(class_options[m] < 0)
{
cout << "The amount you entered was not operable, try again: ";
cin >> class_options[m];
}
else
{
loop = 0;
}
}
}
loop = 1; // Resets while loop.
for(int x = 0; x < class_amount; x++) // Retrieves number of days per week for each class.
{
cout << endl << "Class #" << x + 1 << " has " << class_options[x] << " options." << endl;
for(int y = 0; y < class_options[x]; y++)
{
cout << "How many days a week does class #" << x + 1 << " (" << class_name[x] << ") Option #" << y + 1 << " have: ";
cin >> class_day_amount[x][y];
while(loop == 1) // Checks for incorrect input.
{
if(class_day_amount[x][y] < 1)
{
cout << "The amount you entered was not operable, try again: ";
cin >> class_day_amount[x][y];
}
else
{
loop = 0;
}
}
}
}
loop = 1; // Resets while loop.
cout << endl << "**************" << endl
<< "* Legend *" << endl
<< "**************" << endl
<< "*[M]onday *" << endl
<< "*[T]uesday *" << endl
<< "*[W]ednesday *" << endl
<< "*Th[u]rsday *" << endl
<< "*[F]riday *" << endl
<< "**************" << endl;
for(int x = 0; x < class_amount; x++) // Retrieves the specific days per week for each class.
{
cout << endl << "Prompting for information on class #" << x + 1 << " (" << class_name[x] << ").";
for(int y = 0; y < class_options[x]; y++)
{
cout << endl << "Prompting for information on Option #" << y + 1 << " of the above class.";
for(int z = 0; z < class_day_amount[x][y]; z++)
{
cout << endl << "Type the hot key for Day #" << z + 1 << " and press <Enter>: ";
cin >> class_days[x][y][z];
while(loop == 1) // Checks for incorrect input.
{
switch(class_days[x][y][z])
{
case 'M':
loop = 0;
break;
case 'm':
loop = 0;
break;
case 'T':
loop = 0;
break;
case 't':
loop = 0;
break;
case 'W':
loop = 0;
break;
case 'w':
loop = 0;
break;
case 'U':
loop = 0;
break;
case 'u':
loop = 0;
break;
case 'F':
loop = 0;
break;
case 'f':
loop = 0;
break;
default:
cout << "The character you entered was not operable, try again: ";
cin >> class_days[x][y][z];
break;
}
}
}
}
}
loop = 1; // Resets while loop.
for(int x = 0; x < class_amount; x++) // Retrieves the specific times for each day per week for each class.
{
cout << endl << "Prompting for information on class #" << x + 1 << " (" << class_name[x] << ").";
for(int y = 0; y < class_options[x]; y++)
{
cout << endl << "Prompting for information on Option #" << y + 1 << " of the above class.";
for(int z = 0; z < class_day_amount[x][y]; z++)
{
cout << endl << "Prompting for information on ";
switch(class_days[x][y][z])
{
case 'M':
cout << "Monday of the above option and class.";
break;
case 'm':
cout << "Monday of the above option and class.";
break;
case 'T':
cout << "Tuesday of the above option and class.";
break;
case 't':
cout << "Tuesday of the above option and class.";
break;
case 'W':
cout << "Wednesday of the above option and class.";
break;
case 'w':
cout << "Wednesday of the above option and class.";
break;
case 'U':
cout << "Thursday of the above option and class.";
break;
case 'u':
cout << "Thursday of the above option and class.";
break;
case 'F':
cout << "Friday of the above option and class.";
break;
case 'f':
cout << "Friday of the above option and class.";
break;
default:
break;
}
for(int v = 0; v < class_days[x][y][z]; v++)
{
// Retrieval of time.
}
}
}
}
system("pause");
return 0;
}
Edit & Run
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.