C++課程設計——停車場管理系統

停車場管理系統課程設計報告

 

1. 需求分析

2. 總體設計

3. 詳細設計

4. 編碼

5. 測試的步驟與內容

6. 總結

7. 參考文獻

 

 

1. 需求分析

1.1 需求概述

設計一個停車場管理系統,使之能提供以下功能:

用戶端:

⑴ 停車功能

⑵ 取車功能

管理員端:

⑴ 停車功能

⑵ 取車功能

⑶ 查詢功能

⑷ 查詢並修改功能

 ⑸ 顯示停車場車輛功能

1.2 需求說明

(1) 車輛信息包括車牌號、顏色、車型、停車時間。

(2) 車輛信息用文件形式保存,並可以對其進行查看、查詢、修改、刪除等基本操作。

(3) 車輛信息要顯示出車牌號、顏色、車型、停車的時間。

(4) 每個車輛信息是獨立的、修改其中一個不會對其他造成影響。

(5) 對車輛信息可以通過車牌號、顏色、車型、停車時間結合來查詢。

(6) 管理系統以菜單的形式展示給用戶,更加便於使用。

2.  總體設計

功能劃分

該系統按照功能模塊劃分,如圖所示。


其中:

⑴ 用戶通過用戶端自主存取車或者通過管理員端接受存取車和查詢等服務。

⑵ 查詢車輛信息實現實時查詢停車場所要查詢車輛的信息(需要管理員權限)。

⑶ 顯示車輛信息實現實時顯示停車場所有車輛信息(需要管理員權限)

⑶ 編輯車輛信息實現對特定車輛的信息修改(需要管理員權限)

⑷ 統計車輛實現實時對停車場車輛總數的統計(需要管理員權限)。

⑸ 加載文件實現在重啓管理端後加載所存車輛信息(需要管理員權限)。

1. 詳細設計

3.1類設計

管理系統中包含了3個類

⑴ 車類:包含了車牌號、顏色、車型、停車時間。

class Car

{

public:

    string licensePlate;

    string color;

    string model;

    int time;

};

 

⑵ 管理員類:包括車輛的實例化,存車、查詢、顯示、修改、取車、統計、保存、加載功能函數。

class Manage

{

public:

    Car a[100];

    void add();

    void inquire();

    void show();

    void modification();

    void del();

    void statistics();

    void save();

    void load();

};

⑶ 使用者類:包括用戶名和密碼,管理員的戶名和密碼,還有一個登陸驗證的功能函數。

class User

{

public:

    string ID;

    string password;

    string IDAdmin;

    string passwordAdmin;

    void longin();

};

3.2功能設計

存車:  void add();

查詢:  void inquire();

顯示:  void show();

查詢並修改:  void modification();

取車:  void del();

統計:  void statistics();

保存:  void save();

加載:  void load();

登陸驗證:void longin();

3.3菜單設計

4. 代碼

#include <iostream>

