c++ 车辆租赁信息管理系统 管理系统 实验设计 课程作业

#include <iostream>
#include <conio.h>
#include <fstream>
#include <windows.h>
#include <string.h>
#include <stdio.h>
#include <time.h>
#include <cstdlib>

using namespace std;

void customerData();
int carCount();
int custCount();
int rate(int, int);
void newCustData();
void carData ();
void admin();
void user();
void menu();
void fullscreen();
void art();
void exitArt();
void newCarData();
void delCar();
void displayCar();
void existingCust();
void load();
void load_CHECK();
void gotoxy(int , int );
void time();
void Boarder();
int countUser();
void tNc();
void readUserPass();
void availCar();
int countAvail();
const string currentDateTime();
const string Date();
void date();
void dispAvailCar();
void GotoXY(int , int );
void load_EXIT();
void load_UPDATE();
void newUserPass();
void password();
void resetAvail();
void showCarData();
void welcome();

struct car
{
    char plate_num[10];
    char brand[20];
    char model[20];
    float capacity;
    char colour[20];
    float rate_per_hour;
    float rate_per_half;
    float rate_per_day;
    char transmission[6];
};

struct customer
{
    int id;
    char name[100];
    char phone[15];
    char ic[15];
    char address[1500];
};

struct pass
{
    int ID;
    char passWord[20];
    
};

    pass userPass[1000];
    car rent[1000];
    customer cust[1000];
    car avail[1000];
    
void fullscreen()
{
    keybd_event(VK_MENU,0x38,0,0);
    keybd_event(VK_RETURN,0x1c,0,0);
    keybd_event(VK_RETURN,0x1c,KEYEVENTF_KEYUP,0);
    keybd_event(VK_MENU,0x38,KEYEVENTF_KEYUP,0);
}

const string currentDateTime() 
{
    time_t     now = time(0);
    struct tm  tstruct;
    char       buf[80];
    tstruct = *localtime(&now);
    strftime(buf, sizeof(buf), "%d/%m/%Y 时间: %X", &tstruct);

    return buf;
}

const string Date() 
{
    time_t     now = time(0);
    struct tm  tstruct;
    char       buf[80];
    tstruct = *localtime(&now);
    strftime(buf, sizeof(buf), "%d/%m/%Y 时间: %X", &tstruct);

    return buf;
}

void time()
{
    int i=0;
    
    while( i<5)
    {
    Boarder();
    gotoxy(20,20);
    std::cout <<"\n\n\n\n\n\t  |\t\t\t\t日期: "<<currentDateTime() << std::endl;
    Sleep(900);
    system("cls");
    i++;
    }
    menu();
}

void date()
{
    cout <<"\n\t  |\t\t\t\t\t\t日期: "<<Date()<<endl;

}

void readUserPass()
{
    ifstream ifs;
    ifs.open("UserPass.txt");
    
    int i;
    while(!ifs.eof())
    {
        ifs>>userPass[i].ID;
        ifs.ignore();
        ifs.getline(userPass[i].passWord,20);
        i++;
    }
    ifs.close();
}

void password()
{
    Boarder();
    
   countUser();
   string password;
   char c;
   gotoxy(40,20);
   cout << "\n\n\n\n\t  |\t\t\t密码: ";

    while(c != '\r') //循环直到按下回车键
         {
         c = getch();
         if(c == 0)
            {
            switch(getch())
               {
               default:
                  break;            
               };
            }
         else if(c == '\b')   //如果按下退格键
            {
            if(password.size() != 0)  //如果密码字符串包含数据,则擦除最后一个字符
               {
               cout << "\b \b";
               password.erase(password.size() - 1, 1);
               }
            continue;
            }
         else if(c <= '9' && c >= '0' || c >= 'a' && c <= 'z' || c >= 'A' && c <= 'Z')  //如果用户输入1-9、 a-z 或 a-z,将其添加到密码中并显示星号
            {
            password += c;
            cout << "*";
            }
         else
            continue;
         }
         
         for(int i=0; i<countUser();i++)
         {
             if(password.compare(userPass[i].passWord)==0)
             {
                 system("cls");
                 load_CHECK();
                  admin();
             }
         }
         
         
          if(password == "a")
              {
          system("cls");
          load_CHECK();
          admin();
              }
              
          else
          cout<<"\n\t  |\t\t\t密码错误.. 呼叫管理员";
          cout<<"\n\t  |\t\t\t回到主菜单.."<<endl;
          cout<<"\n\t  |\t\t\t";
          Sleep(1000);
          cout<<"\n\t  |\t\t\t按回车键继续.";
          cout<<"\n\t  |\t\t\t";
          getch();
          menu();
         
    
    
}

