-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.cpp
52 lines (49 loc) · 1.54 KB
/
main.cpp
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
/*
Author: Maxim Teryokhin
*/
#include <iostream>
#include <fstream>
#include "Vehicle.h"
#include "Car.h"
#include "Bus.h"
using namespace std;
const int MAX_VEHICLES = 3;
int main()
{
ifstream fin("input.txt");
ofstream fout("output.txt");
Vehicle* arr[MAX_VEHICLES];
//arr[0] = new Car("LADA", 1000, 2012, 120, 1.5, "2107");
//arr[1] = new Bus("MAZ", 5000, 2014, 150, 47.5, "103");
//arr[0]->print();
//arr[1]->print();
char type;
string man;
double price;
int year;
double maxPassOrSpeed;
double engineVolume;
string model;
for (int i = 0; i < MAX_VEHICLES; i++){
fin >> type >> man >> price >> year >> maxPassOrSpeed >> engineVolume >> model;
if (type == 'c')
arr[i] = new Car(man, price, year, maxPassOrSpeed, engineVolume, model);
else if (type == 'b')
arr[i] = new Bus(man, price, year, (int)maxPassOrSpeed, engineVolume, model);
}
for (int i = 0; i < MAX_VEHICLES; i++){
arr[i]->print();
arr[i]->print(fout);
}
cout << "Enter year: ";
cin >> year;
for (int i = 0; i < MAX_VEHICLES; i++)
if (arr[i]->getYear() == year)
cout << "Vehicle #" << i+1 << ", calculated price: " << arr[i]->getPrice() << '\n';
for (int i = 0; i < MAX_VEHICLES; i++)
for (int j = i+1; j < MAX_VEHICLES; j++)
if (arr[i]->getManufacturer() == arr[j]->getManufacturer())
cout << "Vehicles #" << i+1 << " and #" << j+1 << " have same manufacturer\n";
fout.close();
return 0;
}