#include <string>
#include <cstdlib>
#include<fstream>
using namespace std;
int i;
class Car
{
public:
    string licensePlate;
    string color;
    string model;
    int time;
};
class Manage
{
public:
    Car a[100];
    void add();
    void inquire();
    void show();
    void modification();
    void del();
    void statistics();
    void save();
    void load();
};
void Manage::add()
{
    string licensePlate1;
    string color1;
    string model1;
    int time1;
    cout<<"歡迎停車\n"<<endl;
    if(i==100)
    {
        cout<<"對不起,停車場停車位已滿!"<<endl;
    }
    else
    {
        cout<<"請輸入車牌號:";
        cin>>licensePlate1;
        a[i].licensePlate = licensePlate1;
        cout<<"請輸入車輛顏色:";
        cin>>color1;
        a[i].color = color1;
        cout<<"請輸入車型:";
        cin>>model1;
        a[i].model = model1;
        cout<<"請輸入停車時間:";
        cin>>time1;
        a[i].time = time1;
        i++;
        cout<<"請將車停到停車場中空的車位!"<<endl;
    }
}
void Manage::inquire()
{
    int t;
    int k;
    string val;
    cout<<"請選擇查詢方式"<<endl;
    cout<<"1.通過車牌號查詢"<<endl;
    cout<<"2.通過車顏色查詢"<<endl;
    cout<<"3.通過車型查詢"<<endl;
    cout<<"4.通過停車時間查詢"<<endl;
    cin>>t;
    switch(t)
    {
    case 1:
        cout<<"請輸入車牌號碼:";
        cin>>val;
        for(int j = 0;j<i;j++)
        {
            if(val.compare(a[j].licensePlate)==0)
            {
                cout<<"您所查詢的車輛的車牌號爲:"<<a[j].licensePlate<<endl;
                cout<<"您所查詢的車輛的顏色爲:"<<a[j].color<<endl;
                cout<<"您所查詢的車輛的車型爲:"<<a[j].model<<endl;
                cout<<"您所查詢的車輛的停車時間爲:"<<a[j].time<<endl;
            }
        }
        system("pause");
        break;
    case 2:
        cout<<"請輸入車的顏色:";
        cin>>val;
        for(int j = 0;j<i-1;j++)
        {
            if(val.compare(a[j].color)==0)
            {
                cout<<"您所查詢的車輛的車牌號爲:"<<a[j].licensePlate<<endl;
                cout<<"您所查詢的車輛的顏色爲:"<<a[j].color<<endl;
                cout<<"您所查詢的車輛的車型爲:"<<a[j].model<<endl;
                cout<<"您所查詢的車輛的停車時間爲:"<<a[j].time<<endl;
            }
        }
        system("pause");
        break;
    case 3:
        cout<<"請輸入車的型號:";
        cin>>val;
        for(int j = 0;j<i-1;j++)
        {
            if(val.compare(a[j].model)==0)
            {
                cout<<"您所查詢的車輛的車牌號爲:"<<a[j].licensePlate<<endl;
                cout<<"您所查詢的車輛的顏色爲:"<<a[j].color<<endl;
                cout<<"您所查詢的車輛的車型爲:"<<a[j].model<<endl;
                cout<<"您所查詢的車輛的停車時間爲:"<<a[j].time<<endl;
            }
        }
        system("pause");
        break;
    case 4:
        cout<<"請輸入停車時間:";
        cin>>k;
        for(int j = 0;j<i-1;j++)
        {
            if(k==a[j].time)
            {
                cout<<"您所查詢的車輛的車牌號爲:"<<a[j].licensePlate<<endl;
                cout<<"您所查詢的車輛的顏色爲:"<<a[j].color<<endl;
                cout<<"您所查詢的車輛的車型爲:"<<a[j].model<<endl;
                cout<<"您所查詢的車輛的停車時間爲:"<<a[j].time<<endl<<endl;
            }
        }
        system("pause");
        break;
    }
}
void Manage::modification()
{
    string c;
    string licensePlate1;
    string color1;
    string model1;
    int time1;
    cout<<"請輸入您所查詢的車牌號碼:"<<endl;
    cin>>c;
    for(int j = 0;j<i;j++)
    {
        if(c.compare(a[j].licensePlate)==0)
        {
            cout<<a[j].licensePlate<<"\t"<<a[j].color<<"\t"<<a[j].model<<"\t"<<a[j].time<<endl;
            cout<<"請輸入修改後的車牌號:";
            cin>>licensePlate1;
            a[j].licensePlate = licensePlate1;
            cout<<"請輸入修改後的車輛顏色:";
            cin>>color1;
            a[j].color = color1;
            cout<<"請輸入修改後車型:";
            cin>>model1;
            a[j].model = model1;
            cout<<"請輸入修改後停車時間:";
            cin>>time1;
            a[j].time = time1;
        }
        break;
    }
}
void Manage::del()
{
    int j;
    string c;
    cout<<"歡迎出停車場!"<<endl;
    cout<<"請輸入您想出停車場車輛的車牌號碼:"<<endl;
    cin>>c;
    for(j=0;j<i;j++)
    {
        if(c.compare(a[j].licensePlate)==0)
        {
            cout<<"您的停車時間爲"<<a[j].time<<"小時"<<endl;
            cout<<"請繳納"<<a[j].time*5<<"元的停車費"<<endl;
            for(int k=j;k<=i;k++)
            {
                a[k]=a[k+1];
            }
            i--;
        }
        break;
    }
}
void Manage::statistics()
{
    cout<<"停車場停車總數爲"<<i<<"輛"<<endl;
}
void Manage::show()
{
    for(int j = 0;j<i;j++)
    {
        cout<<"車輛"<<j+1<<"車牌號爲:"<<a[j].licensePlate<<endl;
        cout<<"車輛"<<j+1<<"車顏色爲:"<<a[j].color<<endl;
        cout<<"車輛"<<j+1<<"車型爲:"<<a[j].model<<endl;
        cout<<"車輛"<<j+1<<"停車時間爲:"<<a[j].time<<endl<<endl;
    }
}
void Manage::save()
{
    ofstream inputFile;
    inputFile.open("file.txt");
    for(int j = 0;j<i;j++)
    {
        inputFile<<a[j].licensePlate<<endl<<a[j].color<<endl<<a[j].model<<endl<<a[j].time<<endl;
    }
    inputFile.close();
    ofstream zFile;
    zFile.open("number.txt");
    zFile<<i;
    zFile.close();
}
void Manage::load()
{
    int j = 0;
    ifstream xFile;
    xFile.open ("number.txt");
    xFile>>i;
    xFile.close();
    ifstream outFile;
    outFile.open("file.txt");
    while(!outFile.eof())
    {
        outFile>>a[j].licensePlate>>a[j].color>>a[j].model>>a[j].time;
        j++;
    }
    outFile.close();
}
class User
{
public:
    string ID;
    string password;
    string IDAdmin;
    string passwordAdmin;
    void longin();
};
void User::longin()
{
    User::ID = "abc";
    User::password = "abc";
    User::IDAdmin = "admin";
    User::passwordAdmin = "admin";
    int h=0;
string ID1;
string password1;
cout<<"\n\n\n\t\t\t     歡迎使用停車場管理系統!\n\n\n\n"<<endl;
cout<<"\t\t\t\t請登錄系統!\n"<<endl;
while (h!=3)
{


        cout<<"\t\t\t\t用戶名:";
        cin>>ID1;
        cout<<"\t\t\t\t密碼:";
        cin>>password1;
        if (ID1.compare(User::ID)==0&&password1.compare(User::password)==0)
        {
            cout<<"\t\t\t\t登陸成功!"<<endl;
            system("pause");
            system("cls");
                int a;
                Manage carManage;
                User userName;
                cout<<"\n\n\t\t\t   歡迎進入用戶停車系統!\n\n"<<endl;
                while (1)
                {
                cout<<"\t\t\t     菜單\n\n"<<endl;
                cout<<" \t\t\t    1.停車\n\t\t\t    2.出停車場\n\t\t\t    3.退出\n"<<endl;
                cin>>a;
                switch (a)
                {
                    case 1:
                        {
                            system ("cls");
                            carManage.add();
                            carManage.save();
                            system ("cls");
                            break;
                        }
                    case 2:
                        {
                            system ("cls");
                            carManage.del();
                            carManage.save();
                            system("cls");
                            break;
                        }
                    case 3:
                        {
                            exit(0);
                        }
                    default :
                        {
                            cout<<"請重新輸入"<<endl;
                            system("pause");
                            break;
                        }
                }
                }
        }
        if (ID1.compare(User::IDAdmin)==0&&password1.compare(User::passwordAdmin)==0)
        {
            cout<<"\t\t\t\t登陸成功!"<<endl;
            system("pause");
            system("cls");
                int a;
                Manage carManage;
                User userName;
                cout<<"\n\n\t\t\t   歡迎進入管理員停車場管理系統!\n\n"<<endl;
                while (1)
                {
                cout<<"\t\t\t     菜單\n\n"<<endl;
                cout<<" \t\t\t    1.停車\n\t\t\t    2.查詢車輛信息\n\t\t\t    3.顯示所有車輛信息\n\t\t\t    4.編輯車輛信息\n\t\t\t    5.出停車場\n\t\t\t    6.統計車輛\n\t\t\t    7.加載文件\n\t\t\t    8.退出\n"<<endl;
                cin>>a;
                switch (a)
                {
                    case 1:
                        {
                            system ("cls");
                            carManage.add();
                            carManage.save();
                            system ("cls");
                            break;
                        }
                    case 2:
                        {
                            system ("cls");
                            carManage.inquire();
                            system ("cls");
                            break;
                        }
                    case 3:
                        {
                            system ("cls");
                            carManage.show();
                            system("pause");
                            system ("cls");
                            break;
                        }
                    case 4:
                        {
                            system ("cls");
                            carManage.modification();
                            carManage.save();
                            system ("cls");
                            break;
                        }
                    case 5:
                        {
                            system ("cls");
                            carManage.del();
                            carManage.save();
                            system("cls");
                            break;
                        }
                    case 6:
                        {
                            system ("cls");
                            carManage.statistics();
                            system("pause");
                            system ("cls");
                            break;
                        }
                    case 7:
                        {
                            carManage.load();
                            system ("cls");
                            break;
                        }
                    case 8:
                        {
                            exit(0);
                        }
                    default :
                        {
                            cout<<"請重新輸入"<<endl;
                            system("pause");
                            break;
                        }
                    }
                    }
        }
        else
        {
            h++;
            system ("cls");
            cout<<"\t\t\t   密碼或用戶名輸入錯誤!"<<endl;
            cout<<"\t\t\t請重新輸入,您還有"<<3-h<<"次輸入機會"<<endl;
        }
        if (h==3)
        {
            cout<<"\t\t\t\t您已三次輸入錯誤,系統被強制停止"<<endl;
            exit (0);
        }
}
}
int main()
{
    User userName;
    userName.longin();
    return 0;

}

5. 總結

停車場管理系統是生活中常用的一個程序,實現用戶端和管理員端可以對信息進行保護,用戶可以自主通過用戶端實現存取車這兩個基本功能,也可以在需要的情況下通過管理員的協助來實現信息的查詢修改,也可以通過管理員來了解停車場的現狀,本管理系統實現了對信息的保護,和功能的實現。


發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章