void gotoxy(int x, int y)
{

 COORD coord;

 coord.X = x;

 coord.Y = y;

 SetConsoleCursorPosition(GetStdHandle(STD_OUTPUT_HANDLE), coord);

}

void load()
{
    Boarder();
    
    int timer =5+ rand()%20;
    int row,col,r,c,q;
    gotoxy(65,34);
    cout<<"启动 ...";
    gotoxy(60,36);
    for(r=1;r<=timer;r++)
    {
    for(q=0;q<=100000000;q++);//慢慢地显示这个角色
    printf("%c",177);
    }
    Sleep(100);
    system("cls");
}

void load_CHECK()
{
    Boarder();
    int timer = rand()%5+1;
    int row,col,r,c,q;
    gotoxy(65,34);
    printf("登录...");
    gotoxy(60,36);
    for(r=1;r<=timer;r++)
    {
    for(q=0;q<=100000000;q++);//慢慢地显示这个角色
    printf("%c",177);
    }
    Sleep(100);
    system("cls");
}

void load_UPDATE()
{
    Boarder();
    
    int row,col,r,c,q;
    int timer = rand()%25+1;
    gotoxy(65,34);
    printf("更新数据库...");
    gotoxy(60,36);
    for(r=1;r<=timer;r++)
    {
    for(q=0;q<=100000000;q++);//慢慢地显示这个角色
    printf("%c",177);
    }
    Sleep(100);
    system("cls");
}

void load_EXIT()
{
    Boarder();
    
    int row,col,r,c,q;
    int timer = rand()%5+1;
    gotoxy(65,34);
    printf("下线...");
    gotoxy(60,36);
    for(r=1;r<=timer;r++)
    {
    for(q=0;q<=100000000;q++);//慢慢的显示这个角色 
    printf("%c",177);
    }
    Sleep(100);
    system("cls");
}

void GotoXY(int x, int y)
{
    HANDLE a;
    COORD b;
    fflush(stdout);
    b.X = x;
    b.Y = y;
    a = GetStdHandle(STD_OUTPUT_HANDLE);
    SetConsoleCursorPosition(a,b);
 }

void Boarder()
{
int i;
   system("cls");
   for(i=10;i<140;i++)
   {
       GotoXY(i,10);
           cout<<"=";
       GotoXY(i,58);
           cout<<"=";
   }
   for(i=10;i<58;i++)
   {
       GotoXY(10,i);
           cout<<"|";
       GotoXY(140,i);
               cout<<"|";
   }
}

void art()
{

    Boarder();
    gotoxy(0, 20);
    
    ifstream ifs ("art.txt");    
    string Lines = "";
    
    if (ifs)
    {
        while (ifs.good ())
        {
            string TempLine;
            getline (ifs , TempLine);
            TempLine += "\n";
        
            Lines += TempLine;
        }
        
    cout << Lines;
    date();
    }
    
    ifs.close ();
}

void welcome()
{

    Boarder();
    gotoxy(0, 30);
    ifstream ifs ("welcome.txt");    
    string Lines = "";
    
    if (ifs)
    {
        while (ifs.good ())
        {
            string TempLine;
            getline (ifs , TempLine);
            TempLine += "\n";
        
            Lines += TempLine;
        }
        
    cout << Lines;

    
    }
    cout<<"\n\t  |\t\t\t\t\t\t\t";
    ifs.close ();
    Sleep(1000);
    
}
    
void exitArt()
{
    Boarder();
    gotoxy(0, 30);
    ifstream ifs ("exit art.txt");    
    string Lines = " ";
    
    if (ifs)
    {
        while (ifs.good ())
        {
            string TempLine;
            getline (ifs , TempLine);
            TempLine += "\n";
        
            Lines += TempLine;
        }
        
    cout << Lines;
    
    }
    cout<<"\n\t  |\t\t\t\t\t\t\t";
    ifs.close ();
    Sleep(3000);
    exit(0);
}

