⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 main.cpp~

📁 这是一个简单的 用于标准汽车店的统计管理程序 有多个子程序构成
💻 CPP~
字号:
/*
Name: CHAI, Wennan
StudentID: 780621
Program: car_dealer.cpp
Description:
*/

#include <iostream>
#include <string>
#include "TCar.h"
using namespace std;

int Total=0;
TCar *car[100];


void AddCar()
{
    string s;
    int price;
    TDate date;

   
        cout<<"Input the name of the car : ";
        cin>>s;
        do
        {
            cout<<"Input the price of the car : ";
            cin>>price;
            if (price<0 || price>32766) cout<<"Please input a valid number"<<endl;
        }while (price<0 || price>32766);
        do
        {
            cout<<"Input the manufacture year : ";
            cin>>date.year;
            if (date.year<1900 || date.year>2005) cout<< "Please input number from 1900 to 2005"<<endl;
        }while (date.year<1900 || date.year>2005);
        do
        {
            cout<<"Input the manufacture month : ";
            cin>>date.month;
            if  (date.month<1 || date.month>12) cout <<"Please input number from 1 to 12"<<endl;
        }while (date.month<1 || date.month>12);
        do
        {
            cout<<"Input the manufacture day : ";
            cin>>date.day;
            if (date.day<1 || date.day>31) cout << "Please input a number from 1 to 31"<<endl;
        }while (date.day<1 || date.day>31);
    
    car[Total]=new TCar(s,date,EXIST,Total,type);
    pcar->SetPrice(price);


    Total++;

}

void ListCar()
{
    int i;
    for(i=0;i<Total;i++)
    {
        cout<<"No."<<car[i].GetID()<<"--> "<<
        car[i].GetBrand()<<" "<<car[i].GetPrice()<<"$ "<<car[i].GetDate().year
        << "/"<<car[i].GetDate().month<<"/"<<car[i].GetDate().day;
        if (car[i].GetStatus()==EXIST) cout<<" EXIST";
        else cout<<" SOLD";
        cout<<endl;

    }
}

void DeleteCar()
{


    int choice;
    ListCar();
   
        do
        {
            cout<<"Which car do you want to delete : ";
            cin>>   choice;
            if (choice<0 || choice>Total) cout<<"Please input from 0 to "<<Total-1<<endl;
        }while (choice<0 || choice>Total);
        if (car[choice].GetStatus()==SOLD)
           cout<<"This car has been sold"<<endl;
        else
           car[choice].SetStatus(SOLD);   
}


int InputChoice()
{
    int choice;
   
        do
        {
            cout<<"Please select one from the value (1-4) : ";
            cin>>choice;
        }while( (choice<1) && (choice>4));
    
    return choice;
}
    
void ShowMenu()
{
    cout<<"=========================="<<endl;
    cout<<"          MENU            "<<endl;
    cout<<"1  --  Add a car          "<<endl;
    cout<<"2  --  Sell a car         "<<endl;
    cout<<"3  --  List all cars      "<<endl;
    cout<<"4  --  Exit               "<<endl;
    cout<<"                          "<<endl;
    cout<<"=========================="<<endl;
}





int main()
{
    int  c;

    do
    {
        ShowMenu();
        c = InputChoice();
        switch ( c )
        {
            case 1:
                AddCar();
                break;
            case 2:
                DeleteCar();
                break;
            case 3:
                ListCar();
                break;
        }
    }while  (c!=4);
    
    
    
    return 1;
}


⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -