Home > Back-end >  C the final course design of the train ticketing system
C the final course design of the train ticketing system

Time:04-26

The train ticketing system

One, the project need
(1) the query function: query ticket information, including the origin, number and more tickets and tickets;
(2) booking function: ticket booking;
(3) modify functions: modify the booking information;
(4) the school management functions: input the basic information of the ticket;
(5) display function: the query to the information displayed, available for users to view,
Second, the system design thought
(1) the train ticket booking system general structure,
The main program is divided into the ticket service and system management (ticketing and station management),
(2) the ticket service module is divided into the query, booking tickets and refund,
(3) the station management into the query, add, modify, and delete,
(4) ticket management into the query, add, delete and modify,
Three, the project implementation
1 header file ticket. H
Structure defines the station information, booking information structure and its auxiliary structures; Function declarations of them respectively according to the system management, site management, ticketing management, ticketing services and advocate five big module partition and statement,
//# ifdef _TICKET_H//whether TICKET macro is not defined in the 
# define _TICKEY_H//define TICKET preprocessor macros

# include & lt; Stdio. H>
# include & lt; stdlib.h>
# include & lt; String. H>
# include & lt; Time. H>//UTC (the world standard Time), the Calendar Time (Calendar Time), the epoch (point), the clock tick (clock ticks)
# include & lt; Conio. H>

100//# define STARION_NUM station number
1000//# define TICKET_NUM ticket number
10//# define STR_LEN length of an array of characters

Typedef struct
{
Int stdtionId; No.//the station
Char form [STR_LEN];//tickets starting point
Char to [STR_LEN];//ticket end
Int money;//ticket prices
Int Numbers;//votes
} StationInfo;//the station ticket information

Typedef struct
{
StationInfo station [STATION_NUM];//structure counter
int count;//counter
} Station;

Typedef struct
{
Int stationId; No.//the station
Int seatId;//seat number, and the associated votes
Int ticketId;//ticket code
Char trainId [STR_LEN];//the train service
Char date [STR_LEN];//departure date
Char time [STR_LEN];//departure time
} TicketInfo;//ticket information

Typedef struct
{
TicketInfo ticket [TICKET_NUM];
int count;
} Ticket;

Typedef struct
{
Int autoId;//randomly generated number booking, refund use
Char name [STR_LEN];//booking name
TcketInfo ticketInfo;
} BookInfo;//booking information

Typedef struct
{
Bookinfo book [TICKET_NUM];
int count;
} the Book;

/* module file doMain. Use the function module of */c
Void start (int & amp; The flag);//system began to function
Void the initialize (Station & amp; Station, Ticket & amp; Ticket, Book & amp; The book);//initialization data

/* system management module file systemManage. Use the function module of */c
//system management
Void systemManage (Station & amp; Station, Ticket & amp; Ticket, Book & amp; The book, int & amp; The flag);

/* site management module file stationManage. Use the function module of */c
Void addStation (Station & amp; Station, Ticket & amp; Ticket, int I);//add the station
Void printStation (Station & amp; Station);//show the station information
Void stationManage (Station & amp; Station, Ticket & amp; Ticket, Book & amp; The book, int & amp; The flag);//site management
Void updateStation (Station & amp; Station, Ticket & amp; Ticket);//update the station information
Void updateTicketPrice (Station & amp; S, int stationId);//update ticket price unrealized
Void updateTicketNum (Station & amp; S, int stationId, Ticket & amp; T);//update ticket number unrealized

/* ticket management module file ticketManage. C use function */
Void addTicket (int sationId, int count, Ticket & amp; Ticket);//add ticket information
Void deleteTicket (Station & amp; Station, Ticket & amp; Ticket);//delete ticket information
Void showOnsaleTickets (Stataion & amp; Station);//display for sale ticket
Void showsaledTickets (Book b);//show sold information
Void ticketManage (Station & amp; Station, Ticket & amp; Ticket, Book & amp; The book, int & amp; The flag);//ticket management

Ticketing services/* customer file ticketServices. Use the function module of */c
Void ticketBook (Book & amp; The book, Ticket & amp; Ticket, Station & amp; S);//booking
Void addBookInfo (Book & amp; B, Ticket & amp; T, int stationId, int bookNum);//add booking information
Void ticketInquire (Station s, Ticket Ticket);//query ticket information
Void ticketServices (Station & amp; S, Ticket & amp; T, Book & amp; B, int & amp; The flag);//ticketing service
//# endif

2 tone module implementation file doMain. CPP

 # include "ticket. H" 

Station Station;
Ticket Ticket;
The Book Book;
Int flag=1;

Void the initialize (Station & amp; Station, Ticket & amp; Ticket, Book & amp; The book)//initialized data
{
Station. The count=0;//the station information initialization
Ticket. Count=0;//initialization ticket information
Book. Count=0;//initialization booking information
}

Void start (int& Falg)//system began to function
{
Int option;
If (flag)
{
int i=0;//the first input information station number
Printf (" \ n the system run for the first time, please add the station and the corresponding ticket information! \n");
The initialize (station, ticket);//initialization data
Printf (" \ n please add the number of station information input: ");
The scanf (" % d ", I);
If (I & gt; 0)
{
AddStation (station, the ticket, I);//add the station I add the station number
Flag=1;
} the else start (flag);//other input data, rebuild execution system began to function, the judgement is equivalent to the input
}
//system interface, 3 operating options
printf("\n");
Printf (" \ t \ t * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * \ n ");
Printf (" \ t \ \ t t ticketing services -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- 1 \ n ");
Printf (" \ t \ \ t t system management -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- 2 \ n ");
Printf (" \ t \ \ t t exit system -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- - 0 \ n ");
Printf (" \ t \ t * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * \ n ");
Printf (" \ t \ t please select: ");
The scanf (" % d ", & amp; Option);

The switch (option)
{
Case 1:
TicketServices (station, ticket, book, flag);//ticketing service
Flag=0;
break;
Case 2:
SystemManage (station, ticket, boob, flag);//system administration menu
Flag=0;
break;
Case 0:
The use of printf (" thank you! \n");
exit(0);//0 code all normal exit; Non-normal exit 1
break;
Default://input judgment of option
Printf (" \ n choose wrong! \n");
Flag=0;
Start (flag);
break;
}

}

Int main ()
{
Srand ((unsigned int) time (NULL);//must use srand before calls to rand () () a good random number seed, not set rand () will automatically set the random number seed
While (1) start (flag);


nullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnull
  • Related