int rate(int hour, int j)
{
    int hour_24, hour_12, hour_1;
    int total, total_24, total_12, total_1;
    
    hour_24=hour/24;
    hour_12=(hour - hour_24*24)/12;
    hour_1=(hour - hour_24*24 - hour_12*12)/1;
    
    total_24 = hour_24 * rent[j].rate_per_day;
    total_12 = hour_12 * rent[j].rate_per_half;
    total_1 = hour_1 * rent[j].rate_per_hour;
    
    total = total_24 + total_12 + total_1;
    return total;
}

void customerData()
{
    ifstream ifs;
    ifs.open("Customer.txt");
    int custNum = 0;
    
    while (!ifs.eof())
    {
        ifs >> cust[custNum].id;
        ifs.ignore();
        ifs.getline(cust[custNum].name,100,';');
        ifs.getline(cust[custNum].phone,15,';');
        ifs.getline(cust[custNum].ic,15,';');
        ifs.getline(cust[custNum].address,1500);
        custNum++;
    }
    
    ifs.close();
}

int carCount()
{
    int numOfCar = 0;
    ifstream ifs("car rental.txt"); 

    string word;
    while (getline(ifs, word))
    {
        if (!word.empty())
            numOfCar++;
    }
    
    ifs.close();

    return numOfCar;
}

int custCount()
{
    int numOfCust = 0;
    ifstream ifs("Customer.txt"); 

    string word;
    while (getline(ifs, word))
    {
        if (!word.empty())
            numOfCust++;
    }

    ifs.close();

    return numOfCust;
}

int countUser()
{
    int numOfCust = 0;
    ifstream ifs("UserPass.txt"); 

    string word;
    while (getline(ifs, word))
    {
        if (!word.empty())
            numOfCust++;
    }

    ifs.close();

    return numOfCust;
}

int countAvail()
{
    int numOfCust = 0;
    ifstream ifs("available.txt"); 

    string word;
    while (getline(ifs, word))
    {
        if (!word.empty())
            numOfCust++;
    }

    ifs.close();

    return numOfCust;
}

void displayCar()
{
    cout << "\t  |  车牌号\t品牌\t 模型\t 容量   颜色   每小时收费率   每十二小时收费率   每二十四小时收费率   传输" << endl;
    cout << "\t  |  =======================================================================================================================" << endl;
    for (int i = 0; i < carCount(); i++)
    {
        cout << "\t  |   " << rent[i].plate_num << "\t\t" << rent[i].brand << "\t " << rent[i].model << "\t   " << rent[i].capacity << "\t     "
             << rent[i].colour << "\t  " <<rent[i].rate_per_hour << "\t\t    " << rent[i].rate_per_half << "\t\t    " << rent[i].rate_per_day 
             << "\t\t       " << rent[i].transmission << endl;
    }
}

void dispAvailCar()
{
    cout << "\t  |  车牌号\t品牌\t 模型\t 容量   颜色   每小时收费率   每十二小时收费率   每二十四小时收费率   传输 " << endl;
    cout << "\t  |  =======================================================================================================================" << endl;
    for (int i = 0; i < countAvail(); i++)
    {
        cout << "\t  |   " << avail[i].plate_num << "\t\t" << avail[i].brand << "\t " << avail[i].model << "\t   " << avail[i].capacity << "\t     "
             << avail[i].colour << "\t  " <<avail[i].rate_per_hour << "\t\t    " << avail[i].rate_per_half << "\t\t    " << avail[i].rate_per_day 
             << "\t\t       " << avail[i].transmission << endl;
    }
}

