Self-complete
This commit is contained in:
+90
@@ -0,0 +1,90 @@
|
||||
#include "Car.h"
|
||||
#include "TaxRates.h"
|
||||
|
||||
Car::Car(double worth,
|
||||
double horsepower)
|
||||
: Property(worth)
|
||||
{
|
||||
this->horsepower = horsepower;
|
||||
}
|
||||
|
||||
double Car::calculateTax()
|
||||
{
|
||||
if (horsepower <
|
||||
TAX_RATES::LOW_HORSEPOWER)
|
||||
{
|
||||
return worth *
|
||||
TAX_RATES::CAR_TAX;
|
||||
}
|
||||
|
||||
if (horsepower <=
|
||||
TAX_RATES::HIGH_HORSEPOWER)
|
||||
{
|
||||
return worth *
|
||||
TAX_RATES::CAR_TRUCK_TAX;
|
||||
}
|
||||
|
||||
return worth *
|
||||
TAX_RATES::CAR_LUXURY_TAX;
|
||||
}
|
||||
|
||||
void Car::fromJson(json j)
|
||||
{
|
||||
worth = j["worth"];
|
||||
|
||||
horsepower =
|
||||
j["horsepower"];
|
||||
}
|
||||
|
||||
json Car::toJson()
|
||||
{
|
||||
json j;
|
||||
|
||||
j["worth"] = worth;
|
||||
|
||||
j["horsepower"] =
|
||||
horsepower;
|
||||
|
||||
j["tax"] =
|
||||
calculateTax();
|
||||
|
||||
return j;
|
||||
}
|
||||
|
||||
void Car::fromXml(
|
||||
XMLElement* element)
|
||||
{
|
||||
element->QueryDoubleAttribute(
|
||||
"worth",
|
||||
&worth
|
||||
);
|
||||
|
||||
element->QueryDoubleAttribute(
|
||||
"horsepower",
|
||||
&horsepower
|
||||
);
|
||||
}
|
||||
|
||||
XMLElement* Car::toXml(
|
||||
XMLDocument& doc)
|
||||
{
|
||||
XMLElement* element =
|
||||
doc.NewElement("Car");
|
||||
|
||||
element->SetAttribute(
|
||||
"worth",
|
||||
worth
|
||||
);
|
||||
|
||||
element->SetAttribute(
|
||||
"horsepower",
|
||||
horsepower
|
||||
);
|
||||
|
||||
element->SetAttribute(
|
||||
"tax",
|
||||
calculateTax()
|
||||
);
|
||||
|
||||
return element;
|
||||
}
|
||||
Reference in New Issue
Block a user