① Input at least five vehicle information using the struct Array
(Note that the vehicle status is stored in the file and will be directly read next time)
② Vehicle rental Interface
Different prompts are displayed based on the vehicle status.
# Include <stdio. h> void menu () // establish the system menu {printf ("\ n \ t welcome to lease the company's vehicles \ n "); printf ("\ t \ T1. query all vehicles \ n"); printf ("\ t \ T2. return to rental vehicles \ n "); printf ("\ t \ T3. rent an existing vehicle \ n"); printf ("\ t \ t0. exit the Leasing System \ n ");} // create the struct node {int num, doing; char carname [10], carnum [10], money [10], day [10], daymoney [10],;} INF [5]; // enter the vehicle information void input (struct node INF [5]) {int I; file * FP; // define the file pointer printf ("\ t rental car company system \ n"); PR INTF ("Enter Vehicle Information \ n"); printf ("0: Rental Vehicle 1: Not rental vehicle \ n "); printf ("| No. | model | license plate number | deposit | limited days | daily rental price | current status \ n"); printf ("------------------------------------------------------- \ n "); if (FP = fopen ("E: \ abc.txt", "WB") = NULL) {printf ("cannot open file! \ N "); Return ;}for (I = 0; I <5; I ++) {scanf ("% d % S % d", & INF [I]. num, INF [I]. carname, INF [I]. carnum, INF [I]. money, INF [I]. day, INF [I]. daymoney, & INF [I]. doing);} fwrite (INF, sizeof (struct node), 5, FP); rewind (FP);} // read the int read () {file * FP; if (FP = fopen ("E: \ abc.txt", "rb") = NULL) {return-1 ;}else {fread (INF, sizeof (struct node), 5, FP); return 1 ;}/// void putout (struct node INF [5]) {Int I; printf ("\ n inventory Vehicle Information overview \ n "); printf ("| no | model | license plate number | deposit | Number of days | daily rental price | current status \ n"); printf ("License \ n"); for (I = 0; I <5; I ++) {printf ("% d % S % s", INF [I]. num, INF [I]. carname, INF [I]. carnum, INF [I]. money, INF [I]. day, INF [I]. daymoney); If (INF [I]. doing = 1) printf ("rent \ n"); else printf ("rent \ n");} printf ("\ n ");} // return the void retur function of the rented vehicle N (INT inum) {If (INF [inum]. doing = 1) {printf ("\ n the car is not rented \ n");} else {INF [inum]. doing = 1; printf ("| No. | vehicle model | license plate number | deposit | limited number of days | daily rental price | current status \ n"); printf ("inherit \ n "); printf ("% d % S % s", INF [inum]. num, INF [inum]. carname, INF [inum]. carnum, INF [inum]. money, INF [inum]. day, INF [inum]. daymoney); printf ("not rented \ n"); printf ("operation successful ............ \ N ") ;}// the void borrow (INT inum) {If (INF [inum]. doing = 0) {printf ("\ n the car has been rented \ n");} else {INF [inum]. doing = 0; printf ("| No. | vehicle model | license plate number | deposit | limited number of days | daily rental price | current status \ n"); printf ("inherit \ n "); printf ("% d % S % s", INF [inum]. num, INF [inum]. carname, INF [inum]. carnum, INF [inum]. money, INF [inum]. day, INF [inum]. daymoney); printf ("rental \ n"); printf ("Operation Success ............ \ N ") ;}} int main () {int choose = 0; int fist; fist = read ();
/* This is an important part of the program,
Use fist to determine whether it is the first logon.
When you log on for the first time, call the input function to create a new file,
If it is the first logon, the file content is read directly.
*/
If (fist =-1) {printf ("this is your first logon to the system \ n"); input (INF); read () ;}while (1) {menu (); int inum; printf ("\ t please enter your required service number:"); scanf ("% d", & choose ); if (choose = 1) // query all vehicle functions {putout (INF);} else if (choose = 2) // return the rental vehicle {printf ("Enter the return vehicle number:"); scanf ("% d", & inum); Return (inum );} else if (choose = 3) // rent an existing vehicle {printf ("Enter the rental vehicle number:"); scanf ("% d", & inum ); borrow (inum);} else if (choose = 0) // exit the leasing system {printf ("\ n \ t welcome to come back next time \ n"); break ;}} return 0 ;}
Program defects: only information of five groups of vehicles can be entered, and information of more than five groups cannot be entered.
Knowledge used:
1. struct
2. File