void existingCust()
{
    
    
    int tempCust, hour, userID;
    char carSelect[10];
    tempCust = custCount() - 1;
    ofstream log;
    log.open("Log.txt", fstream::app);
    ofstream ofs;
    ofs.open("temp.txt");
    cout<<"\n\n\n\n";
    cout << endl;
    
    cout<<"\n\n";
    art();
    cout << endl;
    
    cout << "\n\t  |\t\t\t\t请输入用户名 : ";
    cin >> userID;
    
    for (int i = 0 ; i < custCount() ; i++)
    {
        if (userID == cust[i].id)
        {
            cout<<"\n\t  |\t\t\t\t\t欢迎 ";
            cout << cust[i].name;
            log <<"\n姓名: "<< cust[i].name;
            cout<<"\t  |\t身份证号 ";
            cout << cust[i].id;
            cout << "\n\n";
            log<<"\n手机号: "<<cust[i].phone;
            log<<"\n信用卡: "<<cust[i].ic;
        }
    }
    
    
    dispAvailCar();
    
    cout<<"\n\n\t  |\t\t\t\t\t请选车";
    cout<<"\n\t  |\t\t\t\t\t车牌号 : ";
    cin >> ws;
    cin.getline(carSelect,10);
    int x=countAvail();
    for(int i = 0; i < countAvail(); i++)
    {
        if (strcmp(carSelect,avail[i].plate_num) != 0)
        {
            ofs << avail[i].plate_num;
            ofs << " ";
            ofs << avail[i].brand;
            ofs << " ";
            ofs << avail[i].model;
            ofs << " ";
            ofs << avail[i].capacity;
            ofs << " ";
            ofs << avail[i].colour;
            ofs << " ";
            ofs << avail[i].rate_per_hour;
            ofs << " ";
            ofs << avail[i].rate_per_half;
            ofs << " ";
            ofs << avail[i].rate_per_day;
            ofs << " ";
            ofs << avail[i].transmission;
            if(i != countAvail())
            {
                ofs<<endl;
            }
            
            
        }
    }
    
    ofs.close();
    
    remove("available.txt");
    rename("temp.txt","available.txt");
    cout << "\t  |\t\t\t\t\t租金时数 : ";
    cin >> hour;
    int j;
    for(int i = 0; i < carCount(); i++)
    {
        if (strcmp(carSelect,rent[i].plate_num) == 0)
        {
            j = i;

            log<<"\n车: "<<rent[i].plate_num;
            log<<"\n品牌: "<<rent[i].brand;
            log<<"\n模型: "<<rent[i].model;
            log <<"\n时间: "<< hour;
            log <<"\n付款: "<< rate(hour,j);
        }
    }
    
    cout << "\t  |\t\t\t\t以...为代价 " << hour << " 租金时间: rm ";
    cout << rate(hour,j);
    
    log <<"\n日期: "<<currentDateTime();
    log<<"\n==========================================================";
    log.close();

    Sleep(5000);
    system("cls");
    menu();
}

