You must Sign In to post a response.
  • Category: Programming

    Program to find a person is driver for bus,car or bike.


    Taking a Language programming exam for diploma engineering exam? Searching for program solution for finding if a driver is for a bus, car or a bike? Scroll through this page and check out the answers from experts.

    Following is a question that was asked in the manual of Diploma in Electronics and Telecommunication Engineering conducted by Maharashtra State Board of Technical Examination, Mumbai for subject C Language Programming(22218)(G Scheme), Semester-II

    Program along with some explanation is expected.

    Q) Write a program to find a person is driver for bus, car or bike.
  • Answers

    2 Answers found.
  • The above question is based on switch statement. Switch statement is a multi path decision statement used in C language. When user have multiple options and have to select only one option, then switch statement is used.
    Please include stdio,h, conio,h and stdlib.h header files before main function.

    #include
    #include
    #include
    void main(void)
    {
    int ch;
    clrscr();
    printf("\n1.Two Wheeler\n2.Four Wheeler\n3.Six Wheeler\n4.Exit\n");
    printf("\nEnter your option\n");
    scanf("%d",&ch);
    switch(ch)
    {
    case 1:
    printf("\nThe person is driver for bike\n");
    break;
    case 2:
    printf("\nThe person is driver for car\n");
    break;
    case 3:
    printf("\nThe person is driver for bus\n");
    break;
    case 4:
    exit(0);
    break;
    default:
    printf("\nInvalid option");
    }
    getch();
    }

  • I am going to give you the solutions for the above question in C, Java and Inspire Designer.

    Below is my code in C by using "if..else if ladder":

    #include
    int main(void) {
    // your code goes here
    int optionOfCarBikeBus;
    scanf("%d", &optionOfCarBikeBus);
    driverForWhat(optionOfCarBikeBus);
    return 0;
    }
    void driverForWhat(int option)
    {
    if(option == 2)
    {
    printf("The person is driver for Bike");
    }
    else if(option == 4)
    {
    printf("The person is driver for Car");
    }
    else if(option == 6 || option == 8 || option == 10)
    {
    printf("The person is driver for Bus");
    }
    else
    {
    printf("None");
    }
    }


    Below is my code in Java by using "switch":

    import java.util.Scanner;
    public class Sample{
    public static void main(String []args){
    Scanner scan = new Scanner(System.in);
    int userInputs = scan.nextInt();
    switch(userInputs)
    {
    case 2:
    System.out.println("The person is driver for Bike");
    break;
    case 4:
    System.out.println("The person is driver for Car");
    break;
    case 6:
    case 8:
    case 10:
    System.out.println("The person is driver for Bus");
    break;
    default:
    System.out.println("None");
    }
    }
    }


    Below is my code in Inspire Designer by using "switch":

    Note : In inspire designer to solve this problem you need to follow the below steps:
    (a) - First take "DataGenerator Module" which will have numbers from 1 to 10.
    (b) - After that place "ImpositionScript Module" which will have One Data input count and One Data output count.
    (c) - After that place "DataOutput Module" to check your result.

    for(Int i = 0; i < Input_0.Numbers.Count; i++)
    {
    Int userInput = Input_0.Numbers[i].Number;
    is(userInput)
    {
    2 : Output_0.Array0.driverForWhat = "The person is driver for Bike";
    4 : Output_0.Array0.driverForWhat = "The person is driver for Car";
    6,8,10 : Output_0.Array0.driverForWhat = "The person is driver for Bus";
    else
    Output_0.Array0.driverForWhat = "None";
    }
    Output_0.Array0.commit();
    }




    I hope this answer is helpful for you.


  • Sign In to post your comments