By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
454,465 Members | 1,448 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 454,465 IT Pros & Developers. It's quick & easy.

GCC ERROR

P: n/a
#include<iostream>
using namespace std;

struct time
{
int hours,minutes,seconds;
};

struct lecture
{
time stime;
int duration;
int room;
char building;
};

void clash(lecture l1, lecture l2)
{
if(l1.building==l2.building && l1.room==l2.room)
{
if(l1.stime.hours==l2.stime.hours &&
l1.stime.minutes==l2.stime.minutes &&
l1.stime.seconds==l2.stime.seconds)
{
cout<<"CLASH1"<<endl;
}
else if(l1.stime.hours>l2.stime.hours)
{
if((l2.stime.hours+l2.duration)>(l1.stime.hours))
{
cout<<"CLASH2"<<endl;
}
else
{
cout<<"NO CLASH1"<<endl;
}
}
else if(l1.stime.hours<l2.stime.hours)
{
if((l1.stime.hours+l1.duration)>=(l2.stime.hours))
{
cout<<"CLASH3"<<endl;
}
else
{
cout<<"NO CLASH2"<<endl;
}
}
else if(l1.stime.hours==l2.stime.hours)
{
if(l1.stime.minutes>l2.stime.minutes)
{
if((l2.stime.minutes+(l2.duration*60)>((l1.stime.m inutes))))
{
cout<<"CLASH4"<<endl;
}
else
{
cout<<"NO CLASH3"<<endl;
}
}

else if(l1.stime.minutes<l2.stime.minutes)
{
if((l1.stime.minutes+(l1.duration*60))>l2.stime.mi nutes)
{
cout<<"CLASH5"<<endl;
}
else
{
cout<<"NO CLASH4"<<endl;
}
}
else if(l1.stime.minutes==l2.stime.minutes)
{
if(l1.stime.seconds>l2.stime.seconds)
{
}
else if(l1.stime.seconds<l2.stime.seconds)
{
}
else if(l1.stime.seconds==l2.stime.seconds)
{
}
else
{
cout<<"NO CLASH5"<<endl;
}
}

else
{
cout<<"NO CLASH6"<<endl;
}
}

else
{
cout<<"NO CLASH7"<<endl;
}
}

else
{
cout<<"NO CLASH8"<<endl;
}

}

int main()
{
lecture l1, l2;

cout<<"Enter Building of First Lecture"<<endl;
cin>>l1.building;

cout<<"Enter Room of First Lecture"<<endl;
cin>>l1.room;

cout<<"Enter Start Time of the First Lecture in the format of hours,
minutes and then seconds"<<endl;
cin>>l1.stime.hours;
cin>>l1.stime.minutes;
cin>>l1.stime.seconds;

cout<<"Enter Duration of the First Lecture"<<endl;
cin>>l1.duration;

cout<<"Enter Building of Second Lecture"<<endl;
cin>>l2.building;

cout<<"Enter Room of Second Lecture"<<endl;
cin>>l2.room;

cout<<"Enter Start Time of the Second Lecture in the format of hours,
minutes and then seconds"<<endl;
cin>>l2.stime.hours;
cin>>l2.stime.minutes;
cin>>l2.stime.seconds;

cout<<"Enter Duration of the Second Lecture"<<endl;
cin>>l2.duration;

clash(l1,l2);

return 0;
}

This is code for the program which takes the information of two
lectures and determines wheher there is a clash between two lectures or
not. While compiling it with GCC i get error 'struct lecture' has no
member named 'stime' . It works fine with VC++. Please help me remove
the error using GCC.

Nov 22 '05 #1
Share this Question
Share on Google+
3 Replies


P: n/a
coinjo wrote:
#include<iostream>
using namespace std;

struct time
{
int hours,minutes,seconds;
};

struct lecture
{
time stime;


use "struct time stime";
the reason being that time is a predefined function in linux.

Nov 22 '05 #2

P: n/a
Thanks.

Nov 22 '05 #3

P: n/a
In your design I would move more logic to classes, e.g create a time
class like

class Time
{
public:
Time(int h, int m, int s):hour(h), minute(m), second(s)
{ serial = 24*h + 60*m + 60*s; }
friend bool operator == (const Time& t1, const Time& t2)
{ return t1.serial == t2.serial; }
friend bool operator < (const Time& t1, const Time& t2)
{ return t1.serial < t2.serial; }
friend bool operator > (const Time& t1, const Time& t2)
{ return t1.serial > t2.serial; }
friend std::ostream& operator << (std::ostream& os, const Time& t)
{ os << std::setw(2) << std::setfill('0') << t.hour << ":"
<< std::setw(2) << std::setfill('0') << t.minute << ":"
<< std::setw(2) << std::setfill('0') << t.second; return
os; }
private:
int hour, minute, second, serial;
};

You can simplify your clash method a lot by using something like this

Nov 22 '05 #4

This discussion thread is closed

Replies have been disabled for this discussion.