void newCustData ()
{
    cout<<"\n\n";
    art();
    cout << endl;
    
    availCar();
    ofstream ofs,log;
    ofs.open("Customer.txt", fstream::app);
    log.open("Log.txt", fstream::app);
    ofs << endl;
    ofstream availTemp;
    availTemp.open("availtemp.txt");
    cout<<"\n\n\n\n";
    cout << endl;
    
    
    cust[custCount()].id = custCount() + 1001;
    ofs << cust[custCount()].id;
    ofs << ";";
    
    
    cout << "\n\n";
    cout << "\n\t  |\t\t\t\t\t 请输入以下数据 : " << endl;
    
    cout << "\n\t  |\t\t\t\t\t  姓名 : ";
    cin >> ws;
    cin.getline(cust[custCount()].name,100);
    ofs << cust[custCount()].name<<";";
    log <<"\n姓名: "<< cust[custCount()].name;
    
    cout << "\t  |\t\t\t\t\t  手机号 : ";
    cin.getline(cust[custCount()].phone,15);
    ofs << cust[custCount()].phone;
    ofs << ";";
    log <<"\n手机号: "<< cust[custCount()].phone;
    
    
    cout << "\t  |\t\t\t\t\t  信用卡: ";
    cin.getline(cust[custCount()].ic,15);
    ofs << cust[custCount()].ic;
    ofs << ";";
    log <<"\n信用卡: "<< cust[custCount()].ic;
    
    cout << "\t  |\t\t\t\t\t  地址 : ";
    cin.getline(cust[custCount()].address,1500);
    ofs << cust[custCount()].address;
    
    ofs.close();
    
    
    system("cls");
    
    int tempCust, hour;
    char carSelect[10];
    tempCust = custCount() - 1;
    
    cout<<"\n\n\n\n";
    art();
    cout << endl;
    
    cout<<"\n\t  |\t\t\t欢迎 ";
    cout << cust[tempCust].name;
    cout<<"\t  |\t身份证号 ";
    cout << cust[tempCust].id;
    cout << "\n\n";
    
    dispAvailCar();
    
    cout<<"\n\n\t  |\t请选车";
    cout<<"\n\t  |\t车牌号 : ";
    cin >> ws;
    cin.getline(carSelect,10);
    
    int x=countAvail();
    
    for(int i = 0; i < countAvail(); i++)
    {
        if (strcmp(carSelect,avail[i].plate_num) != 0)
        {
            availTemp << avail[i].plate_num;
            availTemp << " ";
            availTemp << avail[i].brand;
            availTemp << " ";
            availTemp << avail[i].model;
            availTemp << " ";
            availTemp << avail[i].capacity;
            availTemp << " ";
            availTemp << avail[i].colour;
            availTemp << " ";
            availTemp << avail[i].rate_per_hour;
            availTemp << " ";
            availTemp << avail[i].rate_per_half;
            availTemp << " ";
            availTemp << avail[i].rate_per_day;
            availTemp << " ";
            availTemp << avail[i].transmission;
            if(i != countAvail())
            {
                availTemp<<endl;
            }
            
            
        }
    }
    
    ofs.close();
    
    remove("available.txt");
    rename("availtemp.txt","available.txt");
    
    cout << "\t  |\t租金时数: ";
    cin >> hour;
    int j;
    for(int i = 0; i < carCount(); i++)
    {
        if (strcmp(carSelect,rent[i].plate_num) == 0)
        {
            j = i;
            rate(hour,j);
            log<<"\n车: "<<rent[i].plate_num;
            log<<"\n品牌: "<<rent[i].brand;
            log<<"\n模型: "<<rent[i].model;
            log <<"\n时间: "<< hour;
            log <<"\n付款: "<< rate(hour,j);
            
        }
    }
        
            
            
    cout << "\n\t  |\t以..为代价 " << hour << " 租金时间: rm ";
    cout << rate(hour,j);
    
    log <<"\n日期: "<<currentDateTime();
    log<<"\n==========================================================";
    log.close();
    availTemp.close();
    availCar();
    
    Sleep(5000);
    system("cls");
    menu();
}

void newCarData()
{
    cout<<"\n\n";
    art();
    cout << endl;
    
    ofstream ofs;
    ofs.open("car rental.txt" , fstream::app);
    ofs<<endl;
    
    int newCar = carCount() + 1;
    cout << "\n\n";
    cout << "\n\t  |\t\t\t\t\t  请输入一下数据: " << endl;
    
    cout << "\n\t  |\t\t\t\t\t 车牌号 : ";
    cin >> ws;
    cin.getline(rent[newCar].plate_num,10);
    ofs << rent[newCar].plate_num;
    ofs << " ";
    
    cout << "\t  |\t\t\t\t\t  品牌 : ";
    cin.getline(rent[newCar].brand,20);
    ofs << rent[newCar].brand;
    ofs << " ";
    
    cout << "\t  |\t\t\t\t\t  模型 : ";
    cin.getline(rent[newCar].model,20);
    ofs << rent[newCar].model;
    ofs << " ";
    
    cout << "\t  |\t\t\t\t\t  容量 : ";
    cin >> rent[newCar].capacity;
    ofs << rent[newCar].capacity;
    ofs << " ";
    
    cout << "\t  |\t\t\t\t\t  颜色 : ";
    cin >> ws;
    cin.getline(rent[newCar].colour,20);
    ofs << rent[newCar].colour;
    ofs << " ";
    
    cout << "\t  |\t\t\t\t\t  每小时租金 : ";
    cin >> rent[newCar].rate_per_hour;
    ofs << rent[newCar].rate_per_hour;
    ofs << " ";
    
    cout << "\t  |\t\t\t\t\t  每十二小时租金 : ";
    cin >> rent[newCar].rate_per_half;
    ofs << rent[newCar].rate_per_half;
    ofs << " ";
    
    cout << "\t  |\t\t\t\t\t  每二十四小时租金: ";
    cin >> rent[newCar].rate_per_day;
    ofs << rent[newCar].rate_per_day;
    ofs << " ";
    
    cout << "\t  |\t\t\t\t\t  转移(a/m): ";
    cin >> ws;
    cin.getline(rent[newCar].transmission,6);
    ofs << rent[newCar].transmission;
    
    ofs.close();
    system("cls");
    
    carData();
    admin();
}

