Taxi Rank

This is a discussion on Taxi Rank within the C++ Programming forums, part of the General Programming Boards category; hi any chance anyone can help me with C programming, im very rubbish at codes i am required to code ...

  1. #1
    Registered User
    Join Date
    Mar 2013
    Posts
    13

    Taxi Rank

    hi any chance anyone can help me with C programming, im very rubbish at codes

    i am required to code up in C, a program to simulate a taxi rank that is implemented as a queue via an array that can hold up to a maximum of six taxis.

    When a taxi arrives, it joins the rear of the queue. When a taxi departs, the first taxi in the rank is used and its departure is logged.
    A "rolling menu" comprising integer codes as specified below is used until 0 is entered to exit the simulation.

    Code Function Detailed Operation(s)
    1 arrive: read taxi number (an integer) and
    add specified taxi number to rear of rank.

    2 depart: remove first taxi from front of rank
    report taxi departure.

    3 print: print contents (including empty) of the rank.

    4 find: read a taxi number. If it is in the rank report
    its position, otherwise report its absence.

    0 exit: cleanly exit the program


    ive done this code but i need help editing it, for the above answers

    Code:
     
    Code:
    #include <stdio.h>
    #include <Stdafx.h>
    
    
    #define MAX 100
    
    
    void print_menu(int n);
    
    
    void main()
    {
        int c;
        int a[MAX];
        int top = 0;
        int reg;
        int temp[MAX];
        
    
    
        print_menu(1);
    
    
        scanf_s("%d", &c);
        while (c != 8)
        {
            if (c == 1)
            {
                // Scan in registration
                printf("Please enter Taxi Registration Number\n");
                scanf("%d", &reg);
                a[top] = reg;
                top++;
                
                
    
    
    
    
                // Call print_menu
                print_menu(1);
                scanf("%d", &c);
            }
            else if (c == 2) 
            {
                //remove from front
                int b;
        
                for(b = 0; b <= top; b++)
                {
                    temp[b] = a[b+1];
                }
    
    
                for (b = 0; b <= top; b++)
                {
                    a[b] = temp[b];
                }
    
    
                top--;
                printf("Taxi has left\n");
    
    
    
    
    
    
    
    
    
    
                //print menu
                print_menu(1);
                scanf("%d", &c);
            }
            else if (c == 3) 
            {
                //search taxi
                int k;
                int notfound = -1;
                printf("Please enter taxi registration number\n");
                scanf("%d", &reg);
                
                for (k = 0; k <= top; k++)
                {
                    if(a[k] == reg)
                    {
                        printf("Taxi %d found in position %d\n", reg, k+1);
                    }
                    else 
                    {
                        notfound++;
                    }
    
    
                    if (notfound == top)
                    {
                        printf("Taxi not found\n");
                    }
                }
                
    
    
                //print taxi menu
                
                print_menu(1);
                scanf("%d", &c);
            }
            else if (c == 4)
            {
    
    
                // print taxi's
                int i, taxnum;
                taxnum = 1;
    
    
    
    
                if (top == 0)
                {
                    printf("No Taxi's in queue\n");
                }
                else
                {
                    for(i = 0; i < top; i++)
                    {
                        printf("Taxi number %d: ", taxnum++);
                        printf("%d\n", a[i]);
                    }
                }
    
    
    
    
    
    
                // call print_menu
                print_menu(1);
                scanf("%d", &c);
            }
            else if (c == 5)
            {
                //print taxi in the front of queue
                if (a[0] < 0)
                {
                    printf("There are no taxi's in the queue\n");
                }
                else
                {
                    printf("First taxi in the queue is: %d\n", a[0]);
                }
    
    
                //print taxi menu
                
                print_menu(1);
                scanf("%d", &c);
            }
            else if (c == 6)
            {
                //print taxi last in queue
                if (top -1 < 0)
                {
                    printf("There are no taxi's in the queue\n");
                }
                else
                {
                    printf("Last taxi in the queue is: %d\n",a[top - 1]);
                }
    
    
    
    
    
    
                // print menu
                
                print_menu(1);
                scanf("%d", &c);
            }
            else if (c == 7)
            {
                //length of queue
                if (top ==1)
                {
                    printf("There is %d Taxi in the queue\n", top);
                }
                else
                {
                    printf("There are %d Taxi's in the queue\n", top);
                }
    
    
    
    
    
    
                //print menu
                print_menu(1);
                scanf("%d", &c);
            }
            else
            {
                printf("**Invalid menu option**\n");
                print_menu(1);
                scanf("%d", &c);
            }
            
        }
        
    }
    
    
    
    
    // Print menu
    void print_menu(int n)
    {
        printf("*************\n");
        printf("* Taxi Menu *\n");
        printf("*************\n");
        printf("* 1. Arrive *\n");
        printf("* 2. Leave  *\n");
        printf("* 3. Search *\n");
        printf("* 4. Print  *\n");
        printf("* 5. Front  *\n");
        printf("* 6. Back   *\n");
        printf("* 7. Length *\n");
        printf("* 8. Exit   *\n");
        printf("*************\n");
        
    }

  2. #2
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    32,855
    OK, so what's your question?

    You can't just dump your assignment and best effort on the forum, and hope we'll just pick it up and finish it for you.
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.
    I support http://www.ukip.org/ as the first necessary step to a free Europe.

  3. #3
    Registered User
    Join Date
    Mar 2013
    Posts
    13
    Apologize for that, ive managed to sort it out but im gettin few new errors now, do u think u can help me

  4. #4
    Registered User
    Join Date
    May 2009
    Posts
    2,779
    Quote Originally Posted by BretFlorida View Post
    Apologize for that, ive managed to sort it out but im gettin few new errors now, do u think u can help me
    If you DO NOT tell us the errors, how to you think we can help you?

    As far as I know, there are no psychics working support on this board.

    Next time post the errors or call the psychic hot line for support.

    Tim S.
    "Programming today is a race between software engineers striving to build bigger and better idiot-proof programs, and the universe trying to produce bigger and better idiots. So far, the Universe is winning." Rick Cook

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. rank
    By Smartbowy in forum C Programming
    Replies: 14
    Last Post: 04-25-2012, 10:54 PM
  2. position vs rank in adt?
    By c_weed in forum Tech Board
    Replies: 2
    Last Post: 02-21-2012, 05:58 PM
  3. Help with my Taxi Rank Code
    By DP1990 in forum C Programming
    Replies: 6
    Last Post: 03-06-2011, 10:14 AM
  4. How can i rank grades?
    By Lopen007 in forum C++ Programming
    Replies: 3
    Last Post: 03-08-2008, 08:29 AM
  5. My book recommendations for rank beginners ...
    By snakum in forum C++ Programming
    Replies: 4
    Last Post: 08-21-2002, 11:38 AM

Tags for this Thread


1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21