|
查看: 705|回复: 11
|
C languege (auto ganerate number)
[复制链接]
|
|
|
发表于 12-12-2008 11:13 PM
|
显示全部楼层
thx i know ald
- /* 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() 
-   );
-   }
复制代码 |
|
|
|
|
|
|
|
|
|
|

楼主 |
发表于 12-12-2008 10:41 PM
|
显示全部楼层
回复 3# deity01 的帖子
该如何使用C languege 随机产生数字???
例子:
1001
1002
第一个数字不更动(1002)
但不可以用increasing的方法
如:
int id=101;
.........
id++; |
|
|
|
|
|
|
|
|
|
|
How to use C languege to auto generate number???
example:
1001
1002
than 1st number is fit(1002)
by not using this matter:- int id=101;
- .........
- 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????? |
|
|
|
|
|
|
|
|
|
|

楼主 |
发表于 12-12-2008 10:36 PM
|
显示全部楼层
回复 4# deity01 的帖子
第一个号码不能变
其他号码不是increasing而是随机数发生(random number generation) |
|
|
|
|
|
|
|
|
|
|
发表于 12-12-2008 10:37 PM
|
显示全部楼层
|
|
|
|
|
|
|
|
|
|
发表于 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:- #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();
- }
复制代码 |
|
|
|
|
|
|
|
|
|
|
发表于 12-12-2008 11:26 PM
|
显示全部楼层
|
用rand....用之前动动一下time。。提示完毕。。 |
|
|
|
|
|
|
|
|
|
|
发表于 13-12-2008 06:53 PM
|
显示全部楼层
当年我念书时,如果assignment都可以网上救助多好。。。
我也学楼上的做下好人:
既然要随机产生号码,记得确定该号码不会重复(就是说要记录以前产生过的号码)
虽然你是学生,我还是建议你现在就学好variable naming convention (hungarian notation etc), 这样你的程序码对我们比较容易读 |
|
|
|
|
|
|
|
|
| |
本周最热论坛帖子
|