void availCar ()
{
    ifstream ifs;
    ifs.open("available.txt");
    int carNum = 0;
    
    while(!ifs.eof())
    {
        ifs.getline(avail[carNum].plate_num,10,' ');
        ifs.getline(avail[carNum].brand,20,' ');
        ifs.getline(avail[carNum].model,20,' ');
        ifs >> avail[carNum].capacity;
        ifs.ignore();
        ifs.getline(avail[carNum].colour,20,' ');
        ifs >> avail[carNum].rate_per_hour;
        ifs.ignore();
        ifs >> avail[carNum].rate_per_half;
        ifs.ignore();
        ifs >> avail[carNum].rate_per_day;
        ifs.ignore();
        ifs.getline(avail[carNum].transmission,6);
        carNum++;
        ifs>>ws;
    }
    
    ifs.close();
}

void resetAvail()
{
    Boarder();
    ofstream ofs;
    ofs.open("temp2.txt");
    
    for(int i = 0; i < carCount(); i++)
    {
            ofs << rent[i].plate_num;
            ofs << " ";
            ofs << rent[i].brand;
            ofs << " ";
            ofs << rent[i].model;
            ofs << " ";
            ofs << rent[i].capacity;
            ofs << " ";
            ofs << rent[i].colour;
            ofs << " ";
            ofs << rent[i].rate_per_hour;
            ofs << " ";
            ofs << rent[i].rate_per_half;
            ofs << " ";
            ofs << rent[i].rate_per_day;
            ofs << " ";
            ofs << rent[i].transmission;
            if(i != carCount())
            {
                ofs<<endl;
            }
            
            
        }
    
    
    
    
    ofs.close();
    remove("available.txt");
    rename("temp2.txt","available.txt");
    
    admin();
    
}

void newUserPass()
{
    Boarder();
    ofstream ofs;
    ofs.open("UserPass.txt", fstream::app);
    
    userPass[countUser()].ID = countUser()+1;
    
    
    string password;
    char c;
    gotoxy(40,20);
    cout << "\n\n\n\n\t  |\t\t\tId (默认值): "<<userPass[countUser()].ID;
    cout << "\n\t  |\t\t\t添加密码: ";

    while(c != '\r') //循环直到按下回车键
         {
         c = getch();
         if(c == 0)
            {
            switch(getch())
               {
               default:
                  break;            
               };
            }
         else if(c == '\b')   //如果按下退格键
            {
            if(password.size() != 0)  //如果密码字符串包含数据,则擦除最后一个字符
               {
               cout << "\b \b";
               password.erase(password.size() - 1, 1);
               }
            continue;
            }
         else if(c <= '9' && c >= '0' || c >= 'a' && c <= 'z' || c >= 'A' && c <= 'Z')  //如果用户输入1-9、 a-z 或 a-z,将其添加到密码并显示星号
            {
            password += c;
            cout << "*";
            }
         else
            continue;
         }
    
    
    strcpy(userPass[countUser()].passWord,password.c_str());
    
    ofs<<userPass[countUser()].ID;
    ofs<<";";
    ofs<<userPass[countUser()].passWord;
    ofs<<endl;    
    
    system("cls");
    admin();

}

void showCarData()
{
    
    
    int x;
    cout<<"\n\n";
    art();
    cout << endl;
    
    cout << "\t  |  车牌号\t品牌\t 模型\t容量    颜色   每小时租金  每十二小时租金   每二十四小时租金   传输" << endl;
    cout << "\t  |  =======================================================================================================================" << endl;
    for (int i = 0; i < carCount(); i++)
    {
        cout << "\t  |  " << rent[i].plate_num << "\t\t" << rent[i].brand << "\t " << rent[i].model << "\t   " << rent[i].capacity << "\t     "
             << rent[i].colour << "\t  " <<rent[i].rate_per_hour << "\t\t    " << rent[i].rate_per_half << "\t\t    " << rent[i].rate_per_day 
             << "\t\t       " << rent[i].transmission << endl;
    }
    cout << "\n\n";
    cout<<"\n\t  |\t\t\t\t\t  1. 后面";
    cout<<"\n\t  |\t\t\t\t\t  2. 主菜单"<<endl<<"\n\n";
    cout<<"\t  |\t\t\t\t\tINPUT :";
    cin >> x;
    
    system("cls");
    
    if (x==1)
    {
        admin();
    }
    
    if (x==2)
    {
        menu();
    }
    
}

