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 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189
|
#include <iostream>
#include <fstream>
#include <vector>
#include <string>
class Worker {
protected:
std::string fullname;
unsigned age {};
float experience {};
public:
void set_fullname(const std::string& name) { fullname = name; }
std::string get_fullname() const { return fullname; }
void set_age(unsigned years) { age = years;}
unsigned get_age() const { return age; }
void set_experience(float expr) { experience = expr; }
float get_experience() const { return experience; }
virtual void showworkerinfo() const = 0;
virtual ~Worker() {}
};
class Driver : public Worker {
private:
std::string licencenumber, category;
public:
void set_licencenumber(const std::string& licence) { licencenumber = licence; }
std::string get_licencenumber() const { return licencenumber; }
void set_category(const std::string& cat) { category = cat; }
std::string get_category() const { return category; }
void showworkerinfo() const override {
std::cout << "|" << '\t' << fullname << '\t' << "|" << '\t' << age << '\t' << "|" << '\t' << experience << '\t' << "|" << '\t' << licencenumber << '\t' << "|" << '\t' << category << '\t' << "|\n";
}
};
class Vehicle {
protected:
std::string brand;
std::string color;
std::string number;
unsigned year_of_production {};
float petrol {};
std::vector<Driver*> driver_;
public:
void set_brand(const std::string& brandname) { brand = brandname; }
std::string get_brand() const { return brand; }
void set_color(const std::string& colour_) { color = colour_; }
std::string get_color() const { return color; }
void set_number(std::string nmb) { number = nmb; }
std::string get_number() const { return number; }
void set_year_of_production(unsigned year) { year_of_production = year; }
unsigned int get_year_of_production() const { return year_of_production; }
void set_petrol(float ptrl) { petrol = ptrl; }
float get_petrol() const { return petrol; }
template<typename T, typename... Args>
void set_driver(T driver, Args... args) {
driver_.push_back(driver);
set_driver(args...);
}
void set_driver() {}
void show_driver() const {
for (const auto& d : driver_)
std::cout << d->get_fullname() << "|" << d->get_licencenumber() << '\n';
}
virtual void showinfo() const = 0;
virtual ~Vehicle() {}
};
class PublicTransport : public Vehicle {
protected:
unsigned passengerseats {};
public:
void set_passengersseats(unsigned seats) { passengerseats = seats; }
unsigned int get_passengerseats() const { return passengerseats; }
};
class Bus : public PublicTransport {
private:
std::string route;
public:
void set_route(const std::string& rout) { route = rout; }
std::string get_route() const { return route; }
void showinfo() const override {
std::cout << "|" << '\t' << number << '\t' << "|" << '\t' << color << '\t' << "|" << '\t' << brand << '\t' << "|" << '\t' << year_of_production << '\t' << "|" << '\t' << petrol << '\t' << "|" << '\t' << passengerseats << '\t' << "|" << '\t' << route << '\t' << "|\n";
}
};
void cin_string(std::string& str, std::ifstream& file, int size = 256, char delim = '|') {
str.clear();
std::getline(file, str, delim);
}
void cin_float(float& f, std::ifstream& file, char delim = '|', int size = 256) {
std::string cstr;
std::getline(file, cstr, delim);
f = stof(cstr);
}
void cin_int(int& f, std::ifstream& file, char delim = '|', int size = 256) {
std::string cstr;
std::getline(file, cstr, delim);
f = stoi(cstr);
}
int main()
{
std::vector<Bus> buses;
std::vector<Driver> drivers;
std::ifstream fbus("buses.txt");
if (!fbus)
return (std::cout << "\nCouldn't find buses.txt.\n"), 1;
while (fbus) {
std::string carnumber, carcolor, carbrand, carroute;
int caryear {}, carseat {};
float carpetrol {};
cin_string(carnumber, fbus);
cin_string(carcolor, fbus);
cin_string(carbrand, fbus);
cin_int(caryear, fbus);
cin_float(carpetrol, fbus);
cin_int(carseat, fbus);
cin_string(carroute, fbus);
if (fbus) {
Bus bus;
bus.set_number(carnumber);
bus.set_color(carcolor);
bus.set_brand(carbrand);
bus.set_year_of_production(caryear);
bus.set_petrol(carpetrol);
bus.set_passengersseats(carseat);
bus.set_route(carroute);
buses.emplace_back(bus);
}
}
fbus.close();
std::ifstream fdriver("drivers.txt");
if (!fdriver)
return (std::cout << '\n' << "\nCouldn't find drivers.txt.\n"), 2;
while (fdriver) {
std::string personname, personlicence, personcategory;
int personage {};
float personexp {};
cin_string(personname, fdriver);
cin_int(personage, fdriver);
cin_float(personexp, fdriver);
cin_string(personlicence, fdriver);
cin_string(personcategory, fdriver);
if (fdriver) {
Driver driver;
driver.set_fullname(personname);
driver.set_age(personage);
driver.set_experience(personexp);
driver.set_licencenumber(personlicence);
driver.set_category(personcategory);
drivers.emplace_back(driver);
}
}
fdriver.close();
buses[0].set_driver(&drivers[0], &drivers[1]);
}
|