1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.

C languege (auto ganerate number)

Discussion in 'C' started by dky8810, Dec 12, 2008.

  1. dky8810

    dky8810 New Member

    Joined:
    Nov 15, 2008
    Messages:
    19
    Likes Received:
    0
    Trophy Points:
    0
    How to use C languege to auto generate number???
    example:
    1001
    1002
    than 1st number is fit(1002)

    by not using this matter:

    Code:
    int id=101;
    .........
    id++;
    
    pls help!!!
     
  2. xpi0t0s

    xpi0t0s Mentor

    Joined:
    Aug 6, 2004
    Messages:
    3,012
    Likes Received:
    203
    Trophy Points:
    0
    Occupation:
    Senior Support Engineer
    Location:
    England
    The question isn't clear. C does not automatically generate numbers, you have to write code to produce a given output from a specific input. Can you give an example of what input you want the program to use (if any), and what output you want the computer to print?

    Why would you not want to declare and increment an integer? It seems those would be fairly essential operations, although this does depend on what output you want the program to produce.
     
  3. dky8810

    dky8810 New Member

    Joined:
    Nov 15, 2008
    Messages:
    19
    Likes Received:
    0
    Trophy Points:
    0
    i'm student this is part of my assignment
    question is"Airline Resevation System"
    question saying that "*IDs are auto generated"
    example:
    customer ID* customer name gender
    1001 David Tan M
    1002 Jenny Lim F

    this is my second assignment in my 1st assignment i are using
    "increment method"
    but my tutor has saying that is wrong !!!
    than i ask him how to do (auto generated) he answer me: i jz can gv you explaintion, assignment need do by yourself i tech you before !!!than i go find the note but cant get it!!!
    this is my 1st assignment:
    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 |
    |-------------------------------------------|

    answer
    Code:
    #include<stdio.h>
    #include<stdlib.h>
    #include<string.h>
    #define sizeR 4
    #define sizeC 5
    #define p 0
    
    void menu();		//function declaration
    void Booking();
    void Display();
    
    
    int available=20;		//global variable
    int i=0, k=0, z=0, q=0;
    int j=65;
    int id=101;
    int require;
    
    int seatNo[sizeC][sizeR] = {0,0};
    
    typedef struct{				// structure for flight ticket
    	char flightno[5];
    	char date[11];
    	char time[6];
    	char gate[3];
    }customer;
    
    customer cust={"AK65","25-12-2008","23:45","G9"}; //global structure
    
    void main()
    {
    	menu();
    }
    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\n");
    		break;
    		
    		
    	}
    }
    
    void Booking()
    {
    	int m;
    	int actualsit[2];
    	char name[15];
    
    
    	//variety the ticket number book from the user
    	fflush(stdin);			
    	printf("Enter the number of ticket you want to book :");
    	scanf("%d", &require);
    
    	if(available == 0)
    	{
    		printf("The flight is fully booked!.\n");
    		system("pause");
    		system("cls");
    		main();
    	}
    	else if(require>available)
    	{
    		printf("Sorry not enough seat for you to book. Please book lesser seat.\n");
    		Booking();
    	}
    	else if(require < 1 || require >sizeR*sizeC)
    	{
    		printf("Error input please try again !! \n");
    		Booking();
    	}
    	else
    	{
    		for(m=1;m<=require;m++)
    		{
    			fflush(stdin);
    			printf("Enter passenger name:");
    			gets(name);
    			
    			if(strlen(name)<1)
    			{
    				Booking();
    			}
    			else
    			{
    				while(z<sizeR*sizeC) //generate seat No
    				{
    					if(q==4)
    					{
    						j++;
    						i++;
    						q=0;
    						k=0;
    					}
    					actualsit[0]=j;  
    					seatNo[i][k]=id;
    					actualsit[1]=q+1;
    					k++;
    					q++;
    					z++;
    					available--;
    					break;
    				}
    
    				//booking display
    				printf(" ___________________________________________________________________\n");  //flight ticket layout
    				printf("|                 ---TARC Airline Booking Ticket---                 |\n");
    				printf("|                                                                   |\n");
    				printf("|  Booking ID  :%d\t\t        Flight No  :%s            |\n",id, cust.flightno);
    				printf("|  Passenger   :%-15s\t        Date       :%s      |\n",name, cust.date);
    				printf("|\t\t\t\t        Time       :%s           |\n", cust.time );
    				printf("|\t\t\t\t        Gate       :%s              |\n", cust.gate );
    				printf("|\t\t\t\t        Seat No.   :%c%d              |\n",actualsit[0],actualsit[1]);
    				printf("|___________________________________________________________________|\n");
    				
    			}
    			
    		
    		
    		}
    		id++; 
    		system("pause");
    		system("cls");
    		main();
    	}
    
    }		
    
    void Display()//seat occupancy layout
    {
    	
    	int i;
    	k=0;
    
    	system("cls");
    	printf("\tSeat Layout & Occupancy\n");
    	printf("      A     B     C     D     E   \n");  
    	printf("    _____ _____ _____ _____ _____\n");
    	for(i=0;i<sizeR;i++)
    	{
    		if (i<sizeR)
    		{ 
    		printf("   |     |     |     |     |     |\n");
    		printf(" %d | %3d | %3d | %3d | %3d | %3d |\n", i+1,seatNo[i][k],seatNo[i][k+1],seatNo[i][k+2],seatNo[i][k+3],seatNo[i][k+4]);
    		printf("   |_____|_____|_____|_____|_____|\n");
    		}	
    		else if(i>k)
    		{
    		printf("   |     |     |     |     |     |\n");
    		printf(" %d | %3d | %3d | %3d | %3d | %3d |\n", i+1,seatNo[i][k],seatNo[i][k+1],seatNo[i][k+2],seatNo[i][k+3],seatNo[i][k+4]);
    		printf("   |_____|_____|_____|_____|_____|\n");	
    	
    		}
    		if(i==1)
    		{
    			printf("   |\t\tAisle            |\n");
    			printf("   |_____ _____ _____ _____ _____|\n");
    		}
    
    	}
    	system("pause");
    	system("cls");
    	main();
    }
    
     
  4. xpi0t0s

    xpi0t0s Mentor

    Joined:
    Aug 6, 2004
    Messages:
    3,012
    Likes Received:
    203
    Trophy Points:
    0
    Occupation:
    Senior Support Engineer
    Location:
    England
    Can't see what's wrong with the id++ part. It's not stored anywhere as far as I can see.

    Interesting use of recursion. Are you sure you really know why you've used it in that way?

    Good use of single character variable names. I haven't got a clue what the code is doing; the intent is absolutely impossible to determine. Very good for job security, that.

    What doesn't the program do that you want? Apart from the autogenerated ID, that is.
     
  5. dky8810

    dky8810 New Member

    Joined:
    Nov 15, 2008
    Messages:
    19
    Likes Received:
    0
    Trophy Points:
    0
    thx i know ald
    Code:
    /* RAND.C: This program seeds the random-number generator
    * with the GetTickCount, then displays 10 random integers.
     */
    
    #include <stdlib.h>
    #include <stdio.h>
    #include <winbase.h>
    
    void main( void )
    {
       int i;
       /* Seed the random-number generator with GetTickCount so that
          the numbers will be different every time we run.
           */
       srand(
           GetTickCount() 
             );
       /* Display 10 numbers. */
       for(
             i = 0;   i < 10;i++ 
            )
       printf(
             "%6d\n", rand() 
            );
       }
     
  6. xpi0t0s

    xpi0t0s Mentor

    Joined:
    Aug 6, 2004
    Messages:
    3,012
    Likes Received:
    203
    Trophy Points:
    0
    Occupation:
    Senior Support Engineer
    Location:
    England
    M gn stp sng cplt wds, th u l cn c w fkn dft t s 2 wk t wt h fk u n bt.
     
  7. xpi0t0s

    xpi0t0s Mentor

    Joined:
    Aug 6, 2004
    Messages:
    3,012
    Likes Received:
    203
    Trophy Points:
    0
    Occupation:
    Senior Support Engineer
    Location:
    England
    Gg, o gdu xi eo'u J () tuq toh wxmt muhuis oe () odsnou di muus c o? Decode THAT!
     
  8. skp819

    skp819 New Member

    Joined:
    Dec 8, 2008
    Messages:
    89
    Likes Received:
    3
    Trophy Points:
    0
    Absolutely, I don't think that I understand what you said all.

    Due to my understand It's my answer:

    You can use a large number begin with 1
    ex: id = 1000;
    And after that you can general other number so that it's less than id
    ex: id2 = rand()%id;
    And finally you can sum both of them
    ex: result = id + id2;
     

Share This Page