void carData ()
{
    ifstream ifs;
    ifs.open("car rental.txt");
    int carNum = 0;
    
    while(!ifs.eof())
    {
        ifs.getline(rent[carNum].plate_num,10,' ');
        ifs.getline(rent[carNum].brand,20,' ');
        ifs.getline(rent[carNum].model,20,' ');
        ifs >> rent[carNum].capacity;
        ifs.ignore();
        ifs.getline(rent[carNum].colour,20,' ');
        ifs >> rent[carNum].rate_per_hour;
        ifs.ignore();
        ifs >> rent[carNum].rate_per_half;
        ifs.ignore();
        ifs >> rent[carNum].rate_per_day;
        ifs.ignore();
        ifs.getline(rent[carNum].transmission,6);
        carNum++;
        ifs>>ws;
    }
    
    ifs.close();
}

void admin()
{
    int x;
    cout<<"\n\n\n\n";
    art();
    cout << endl;
    
    cout<<"\n\t  |\t\t\t\t\t\t\t  1. 添加管理员";
    cout<<"\n\t  |\t\t\t\t\t\t\t  2. 显示数据";
    cout<<"\n\t  |\t\t\t\t\t\t\t  3. 添加车辆";
    cout<<"\n\t  |\t\t\t\t\t\t\t  4. 删除车辆";
    cout<<"\n\t  |\t\t\t\t\t\t\t  5. 复位可用车辆";
    cout<<"\n\t  |\t\t\t\t\t\t\t  6. 退出"<<endl<<"\n";
    cout<<"\t  |\t\t\t\t\t\t\tINPUT :";
    cin>>x;
    
    
    system("cls");
    
    if (x==6)
    {
        load_EXIT();
        menu();
    }
    
    else if (x==2)
    {
        showCarData();
    }
    
    else if (x==3)
    {
        newCarData();
    }
    
    else if (x==4)
    {
        delCar();
    }
    else if (x==1)
    {
        newUserPass();
    }
    else if(x==5)
    system("cls");
        resetAvail();
}

void user()
{
    
    int x;
    
    art();
    cout << endl;
    

    cout<<"\n\t  |\t\t\t\t\t\t\t  1. 新建";
    cout<<"\n\t  |\t\t\t\t\t\t\t  2. 现有的";
    cout<<"\n\t  |\t\t\t\t\t\t\t  3. 主菜单"<<endl;
    cout<<"\n\n\t  |\t\t\t\t\t\t\t输入 :";
    cin>>x;

    system("cls");
    if (x==1)
    {
        newCustData();
    }
    
    else if (x==2)
    {
        system("cls");
        load_UPDATE();
        existingCust();
    }
    
    else if (x==3)
    {
        menu();
    }
    


    
}

void menu()
{
    
    int x;
    art();
    
    cout << endl;
    cout<<"\n\t  |\t\t\t\t\t\t\t  1. 管理员";
    cout<<"\n\t  |\t\t\t\t\t\t\t  2. 用户";
    cout<<"\n\t  |\t\t\t\t\t\t\t  3. T%C";
    cout<<"\n\t  |\t\t\t\t\t\t\t  4. 出口"<<endl<<"\n";
    cout<<"\n\t  |\t\t\t\t\t\t\tINPUT :";
    cin>>x;
    
    
    system("cls");
    
    if (x==2)
    {
        user();
    }
    
    else if (x==1)
    {
        password();
    }
    
    if(x==3)
    {
    
    tNc();
    getch();
    }
    
    if(x==5)
    time();
    
    else if (x==4)
    {
        cout << "\n\n\n\n";
        exitArt();
        Sleep(1000);
        exit(0);
    }
        
    else if (x==6)
    {
        fullscreen();
        menu();
    }    
        
        
        
        
        
}

