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

Post a Comment

Popular posts from this blog

C Questions

C Questions
C Questions

Note : All the programs are tested under Turbo C/C++ compilers.
It is assumed that,
Programs run under DOS environment, The underlying machine is an x86 system, Program is compiled using Turbo C/C++ compiler.
The program output may depend on the information based on this assumptions (for example sizeof(int) == 2 may be assumed).
Predict the output or error(s) for the following:

void main()
{
int const * p=5; printf("%d",++(*p));
}
Answer:
Compiler error: Cannot modify a constant value.
Explanation:
p is a pointer to a "constant integer". But we tried to change the value of the "constant integer".
main()
{
char s[ ]="man"; int i;
for(i=0;s[ i ];i++)
printf("\n%c%c%c%c",s[ i ],*(s+i),*(i+s),i[s]);
}
Answer: mmmm
aaaa nnnn
Explanation

Zoho Interview | Set 1 (Advanced Programming Round)

Third Round: (Advanced Programming Round) Here they asked us to create a “Railway reservation system” and gave us 4 modules. The modules were:
    1. Booking
    2. Availability checking
    3. Cancellation
    4. Prepare chart
We were asked to create the modules for representing each data first and to continue with the implementation phase.

 My Solution :

#include<stdio.h>#include<conio.h>#include<stdlib.h>#include<string.h>#include<iostream.h>#include<time.h>#include<iomanip.h>#include<fstream.h>char f[10]="f";char s[10]="s";int addr,ad,flag,f1,d,m,i,amt;float tamt; class login {public:char id[100];char pass[100];char*password;void getid(){ cout<<"Enter your id:";gets(id); password=getpass("Enter the password:");strcpy(pass,password);}void displayid(){ cout<<"Id:";puts(id); cout<<"Password:";puts(pass);}}; class detail {public:in…

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