佳礼资讯网

 找回密码
 注册

ADVERTISEMENT

查看: 708|回复: 11

C languege (auto ganerate number)

[复制链接]
发表于 12-12-2008 11:13 PM | 显示全部楼层
thx i know ald
  1. /* RAND.C: This program seeds the random-number generator
  2. * with the GetTickCount, then displays 10 random integers.
  3.  */

  4. #include <stdlib.h>
  5. #include <stdio.h>
  6. #include <winbase.h>

  7. void main( void )
  8. {
  9. &#160;  int i;
  10. &#160;  /* Seed the random-number generator with GetTickCount so that
  11. &#160;     the numbers will be different every time we run.
  12. &#160;      */
  13. &#160;  srand(
  14. &#160;      GetTickCount()&#160;
  15. &#160;        );
  16. &#160;  /* Display 10 numbers. */
  17. &#160;  for(
  18. &#160;        i = 0;   i < 10;i++&#160;
  19. &#160;       )
  20. &#160;  printf(
  21. &#160;        "%6d\n", rand()&#160;
  22. &#160;       );
  23. &#160;  }
复制代码
回复

使用道具 举报


ADVERTISEMENT

 楼主| 发表于 12-12-2008 10:41 PM | 显示全部楼层

回复 3# deity01 的帖子

该如何使用C languege 随机产生数字???
例子:
1001
1002
第一个数字不更动(1002)
但不可以用increasing的方法
如:
int id=101;
.........
id++;
回复

使用道具 举报

 楼主| 发表于 12-12-2008 09:24 PM | 显示全部楼层 |阅读模式
How to use C languege to auto generate number???
example:
1001
1002
than 1st number is fit(1002)

by not using this matter:
  1. int id=101;
  2. .........
  3. id++;
复制代码
pls help!!!
回复

使用道具 举报

发表于 12-12-2008 09:32 PM | 显示全部楼层
int id=1001;
id+=1; //???
抱歉,菜鸟一个
回复

使用道具 举报

发表于 12-12-2008 09:44 PM | 显示全部楼层
不懂你在讲什么。。。
回复

使用道具 举报

发表于 12-12-2008 09:46 PM | 显示全部楼层
第一个号码不能变??其他号码就继续increasing?????
回复

使用道具 举报

Follow Us
 楼主| 发表于 12-12-2008 10:36 PM | 显示全部楼层

回复 4# deity01 的帖子

第一个号码不能变
其他号码不是increasing而是随机数发生(random number generation)
回复

使用道具 举报

发表于 12-12-2008 10:37 PM | 显示全部楼层
软件的版本号码吗?
不了解你要什么咚咚
回复

使用道具 举报


ADVERTISEMENT

发表于 12-12-2008 10:43 PM | 显示全部楼层
原帖由 dky8810 于 12-12-2008 10:41 PM 发表
该如何使用C languege 随机产生数字???
例子:
1001
1002
第一个数字不更动(1002)
但不可以用increasing的方法
如:
int id=101;
.........
id++;


random一个 0到999 的数字,然后加1000不就行了咯。。。有什么难度。。
回复

使用道具 举报

 楼主| 发表于 12-12-2008 10:54 PM | 显示全部楼层

回复 6# yeenfei 的帖子

不是!我是一个学生
这是部分于我的assignment!
"Airline Resevation System"
问题旨明:"*IDs are auto generated"
例子:
客户身份证   客户名     性
1001              大卫晒黑   M
1002              珍妮       F
这在我的第二个assignment 在第一个assignment我使用
" 增量方法 "
但是我的指导教师说做错了!!!
他说要用随机数发生(random number generation)!!!
以下是我第一个assignment :
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:
  1. #include<stdio.h>
  2. #include<stdlib.h>
  3. #include<string.h>
  4. #define sizeR 4
  5. #define sizeC 5
  6. #define p 0

  7. void menu();                //function declaration
  8. void Booking();
  9. void Display();


  10. int available=20;                //global variable
  11. int i=0, k=0, z=0, q=0;
  12. int j=65;
  13. int id=101;
  14. int require;

  15. int seatNo[sizeC][sizeR] = {0,0};

  16. typedef struct{                                // structure for flight ticket
  17.         char flightno[5];
  18.         char date[11];
  19.         char time[6];
  20.         char gate[3];
  21. }customer;

  22. customer cust={"AK65","25-12-2008","23:45","G9"}; //global structure

  23. void main()
  24. {
  25.         menu();
  26. }
  27. void menu(void)
  28. {
  29.         int choice;

  30.         printf("\t\t********TARC Airlene Reservation Menu*********\n");
  31.         printf("\t\t1) Booking\n");
  32.         printf("\t\t2) Seat Layout & Occupancy\n");
  33.         printf("\t\t3) Exit\n");

  34.         printf("\t\t\tYour choice : ");
  35.         scanf("%d",&choice);

  36.         switch(choice){
  37.         case 1:
  38.                 Booking();
  39.                 break;
  40.                
  41.         case 2:
  42.                 Display();
  43.                 break;
  44.         default:
  45.                 printf("End the program\n");
  46.                 break;
  47.                
  48.                
  49.         }
  50. }

  51. void Booking()
  52. {
  53.         int m;
  54.         int actualsit[2];
  55.         char name[15];


  56.         //variety the ticket number book from the user
  57.         fflush(stdin);                       
  58.         printf("Enter the number of ticket you want to book :");
  59.         scanf("%d", &require);

  60.         if(available == 0)
  61.         {
  62.                 printf("The flight is fully booked!.\n");
  63.                 system("pause");
  64.                 system("cls");
  65.                 main();
  66.         }
  67.         else if(require>available)
  68.         {
  69.                 printf("Sorry not enough seat for you to book. Please book lesser seat.\n");
  70.                 Booking();
  71.         }
  72.         else if(require < 1 || require >sizeR*sizeC)
  73.         {
  74.                 printf("Error input please try again !! \n");
  75.                 Booking();
  76.         }
  77.         else
  78.         {
  79.                 for(m=1;m<=require;m++)
  80.                 {
  81.                         fflush(stdin);
  82.                         printf("Enter passenger name:");
  83.                         gets(name);
  84.                        
  85.                         if(strlen(name)<1)
  86.                         {
  87.                                 Booking();
  88.                         }
  89.                         else
  90.                         {
  91.                                 while(z<sizeR*sizeC) //generate seat No
  92.                                 {
  93.                                         if(q==4)
  94.                                         {
  95.                                                 j++;
  96.                                                 i++;
  97.                                                 q=0;
  98.                                                 k=0;
  99.                                         }
  100.                                         actualsit[0]=j;  
  101.                                         seatNo[i][k]=id;
  102.                                         actualsit[1]=q+1;
  103.                                         k++;
  104.                                         q++;
  105.                                         z++;
  106.                                         available--;
  107.                                         break;
  108.                                 }

  109.                                 //booking display
  110.                                 printf(" ___________________________________________________________________\n");  //flight ticket layout
  111.                                 printf("|                 ---TARC Airline Booking Ticket---                 |\n");
  112.                                 printf("|                                                                   |\n");
  113.                                 printf("|  Booking ID  :%d\t\t        Flight No  :%s            |\n",id, cust.flightno);
  114.                                 printf("|  Passenger   :%-15s\t        Date       :%s      |\n",name, cust.date);
  115.                                 printf("|\t\t\t\t        Time       :%s           |\n", cust.time );
  116.                                 printf("|\t\t\t\t        Gate       :%s              |\n", cust.gate );
  117.                                 printf("|\t\t\t\t        Seat No.   :%c%d              |\n",actualsit[0],actualsit[1]);
  118.                                 printf("|___________________________________________________________________|\n");
  119.                                
  120.                         }
  121.                        
  122.                
  123.                
  124.                 }
  125.                 id++;
  126.                 system("pause");
  127.                 system("cls");
  128.                 main();
  129.         }

  130. }               

  131. void Display()//seat occupancy layout
  132. {
  133.        
  134.         int i;
  135.         k=0;

  136.         system("cls");
  137.         printf("\tSeat Layout & Occupancy\n");
  138.         printf("      A     B     C     D     E   \n");  
  139.         printf("    _____ _____ _____ _____ _____\n");
  140.         for(i=0;i<sizeR;i++)
  141.         {
  142.                 if (i<sizeR)
  143.                 {
  144.                 printf("   |     |     |     |     |     |\n");
  145.                 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]);
  146.                 printf("   |_____|_____|_____|_____|_____|\n");
  147.                 }       
  148.                 else if(i>k)
  149.                 {
  150.                 printf("   |     |     |     |     |     |\n");
  151.                 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]);
  152.                 printf("   |_____|_____|_____|_____|_____|\n");       
  153.        
  154.                 }
  155.                 if(i==1)
  156.                 {
  157.                         printf("   |\t\tAisle            |\n");
  158.                         printf("   |_____ _____ _____ _____ _____|\n");
  159.                 }

  160.         }
  161.         system("pause");
  162.         system("cls");
  163.         main();
  164. }
复制代码
回复

使用道具 举报

发表于 12-12-2008 11:26 PM | 显示全部楼层
用rand....用之前动动一下time。。提示完毕。。
回复

使用道具 举报

发表于 13-12-2008 06:53 PM | 显示全部楼层
当年我念书时,如果assignment都可以网上救助多好。。。

我也学楼上的做下好人:
既然要随机产生号码,记得确定该号码不会重复(就是说要记录以前产生过的号码)
虽然你是学生,我还是建议你现在就学好variable naming convention (hungarian notation etc), 这样你的程序码对我们比较容易读
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 注册

本版积分规则

 

ADVERTISEMENT



ADVERTISEMENT



ADVERTISEMENT

ADVERTISEMENT


版权所有 © 1996-2023 Cari Internet Sdn Bhd (483575-W)|IPSERVERONE 提供云主机|广告刊登|关于我们|私隐权|免控|投诉|联络|脸书|佳礼资讯网

GMT+8, 22-12-2025 05:57 AM , Processed in 0.108465 second(s), 24 queries , Gzip On.

Powered by Discuz! X3.4

Copyright © 2001-2021, Tencent Cloud.

快速回复 返回顶部 返回列表