void delCar()
{
    char plate[10];
    
    ofstream ofs;
    ofs.open("temp.txt");
    
    cout<<"\n\n\n\n";
    art();
    cout << endl;
    displayCar();
    
    cout << "\n\n";
    cout << "\t  | \t\t输入要删除的车牌号(大写字母 w/out 空格): "<<endl;
    cout<< "\t  |  \t\t\t\t\t\t\t";
    cin >> ws;
    cin.getline(plate,10);
    int x=carCount();
    for(int i = 0; i < carCount(); i++)
    {
        if (strcmp(plate,rent[i].plate_num) != 0)
        {
            ofs << rent[i].plate_num;
            ofs << " ";
            ofs << rent[i].brand;
            ofs << " ";
            ofs << rent[i].model;
            ofs << " ";
            ofs << rent[i].capacity;
            ofs << " ";
            ofs << rent[i].colour;
            ofs << " ";
            ofs << rent[i].rate_per_hour;
            ofs << " ";
            ofs << rent[i].rate_per_half;
            ofs << " ";
            ofs << rent[i].rate_per_day;
            ofs << " ";
            ofs << rent[i].transmission;
            if(i != carCount())
            {
                ofs<<endl;
            }
            
            
        }
    }
    
    ofs.close();
    
    remove("car rental.txt");
    rename("temp.txt","car rental.txt");
    
    
    system("cls");
    
    carData();
    admin();
}

void tNc()
{
    art();
    cout<<endl;
    cout<<"\n\t  |\t\t\t1. 最低租金时间是3小时";
    cout<<"\n\t  |\t\t\t2. 自己承担风险";
    cout<<"\n\t  |\t\t\t3. 万一发生意外,所有费用由司机支付";
    cout<<"\n\t  |\t\t\t4. 准备下列物品";
    cout<<"\n\t  |\t\t\t     \3份身份证明,执照";
    cout<<"\n\t  |\t\t\t     \3deposit (根据车辆类型)";
    cout<<"\n\t  |\t\t\t5. 如果迟到的话,额外的费用";
    cout<<"\n\t  |\t\t\t6. 安全驾驶!";
    cout<<"\n\n\n\n\t  |\t\t\t                           按任意键继续  :)";
    cout<<"\n\t  |\t\t\t                                                            ";
    
    getch();
    menu();
}

main()
{
    
    fullscreen();
    welcome();
    load();
    Boarder();
    readUserPass();
    availCar();
    customerData();
    carData();
    menu();

    
}
 

  • 1
    点赞
  • 5
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
一个简单的汽车租赁管理系统C++控制台程序): 利用C++实现对汽车和客户信息的增、删、改等操作,并保存。 部分代码: // CarRent.cpp : 定义控制台应用程序的入口点。 // #include "stdafx.h" #include "CarData.h" #include "Menu.h" #include"CustomerData.h" int main() { Menu::welcome(); Menu::login(); //登录界面 char choice; int carid, customerid; //汽车编号,客户编号 CustomerData CustomerDB; //客户库 Customer *r; //客户 CarData CarDB; //汽车库 Car *b; //汽车 Menu::showMenu(); //显示菜单 cout <> choice; while (choice != '0') { switch (choice) { case '1': //输入客户编号和要出租的汽车 cout <> customerid; try { if (customerid <= 0) throw 1; } catch (...) { cout << "输入有误,请重新输入"; break; } cout <> carid; try { if (carid <= 0) throw 1; } catch (...) { cout << "输入有误,请重新输入"; break; } r = CustomerDB.search(customerid); if (NULL == r) { cout << "不存在该客户!"; cout << endl; break; } b = CarDB.search(carid); if (b == NULL) { cout << "不存在该汽车!"; cout <borrowCar() == 0) { cout << "该汽车已租出!"; cout <borrowCar(b->getNo()); cout << "你在" <getBorTime()) << "成功出租一辆" <getName() << endl << "每日租金为(不足一天按一天计算):" <getPay(); break; case '2': //归还操作 cout <> customerid; try { if (customerid <= 0) throw 1; } catch (...) { cout << "输入有误,请重新输入"; break; } cout <> carid; try { if (carid <= 0) throw 1; } catch (...) { cout << "输入有误,请重新输入"; break; } r = CustomerDB.search(customerid); //按编号查找 if (r == NULL) { cout << "不存在该客户!" << endl; break; } b = CarDB.search(carid); if (b == NULL) { cout << "不存在该汽车!" <getOnshelf() == 1) { cout << "该汽车已经归还!" << endl; break; } cout << "您成功归还一辆"

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值