help me urgent

Discussion in 'C' started by dky8810, Nov 15, 2008.

  1. dky8810

    dky8810 New Member

    Joined:
    Nov 15, 2008
    Messages:
    19
    Likes Received:
    0
    Trophy Points:
    0
    question:
    The airline company, KL AIRLINE, has engaged your teanm to develop a new Airline Ticket Reservation System....airplane wiyh the occupancy of "20 passengers".

    !.display the KL "Airline Reservation Menu" for the user to select from 2 main options which are to do "Booking" and "display seat layout & occupancy".thr is one last option -to "exit" from the system after displaying an appropriate farewell message.

    2.Booking
    -ask user for yhe number of seat required
    -Generete the Booking ID(if enough seats are available)
    -for each seat required,
    *ask for the passenger name,
    *assign the booking ID to the seat, and
    *display the ticket in following format:
    -------------------------------------------------------------------------------------
    | --KL airline booking tikcket---- |
    | booking ID:100 Flight No.:AK65 |
    | Passenger:XXXXXXXXX Date :25-12-2008 |
    | Time :23:45 |
    | Gate :G9 |
    | seat No :3B |
    ---------------------------------------------------------------------------------------

    note:-( Flight No,Date,Time,Gate )will be initizalized either during compile-time or run time.the details are to be stored in a "Struture variable"
    -hv all the necessary "validation" in place, including useful messages, "not enough seat available"
    - must use a Two Dimensional Array to store the seat information(the booking ID or a Zero value).

    3.display seat layout & Occupancy
    sample:
    A B C D E
    |--------------------------------------------|
    1 |101 | 101 | 101 |102 | 103 |
    |-------------------------------------------|
    2 |103 |104 |104 |104 |0 |
    |-------------------------------------------|
    | Aisle |
    |-------------------------------------------|
    3 | 0 | 0 | 0 | 0 | 0 |
    |-------------------------------------------|
    4 | 0 | 0 | 0 | 0 |0 |
    |-------------------------------------------|



    ******required to use :array,structure,Function***********
    T.T pls help hv to submit:19 nov 2008
     
  2. xpi0t0s

    xpi0t0s Mentor

    Joined:
    Aug 6, 2004
    Messages:
    3,009
    Likes Received:
    203
    Trophy Points:
    63
    Occupation:
    Senior Support Engineer
    Location:
    England
    We can't help you if we don't know what the problem is. In what way are you stuck? Is there some specific code you're struggling with, in the sense that what you've written doesn't do what you want it to?
     
  3. dky8810

    dky8810 New Member

    Joined:
    Nov 15, 2008
    Messages:
    19
    Likes Received:
    0
    Trophy Points:
    0
    Code:
    #include<stdio.h>
    #include<string.h>
    #include<stdlib.h>
    #define sizeR 4
    #define sizeC 5
    
    void menu(void);
    void Booking(void);
    void getinf(void);
    void Display(void);
    
    typedef struct{
    int id;
    char flightNo[40];
    char date[20];
    char time;
    char gate;
    char seatNo;
    }customer;
    struct customer cust[sizeR][sizeC];
    
    void menu(void)
    {
    int choice;
    
    printf("\t\t********TARC Airlene Reservation Menu*********\n");
    printf("\t\t1) Booking\n");
    printf("\t\t2) Seat Layout & Occupancy\n");
    printf("\t\t3) Exit\n");
    
    printf("\t\t\tYour choice : ");
    scanf("%d",&choice);
    
    switch(choice){
    case 1:
    Booking();
    break;
    
    case 2:
    Display();
    break;
    default:
    printf("End the program");
    break;
    
    
    }
    }
    
    void main()
    {
    
    menu();
    
    
    }
    
    void Booking(void)
    {
    customer cust[sizeR][sizeC];
    int i;
    int j;
    int row;
    int col;
    printf("How many seat are you required:\n");
    scanf("%d",&i);
    for(row=0;row<sizeR;row++){
    for(col=0;col<sizeC;col++){
    if(cust[sizeR][sizeC] != 0){
    int fp[4]={0},i,f;
    
    printf("hhh\n\n");
    
    for(i=0;i<10;i++){
    f=cust[sizeR][sizeC];
    fp[f]++;
    }
    for(i=0;i<4;i++){
    printf("%d\n\n",i,fp[i]);
    }
    
    
    
    
    
    
    
    
    }
    }
    }
    
    
    
    else
    printf("Not enough seats available!The flight is fully booked!");
    }
    void Display(void)
    {
    }
    void getinf(void)
    {
    /* int i;
    
    printf("Please enter your name:");
    scanf("%[^\n]",cust[sizeR][sizeL].name);*/
    }
    
    here here it can no run???
    "if(cust[sizeR][sizeC] != 0)"
    line60 till 70
     
    Last edited by a moderator: Nov 15, 2008
  4. shabbir

    shabbir Administrator Staff Member

    Joined:
    Jul 12, 2004
    Messages:
    15,375
    Likes Received:
    388
    Trophy Points:
    83
    Use code block when you use Code in Posts and also write the code which is readable and well tabbed.
     
  5. xpi0t0s

    xpi0t0s Mentor

    Joined:
    Aug 6, 2004
    Messages:
    3,009
    Likes Received:
    203
    Trophy Points:
    63
    Occupation:
    Senior Support Engineer
    Location:
    England
    Are you sure it won't run? As in: it compiles OK but there is a runtime problem?
    For me it wouldn't even compile, although it's possible we're using different compilers (I'm using Visual Studio 2005). The first error I got was the redefinition of customer, so I changed the definition to:
    Code:
    struct customer {
    int id;
    char flightNo[40];
    char date[20];
    char time;
    char gate;
    char seatNo;
    };
    struct customer cust[sizeR][sizeC];
    
    If you have typedef struct { ... } customer;, that defines customer as struct { ... }, and you don't need to use "struct customer".

    Then I got a compile error on "if(cust[sizeR][sizeC] != 0)", which I presume is what you're trying to say.
    Why do you think there might be a problem with this line? What type is cust[sizeR][sizeC]? Do you think it's possible to compare one of those directly with an integer?
     
  6. dky8810

    dky8810 New Member

    Joined:
    Nov 15, 2008
    Messages:
    19
    Likes Received:
    0
    Trophy Points:
    0
    i have cancel the keyword"struct",i use typedef format.the problem in this line show by my compile is :(binary '!=':'customer'does not define this operate or a conversion to a type acceptable to the predefined operator).cust[sizeR][sizeC]is array of structure.what code i need to use for know array element is empty ??
     
  7. xpi0t0s

    xpi0t0s Mentor

    Joined:
    Aug 6, 2004
    Messages:
    3,009
    Likes Received:
    203
    Trophy Points:
    63
    Occupation:
    Senior Support Engineer
    Location:
    England
    You could initialise it to a certain value that indicates that a particular entry is empty. For example if all customer IDs are greater than zero, you could use 0 as the ID for an empty slot. Or you could have an explicit isEmpty variable, which would make the code easier to understand. On program startup you would need to initialise all isEmpty's to TRUE, then as each is allocated to a customer you could set it to FALSE. Then all you need to do is test the value of cust[][].isEmpty.
     
  8. dky8810

    dky8810 New Member

    Joined:
    Nov 15, 2008
    Messages:
    19
    Likes Received:
    0
    Trophy Points:
    0
    i done this
    int ID[4][5]={
    {0,0,0,0,0},
    {0,0,0,0,0},
    {0,0,0,0,0},
    {0,0,0,0,0}
    };

    if(cust[sizeR][sizeC] != 0)
    but the problem in line 70 show by my compile is binary '!=':'customer'does not define this operate or a conversion to a type acceptable to the predefined operator).
     
  9. xpi0t0s

    xpi0t0s Mentor

    Joined:
    Aug 6, 2004
    Messages:
    3,009
    Likes Received:
    203
    Trophy Points:
    63
    Occupation:
    Senior Support Engineer
    Location:
    England
    What type is cust[sizeR][sizeC]? Is it an integer?
     
  10. dky8810

    dky8810 New Member

    Joined:
    Nov 15, 2008
    Messages:
    19
    Likes Received:
    0
    Trophy Points:
    0
    it is array of structure (two dimensional array)it contain string and integer!!
    i hv change the code :
    Code:
    void Booking(void)
    {
    	int ID[4][5]={
    	{0,0,0,0,0},
    	{0,0,0,0,0},
    	{0,0,0,0,0},
    	{0,0,0,0,0}
    	};
    	
    
    	customer cust[sizeR][sizeC];
    	int i;
    	int row;
    	int col;
    	int flag=0;
    	printf("How many seat are you required:\n");
    	scanf("%d",&i);
    	for(row=0;row<sizeR;row++){
    		for(col=0;col<sizeC;col++){
    			if(0==ID[4][5]){
    				flag=1;
    				break;
    			}
    		}
    
    		if(flag==0)
    			printf("Please enter your name\n",cust[sizeR][sizeC].name);
    		else
    			printf("Not enough seats available!The flight is fully booked!");
    }
    	}
    
    in this part it keep looping how to stop it??
    if(flag==0)
    printf("Please enter your name\n",cust[sizeR][sizeC].name);
     
    Last edited by a moderator: Nov 16, 2008
  11. xpi0t0s

    xpi0t0s Mentor

    Joined:
    Aug 6, 2004
    Messages:
    3,009
    Likes Received:
    203
    Trophy Points:
    63
    Occupation:
    Senior Support Engineer
    Location:
    England
    Please use code blocks and indent your code. Code blocks are really easy, just put [ code ] before the code and [ /code ] after it (without the spaces). You have been asked to do this before.

    > in this part it keep looping how to stop it??

    I don't know. There is no loop there, so it can't be looping. An if statement evaluates the expression it is given and executes the next statement or code block if the expression is true and skips over it if it is false.
    It may be that by adding cust[sizeR][sizeC].name into the printf you're getting undefined behaviour. Take that out, it has no beneficial effect. The statement should just be printf("Please enter your name\n");

    Don't forget that C counts from zero, not 1, so cust[sizeR][sizeC] doesn't exist. Let me know if you don't understand this and I'll explain it in more detail.
     
  12. shabbir

    shabbir Administrator Staff Member

    Joined:
    Jul 12, 2004
    Messages:
    15,375
    Likes Received:
    388
    Trophy Points:
    83
    dky please use code blocks when you have code snippets in the posts
     
  13. dky8810

    dky8810 New Member

    Joined:
    Nov 15, 2008
    Messages:
    19
    Likes Received:
    0
    Trophy Points:
    0
    i dont understand why saying that cust[sizeR][sizeC] doesn't exit??
    i hv a other question :how to initializes the structure members?
    i have do like this but cant:
    Code:
    customer cust[sizeR][sizeC]={"AK65","25-12-2008","23:45","G9","3B"}
    what code i need to use??
     
  14. xpi0t0s

    xpi0t0s Mentor

    Joined:
    Aug 6, 2004
    Messages:
    3,009
    Likes Received:
    203
    Trophy Points:
    63
    Occupation:
    Senior Support Engineer
    Location:
    England
    Thanks for putting the code block in, it makes it a lot clearer. Code blocks and indentation are to code what punctuation, words and caps are to sentences.
    theprecedingsentenceismucheasiertoreadthanthisoneno?

    OK. C counts from zero; that's how computers work internally. So when you create an array of size 5, you get 5 elements, but the first is element 0, not element 1.
    If the first element was 1 as in other languages, then valid array indices would be 1,2,3,4,5.
    But because C counts from zero the valid array indices are 0,1,2,3,4, and element 5 in a 5 item array does not exist, and you should not try to write to it.

    As for the initialisation that you're trying to do, the compiler will allow this kind of shortcut for static initialisation, but the array sizes on each side of the "=" must match. cust is a 2D array of customer struct's, with the number of elements equal to sizeR*sizeC. But {"AK65"...} is only one record, not sizeR*sizeC records. (Your int ID[4][5] declaration earlier shows you know how to do static initialisation of a 2D array. It's the same for static initialisation of cust, except that each 0 should be replaced with {"AK65"...}.)

    Secondly the compiler has no way to match up the data. There is no customer ID. time is declared as type char, which means you can only store a single character in it, so it can't store "23:45". Same for gate and seatNo.

    Thirdly if you ARE trying to assign "AK45" etc to the single entry in the customer array cust[sizeR][sizeC], you need to drop "customer" so that it isn't declaring a new array, and as explained above this entry doesn't exist; the only valid entries are cust[0...sizeR01][0...sizeC-1].

    Fourthly runtime assignment isn't allowed in this way; it's just a compile-time shortcut, so you must assign each item separately:
    Code:
    cust[a][b].id=27;
    strcpy(cust[a][b].flightNo,"AK65");
    strcpy(cust[a][b].date,"25-12-2008");
    ... etc
    
     
  15. dky8810

    dky8810 New Member

    Joined:
    Nov 15, 2008
    Messages:
    19
    Likes Received:
    0
    Trophy Points:
    0

    like this?
    Code:
    cust[sizeR][sizeC].id=100;
    	strcpy(cust[sizeR][sizeC].flightNo,"AK65");
    	strcpy(cust[sizeR][sizeC].date,"25-12-2008");
    	strcpy(cust[sizeR][sizeC].time,"23:45");
    	strcpy(cust[sizeR][sizeC].gate,"G9");
    i still dont rely understant :

    Thirdly if you ARE trying to assign "AK45" etc to the single entry in the customer array cust[sizeR][sizeC], you need to drop "customer" so that it isn't declaring a new array, and as explained above this entry doesn't exist; the only valid entries are cust[0...sizeR01][0...sizeC-1].
     
  16. dky8810

    dky8810 New Member

    Joined:
    Nov 15, 2008
    Messages:
    19
    Likes Received:
    0
    Trophy Points:
    0
    i no ideal for next part!!!
    help help!
     
  17. dky8810

    dky8810 New Member

    Joined:
    Nov 15, 2008
    Messages:
    19
    Likes Received:
    0
    Trophy Points:
    0
    T.T
    help pls
     
  18. xpi0t0s

    xpi0t0s Mentor

    Joined:
    Aug 6, 2004
    Messages:
    3,009
    Likes Received:
    203
    Trophy Points:
    63
    Occupation:
    Senior Support Engineer
    Location:
    England
    OK. Count the fingers of one hand. One. Two. Three, four five. Six? No, of course not.

    Now count them again, starting at zero instead of one. Zero. One, two, three four. Five? Hopefully no, unless you've grown a new one in the meantime.

    That's what I mean when I say in a five element array, elements 0-4 exist, but 5 does not.

    So if you are assigning to cust[sizeR][sizeC], when cust is only declared as cust[sizeR][sizeC], then you are doing the equivalent of trying to put a ring on the sixth finger on your hand.

    If you can't grasp this then you need to take your tutor aside and tell him you have no idea why an array declared as having five elements only has five elements and why they are numbered 0,1,2,3,4. Getting this kind of understanding is way beyond what can be accomplished in a forum.
     
  19. dky8810

    dky8810 New Member

    Joined:
    Nov 15, 2008
    Messages:
    19
    Likes Received:
    0
    Trophy Points:
    0

    #define sizeR 3
    #define sizeC 4
     
  20. xpi0t0s

    xpi0t0s Mentor

    Joined:
    Aug 6, 2004
    Messages:
    3,009
    Likes Received:
    203
    Trophy Points:
    63
    Occupation:
    Senior Support Engineer
    Location:
    England
    If cust is defined as customer cust[3][4] then the following array entries exist and can be used:
    cust[0][0] cust[0][1] cust[0][2] cust[0][3]
    cust[1][0] cust[1][1] cust[1][2] cust[1][3]
    cust[2][0] cust[2][1] cust[2][2] cust[2][3]

    Which you will see is 3 rows of 4 columns, and neither cust[3][x] nor cust[x][4] are valid. So writing to cust[sizeR=3][sizeC=4] should not be attempted; that location is beyong the end of the array and you would be overwriting memory that belongs to another part of your program.
     

Share This Page

  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.
    Dismiss Notice