Okay, a few things:
1) Indentation. You can of course indent however you like, but in every environment I've worked in, I've never seen anyone indent after a loop like:
1 2 3
|
for(...)
{ // <--- unnecessary!
// <--- good to indent here though, imo
|
so instead, I might recommend:
1 2 3
|
for(...)
{
cout << ...
|
2) While loops.
1 2 3 4 5 6 7 8 9 10 11 12 13
|
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;
}
}
|
could be written more simply as:
1 2 3 4 5
|
while(class_options[m] < 0)
{
cout << "The amount you entered was not operable, try again: ";
cin >> class_options[m];
}
|
Note that if you really DID need to break out for some abnormal condition, you can do that with a 'break;' statement instead of injecting an additional variable into the loop.
3) Switch statements. You have:
1 2 3 4 5 6 7 8
|
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;
|
This can be simplified one of two ways:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15
|
switch(class_days[x][y][z])
{
case 'M':
case 'm':
cout << "Monday of the above option and class.";
break;
// OR
switch(toupper(class_days[x][y][z])) // Notice call to toupper
{
case 'M':
cout << "Monday of the above option and class.";
break;
|
Edit: Even better (at least when getting class days), you can just do:
1 2 3 4 5
|
string days = "MTWUF";
while(days.find(toupper(class_days[x][y][z])) == days.end())
{
// invalid day, get new one
}
|
4) Arrays of unknown size (at compile time)
I notice you are getting the 'class amount' from the user, and using that many entries in your array. It might be easier instead to dynamically allocate your arrays based on this value:
1 2 3 4 5 6 7
|
string * class_name = 0;
cout << "Number of classes being taken: ";
cin >> class_amount; // Amount of classes being taken.
// error checking
class_name = new string[class_amount];
|
OR, for a more c++ish style, just use
std::vector<string> class_name
5) Time. This is a bit of a tricky one. Many time libraries store specific times as 'the number of seconds since January 1, 1970' (for historical reasons). But in your case, you aren't looking for a single specific time, but a time that will be the same on a weekly basis. There are a variety of ways to implement this. Properly, probably some type of 'Time' class might be used, but for this situation I would probably hack it together as an integer, and ask the user for the time in military, so:
730 = 7:30am
1450 = 2:50pm
etc
6) Data structures. I would say your storage mechanism for classes is perhaps a bit too complicated; I haven't quite read over every piece of code, but what I have read suggests things could be simpler. Have you tried to organize it as:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26
|
// Where Class represents "Calc 2, id 2014, which meets 3 times a week",
// MeetingTime represents a specific meeting day and range of a class, so
// "Monday, 2:30-3:30". A Class will have 1 or more MeetingTime children
struct MeetingTime
{
// You could store a reference to the 'Class' instance here, but I don't think it's required
char day;
int start_time;
int end_time;
};
struct Class
{
string name;
string class_id;
std::list<MeetingTime> meeting_times;
};
// ...
list<Class> classes;
// Load classes here
// Once loaded, start your processing. with only 5 potential classes, it won't take too long. If they entered ~10, you could get a lot of output calculating every permutation!
|
There are a couple other little things, but this should be enough to get you in the right direction :)