Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

How to realize the ticket Management system on C++

2025-01-28 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >

Share

Shulou(Shulou.com)06/01 Report--

This article mainly introduces "how C++ realizes the ticket management system". In the daily operation, I believe that many people have doubts about how C++ realizes the ticket management system. The editor consulted all kinds of materials and sorted out simple and easy-to-use operation methods. I hope it will be helpful to answer the doubts about "how C++ realizes the ticket management system". Next, please follow the editor to study!

There are n departures at a station every day, and each shift has a number (1, 2, 3). N), fixed departure time

Fixed route (starting station, terminal), approximate travel time, fixed rated passenger capacity. Such as

The departure time of the shift, the departure time, the terminal, the travel time, the rated load, the number of tickets

1 8:00 Guanghan 2 45 30, Pixian County

2 6:30 Chengdu, Pixian County

3 7:00 Chengdu, Pixian County

4 10:00 in Chengdu, Pixian County

...

Functional requirements:

(1) enter the shift information (the information is saved in a file), and the shift data can be increased from time to time.

(2) browse the shift information to show the total current status of all shifts (if the current system time exceeds the departure time of a certain shift, the prompt message that "this shift has been issued" is displayed).

(3) Enquiry route: can be queried by shift number and by terminal

(4) ticketing and refund functions

A: tickets can be sold only when the number of booked tickets is less than the rated load and the current system time is less than the departure time, and the number of tickets sold will be updated automatically.

B: when you refund the ticket, enter the frequency of the refund, and only when the bus is not issued can the ticket be refunded. The number of tickets sold will be updated automatically.

Here is the code.

The tools are VS2019, MySQL8.0

Note: please set up the environment of VS in advance, otherwise it will not run. I am a rookie, the code may be more complex than low, light spray.

# define _ CRT_SECURE_NO_WARNINGS#include # include using namespace std;// contains additional dependencies. You can also set / / # pragma comment (lib, "wsock32.lib") / / # pragma comment (lib, "libmysql.lib") MYSQL mysql; / / mysql to connect MYSQL_FIELD* fd; / / field array array char field [32] [32]; / / save the field name two-dimensional array MYSQL_RES* res in the project-property. / / this structure represents a query result set MYSQL_ROW column,row; / / a type-safe representation of row data, the column char query representing the data row; / / query statement bool ConnectDatabase (); / / function declaration void FreeConnect (); bool read (); / / query 1bool search (); / / query 2bool input (); bool piao (); void mainmenu (); bool readtest () Int main (int argc, char** argv) {int m; int k = 1; ConnectDatabase (); mainmenu (); while (krypton1) {printf ("\ n"); printf ("Please select function:"); cin > > m; switch (m) {case 1: input (); break;// enter ticket information case 2: read (); break / / browse ticket information case 3: search (); break;// query ticket information case 4: piao (); break;// ticket sales and refund case 5: K = 0; break;// exit system}} FreeConnect (); system ("pause"); return 0;} / / Connect database bool ConnectDatabase () {/ / initialize mysql mysql_init (& mysql) / / connect to mysql. If the database / / returns false, the connection fails. If you return true, the connection succeeds if (! (mysql_real_connect (& mysql, "localhost", "root", "123456", "chepiao", 3306, NULL, 0)) / / the host, user name, password, database name and port number, respectively. Can be written as a parameter and then passed in {printf ("Error connecting to database:%s\ n", mysql_error (& mysql)) Return false;} else {printf ("Connected success\ n"); return true;}} void mainmenu () {cout n; sprintf (query, "select * from testtable where shift ='"); / / execute the query statement, where all are queried. User is the table name and you can strcat (query, n) with strcpy without quotation marks; strcat (query, abc) Mysql_query (& mysql, "set names gbk"); / / set the encoding format (SET NAMES GBK is also OK), otherwise Chinese garbled mysql_query (& mysql, query) under cmd / / execute the SQL statement / / get the result set if (! (res = mysql_store_result (& mysql) / / get the result set {printf ("Couldn't get result from% s\ n", mysql_error (& mysql)) returned after the end of the sql statement; return false;} for (int I = 0 Fd = mysql_fetch_field (res); iTunes +) / / get the field name strcpy (field [I], fd- > name); int j = mysql_num_fields (res); / / get the number of columns column = mysql_fetch_row (res); a = atoi (column [6]) If (! strcmp (column [7], "this car is not issued") {printf ("\ n"); printf ("refund successful\ n"); printf ("\ n"); for (int I = 0; I

< j; i++) //打印字段 printf("s\t", field[i]); printf("\n"); a = a - 1; itoa(a, column[6], 10); sprintf(query, "update testtable set 已订票人数='"); //执行查询语句,这里是查询所有,user是表名,不用加引号,用strcpy也可以 strcat(query, column[6]); strcat(query, abc); strcat(query, cc); strcat(query, n); strcat(query, abc); mysql_query(&mysql, "set names gbk"); //设置编码格式(SET NAMES GBK也行),否则cmd下中文乱码 mysql_query(&mysql, query); //执行SQL语句 printf("s\ts\ts\ts\ts\ts\ts\ts\n", column[0], column[1], column[2], column[3], column[4], column[5], column[6], column[7]); //column是列数组 } } printf("\n"); printf(" 1 继续售票/退票;2 返回主界面\n"); printf(" 请输入您的操作: "); cin >

> y; if (y = = 1) {piao ();} else if (y = = 2) {mainmenu ();}} at this point, the study on "how to implement the ticket management system for C++" is over. I hope I can solve your doubts. The collocation of theory and practice can better help you learn, go and try it! If you want to continue to learn more related knowledge, please continue to follow the website, the editor will continue to work hard to bring you more practical articles!

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Development

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report