Website Summary Files Commits Branches @commit @diff @stats
path: root / Week10 / Exercise02 / Vehicle.cpp
blob: bbc6bf0777c9206764df7916def9d13a7da4c136 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
#include "Vehicle.h"
#include <cstring>

Vehicle::Vehicle() : model(), yearOfManufacture(), mileage(), ecoCategory(), weight(), horsePower() {
	type = 0;
}

const char* Vehicle::GetModel() const {
	return model;
}

void Vehicle::SetModel(char model[MODEL_LENGTH]) {
	strcpy(this->model, model);
}

unsigned Vehicle::GetYearOfManufacture() const {
	return yearOfManufacture;
}

void Vehicle::SetYearOfManufacture(unsigned yearOfManufacture) {
	this->yearOfManufacture = yearOfManufacture;
}

double Vehicle::GetMileage() const {
return mileage;
}

void Vehicle::SetMileage(double mileage) {
	this->mileage = mileage;
}

unsigned short Vehicle::GetEcoCategory() const {
	return ecoCategory;
}

void Vehicle::SetEcoCategory(unsigned short ecoCategory) {
	this->ecoCategory = ecoCategory;
}

double Vehicle::GetWeight() const {
	return weight;
}

void Vehicle::SetWeight(double weight) {
	this->weight = weight;
}

double Vehicle::GetHorsePower() const {
	return horsePower;
}

void Vehicle::SetHorsePower(double horsePower) {
	this->horsePower = horsePower;
}

std::ostream& operator<<(std::ostream& ostr, const Vehicle& vehicle) {
	ostr << vehicle.model << std::endl
		<< "Manufactured: " << vehicle.yearOfManufacture << std::endl
		<< "Mileage: " << vehicle.mileage << std::endl
		<< "Eco category: " << vehicle.ecoCategory << std::endl
		<< "Weight: " << vehicle.weight << std::endl
		<< "Horse power: " << vehicle.horsePower << std::endl;
	return ostr;
}

std::istream& operator>>(std::istream& istr, Vehicle& vehicle) {
	istr.getline(vehicle.model, MODEL_LENGTH);
	istr >> vehicle.yearOfManufacture
		>> vehicle.mileage
		>> vehicle.ecoCategory
		>> vehicle.weight
		>> vehicle.horsePower;
	return istr;
}