Skip to main content

Zoho Interview | Set 3 COMPLEX CODING

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

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;
}


Comments

  1. Hi Mark,

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

    Tnx in adv.

    ReplyDelete
  2. 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

    ReplyDelete
  3. Thanks alot. It's really helpful.

    ReplyDelete
  4. What does the 'c' variable indicate in the struct taxi??

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

    ReplyDelete
  6. You 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

    ReplyDelete
  7. Nice One bro
    Thank YOu
    Code is simple and crystal clear.
    it helped a lot

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

    ReplyDelete
  9. Thanks for posting such a helpful and informative post. Amazing deals offers on Best Online Taxi, Cab & Bus Booking Services 24x7 Customer Support Call +2348145096407

    Click out here - http://waka247.com/

    ReplyDelete
  10. Thank You.It helped a lot

    ReplyDelete

Post a Comment

Popular posts from this blog

ORACLE 9i practice solutions

Created by BCL easyConverter SDK 3 (HTML Version)

Hackerrank > SQL > Basic Select

Select
01-Select All
Given a City table, whose fields are described as +-------------+----------+ | Field       | Type     | +-------------+----------+ | ID          | int(11)  | | Name        | char(35) | | CountryCode | char(3)  | | District    | char(20) | | Population  | int(11)  | +-------------+----------+
write a query that will fetch all columns for every row in the table.

My Solution
SELECT*FROM city;
---------------------------------------------------------------------------------
02-Select by ID
Given a City table, whose fields are described as

Zoho Puzzle Questions With Answers

Measuring Time Logic Puzzle You are given with two ropes with variable width. However if we start burning both the ropes, they will burn at exactly same time i.e. an hour. The ropes are non-homogeneous in nature. You are asked to measure 45 minutes by using these two ropes.

How can you do it?

Please note that you can’t break the rope in half as it is being clearly stated that the ropes are non-homogeneous in nature.
Answer & Explanation Solution: 45 minutes

Explanation :
All you have to do is burn the first rope from both the ends and the second rope from one end only simultaneously. The first rope will burn in 30 minutes (half of an hour since we burned from both sides) while the other rope would have burnt half. At this moment, light the second rope from the other end as well. Where, the second rope would have taken half an hour more to burn completely, it will take just 15 minutes as we have lit it from the other end too.

Thus you have successfully calculated 30+15 = 45 minutes …