Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations wOOdy-Soft on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Comparing time?

Status
Not open for further replies.

Guest_imported

New member
Jan 1, 1970
0
Vis-C-tor (Visitor) Oct 16, 2001
hi all,
I am trying to make a program that will allow users to add a course if it does not conflict with any existing course. The program should then check with the existing two courses to see if there is a conflict in time. If there is a conflict, the course will not be added, otherwise added. Finally the updated course list will be displayed.
This is what I got so far and I have reach my limit.
The problem I have is getting C++ to check to see if the time the user input is in conflict with with any existing course.Other than that I know how to do.I have tried the if-statement but with no luck.Can anyone help me out here?

#include<iostream>

struct Time
{ int Hrs;
int Mins;
};

{
char CourseID[10];
Time StartTime;
int Length;
};


Time SetTime();
void PrintTime(Time );

void main()
{//Declaration of an array of type Course of size 5 with first two elements initialized.
Course Current[5] = { {&quot;MTH101&quot;, 9, 30, 75}, {&quot;M212&quot;, 14, 0, 110} };

cout<<&quot;\nEnter course number: &quot;;
cin>>Current[2].CourseID;
Current[2].StartTime = SetTime();
cout<<&quot;\nEnter the length in minutes: &quot;;
cin>>Current[2].Length;



}


//function definitions
Time SetTime()
{ Time T;
cout <<&quot;Enter hours (in military) and minutes separated by a space: &quot;;
cin >> T.Hrs >> T.Mins;
return T;
}

void PrintTime(Time T)
{ if (T.Hrs != 12)
cout << T.Hrs%12 <<':';
else
cout <<T.Hrs <<':';
if (T.Mins < 10 )
cout << '0' <<T.Mins;
else
cout << T.Mins;
if (T.Hrs < 12)
cout <<&quot; AM&quot;;
else
cout <<&quot; PM&quot;;
}


 
You should enumerate the available blocks of time. This would allow a straight integer comparison to determine conflicts:

typedef enum {
morning1, // 0800 - 0900
morning2, // 0900 - 1000
et...
eveningN, // 2100 - 2200
special // if more flexibility is needed.
}

These could then index into an array of structures which define them. The user is then given only valid choices.

Brudnakm.
 
thanks for your suggestions, but what about the minutes.
The user will input a course id,start time,and length of the coursee. The minutes have to be taken into consideration too.
 
this is actually a problem to check if the two line segments overlap each other.
say the two line segments : (x1,d1) and (x2,d2);
x is the start point, while d is the length.

Obviously the condition of nonoverlap is:

(x2 >= x1 + d1) || (x1 >= x2 + d2)

You can figure out how this applies to your course scheduling.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top