Vehicle Rental Management System

Source: Internet
Author: User

① 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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.