📄 tcarmarket.cpp
字号:
/*
Name: CHAI, Wennan
StudentID: 780621
Program: TCarMarket.cpp
Description:
*/
#include <iostream>
#include <string>
#include "TCarMarket.h"
using namespace std;
void TCarMarket::AddCar()
{
string s;
int price;
TDate date;
int usedtime;
TCarType type;
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);
do{
cout<<"Input the usedtime (how many months the car hs been used) : ";
cin>>usedtime;
if(usedtime<0) cout<<"Please input 0 or possitive num."<<endl;
}while (usedtime<0);
if(usedtime==0) {type=NEW; car[Total]=new NewCar(s,date,EXIST,Total,type);}
if((usedtime>0)&&(usedtime<13)) {type=EMPLOYEE; car[Total]=new EmployeesCar(s,date,EXIST,Total,type);}
if(usedtime>12) {type=SECONDHAND; car[Total]=new SecondHandCar(s,date,EXIST,Total,type);}
car[Total]->SetPrice(price);
car[Total]->SetUsedTime(usedtime);
Total++;
}
void TCarMarket::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;
switch(car[i]->GetType()){
case NEW : cout<<" NewCar "; break;
case EMPLOYEE : cout<<" EmployeesCar "<<car[i]->GetUsedTime()<<"MonthsUSED"; break;
case SECONDHAND : cout<<" SecondHandCar "<<car[i]->GetUsedTime()<<"MonthsUSED"; break;
}
if (car[i]->GetStatus()==EXIST) cout<<" EXIST";
else cout<<" SOLD";
cout<<endl;
}
}
void TCarMarket::SellCar()
{
int choice;
do
{
cout<<"Which car do you want to sell : ";
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);
}
TCarMarket::TCarMarket()
{Total=0;}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -