Sunday, 12 May 2013

Wrrite a program which event become earlier


You are to write a program to process the timings of events. The program should have following structures.

Date is defined as a structure with three fields of type integer i.e. day, month and year.
Time is defined as a structure with three fields of type integer i.e. hour, minute and second.
Event is also defined as a structure with three fields. One of the fields is venue of type integer. Whereas other two fields are the variables of type DateType and TimeType. 







#include<stdio.h>
#include<stdlib.h>
struct time
{
int hour;
int min;
int sec;
};
struct date
{
int day;
int month;
int year;
};
struct even
{
int venue;
struct time t;
struct date d;
};
void inputtime(struct time *t);
void inputdate(struct date *d);
void inputeven( struct even *e1);
int Earlierevevt(struct even *e1 , struct even *e2);
void print(even *e1);
void main()
{
struct even s[10] , temp;
int i,j;
for(i=0;i<3;i++)
{
inputeven(&s[i]);
}
for(i=0;i<2;i++)
{
for(j=i+1;j<3;j++)
if(Earlierevevt(&s[i],&s[j])==1)
{
temp=s[i];
s[i]=s[j];
s[j]=temp;
}
}
system("cls");
for(i=0;i<3;i++)
print(&s[i]);
system("pause");
}
void inputtime(struct time *t)
{
printf("enter hour\n");
scanf("%d",&t->hour);
printf("enter min\n");
scanf("%d",&t->min);
printf("enter second\n");
scanf("%d",&t->sec);
}
void inputdate(struct date *d)
{
printf("enter date\n");
scanf("%d",&d->day);
printf("enter month\n");
scanf("%d",&d->month);
printf("enter year\n");
scanf("%d",&d->year);
}
void inputeven( struct even *e1)
{
printf("enter the venue of event\n");
scanf("%d",&e1->venue);
printf("enter the date of event\n");
inputdate(&(e1->d));
printf("enter the time of event\n");
inputtime(&(e1->t));
}
int Earlierevevt(struct even *e1 , struct even *e2)
{
if(e1->d.year != e2->d.year)
{
if(e1->d.year > e2->d.year)
return 1;
else{}
}
if(e1->d.month != e2->d.month)
{
if(e1->d.month > e2->d.month)
return 1;
else{}
}
if(e1->d.day != e2->d.day)
{
if(e1->d.day > e2->d.day)
return 1;
else{}
}
if(e1->t.hour != e2->t.hour)
{
if(e1->t.hour > e2->t.hour)
return 1;
else{}
}
if(e1->t.min != e2->t.min)
{
if(e1->t.min > e2->t.min)
return 1;
else{}
}
if(e1->t.sec != e2->t.sec)
{
if(e1->t.sec > e2->t.sec)
return 1;
else{}
}
return 0;
}
void print(even *e1)
{
printf("Venue %d\n",e1->venue);
printf("Date= %d/%d/%d\n",e1->d.day,e1->d.month,e1->d.year);
printf("Time= %d:%d:%d\n",e1->t.hour,e1->t.min,e1->t.sec);
}


No comments:

Post a Comment