1) Design a Call taxi booking application

-There are n number of taxi’s. For simplicity, assume 4. But it should work for any number of taxi’s.

-The are 6 points(A,B,C,D,E,F)

-All the points are in a straight line, and each point is 15kms away from the adjacent points.

-It takes 60 mins to travel from one point to another

-Each taxi charges Rs.100 minimum for the first 5 kilometers and Rs.10 for the subsequent kilometers.

-For simplicity, time can be entered as absolute time. Eg: 9hrs, 15hrs etc.

-All taxi’s are initially stationed at A.

-When a customer books a Taxi, a free taxi at that point is allocated

-If no free taxi is available at that point, a free taxi at the nearest point is allocated.

-If two taxi’s are free at the same point, one with lower earning is allocated

-Note that the taxi only charges the customer from the pickup point to the drop point. Not the distance it travels from an adjacent point to pickup the customer.

-If no taxi is free at that time, booking is rejected

Design modules for

-There are n number of taxi’s. For simplicity, assume 4. But it should work for any number of taxi’s.

-The are 6 points(A,B,C,D,E,F)

-All the points are in a straight line, and each point is 15kms away from the adjacent points.

-It takes 60 mins to travel from one point to another

-Each taxi charges Rs.100 minimum for the first 5 kilometers and Rs.10 for the subsequent kilometers.

-For simplicity, time can be entered as absolute time. Eg: 9hrs, 15hrs etc.

-All taxi’s are initially stationed at A.

-When a customer books a Taxi, a free taxi at that point is allocated

-If no free taxi is available at that point, a free taxi at the nearest point is allocated.

-If two taxi’s are free at the same point, one with lower earning is allocated

-Note that the taxi only charges the customer from the pickup point to the drop point. Not the distance it travels from an adjacent point to pickup the customer.

-If no taxi is free at that time, booking is rejected

Design modules for

1) Call taxi booking Input 1: Customer ID: 1 Pickup Point: A Drop Point: B Pickup Time: 9 Output 1: Taxi can be allotted. Taxi-1 is allotted Input 2: Customer ID: 2 Pickup Point: B Drop Point: D Pickup Time: 9 Output 1: Taxi can be allotted. Taxi-2 is allotted

(Note: Since Taxi-1 would have completed its journey when second booking is done, so Taxi-2 from nearest point A which is free is allocated)

Input 3: Customer ID: 3 Pickup Point: B Drop Point: C Pickup Time: 12 Output 1: Taxi can be allotted. Taxi-1 is allotted

2) Display the Taxi details

Taxi No: Total Earnings: BookingID CustomerID From To PickupTime DropTime Amount Output: Taxi-1 Total Earnings: Rs. 400 1 1 A B 9 10 200 3 3 B C 12 13 200 Taxi-2 Total Earnings: Rs. 350 2 2 B D 9 11 350

These were just sample inputs. It should work for any input that they give.

**My Solution ::**#include <stdio.h> #include <string.h> #include <math.h> #include <stdlib.h> #include <conio.h> struct taxi { int c; int booking_id[10]; int customer_id[10]; char from[10]; char to[10]; int pickup_time[10]; int drop_time[10]; int amount[10]; char current_position; int current_time; }s[4]; struct customer { int customer_id; char pickup_point; char drop_point; int pickup_time; }cc; int cust() { int j; scanf("%d%s%s%d",&cc.customer_id,&cc.pickup_point,&cc.drop_point,&cc.pickup_time); j=calc(); return j; } int tot(int i) { int k,total=0; for(k=0;k<s[i].c;k++) total=total+s[i].amount[k]; return total; } int calc() { int k,min=100,i,m=0,j,total1,total2; for(i=0;i<4;i++) { k=abs(s[i].current_position-cc.pickup_point); if(min>k&&(s[i].current_time<=cc.pickup_time)) { min=k; m=i; } else if(min==k&&(s[i].current_time<=cc.pickup_time)) { total1=tot(m); total2=tot(i); if(total1>total2) { min=k; m=i; } } } return m; } void assign(int j) { s[j].booking_id[s[j].c]=1; s[j].current_position=cc.drop_point; s[j].amount[s[j].c]=(((abs(cc.pickup_point-cc.drop_point)*15)-5)*10)+100; s[j].pickup_time[s[j].c]=cc.pickup_time; s[j].drop_time[s[j].c]=(abs(cc.pickup_point-cc.drop_point)*1)+cc.pickup_time; s[j].from[s[j].c]=cc.pickup_point; s[j].to[s[j].c]=cc.drop_point; s[j].customer_id[s[j].c]=cc.customer_id; s[j].current_time=s[j].drop_time[s[j].c]; s[j].c++; } void details() { int i,j,sum=0; scanf("%d",&j); j=j-1; for(i=0;i<s[j].c;i++) { sum=sum+s[j].amount[i]; } printf("total:%d\n",sum); printf("\ntaxi:\tbooking id:\tcustomer id:\tfrom:\tto:\tpickup time:\tdrop time:\tamount:\tcurrent point:\n"); for(i=0;i<s[j].c;i++) printf("%d\t%d\t%d\t%c\t%c\t%d\t%d\t%d\t%c",j,s[j].booking_id[i],s[j].customer_id[i],s[j].from[i],s[j].to[i],s[j].pickup_time[i],s[j].drop_time[i],s[j].amount[i],s[j].current_position); } int main() { int i,j,k; for(i=0;i<4;i++) { s[i].c=0; s[i].current_position='a'; s[i].current_time=0; } clrscr(); while(1) { printf("\n1.customer\n2.display\n3.exit\n"); scanf("%d",&k); switch(k) { case 1: j=cust(); assign(j); break; case 2: details(); break; case 3: exit(0); default: printf("invalid input"); break; } } getch(); return 0; }

Hi Mark,

ReplyDeleteCan u xplain what is done on the calc() function and what Min variable denotes.

Tnx in adv.

actually min variable is which stores the smallest distance, between the pick up point and the taxi, the calc areturn the available taxi to be assigned

ReplyDeleteThanks alot. It's really helpful.

ReplyDeleteWhat does the 'c' variable indicate in the struct taxi??

ReplyDeleteHi, are you sure this enough for round 3?. because,I thought that we have to implement with oops (classes and objects)

ReplyDeleteIt,s your wish bro

DeleteYou can Improve your calc() function by initializing m as -ve number,if it returns 0 to 3 that means taxi can be alloted but if returns the same negative number than you can print the message that taxi cant be alloted..I blv you have not covered this case in your program

ReplyDeleteNice One bro

ReplyDeleteThank YOu

Code is simple and crystal clear.

it helped a lot

is it important to code in turbo c can't we choose codeblocks in zohooo coding round?

ReplyDelete