Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #pragma once
- #include <iostream>
- #include <string>
- #include <map>
- #include <tuple>
- #include <algorithm>
- using namespace std;
- #ifndef _AUTOMOBILE_HPP_
- #define _AUTOMOBILE_HPP_
- class Automobile {
- protected:
- size_t power;
- string model;
- string number;
- string owner;
- public:
- Automobile() : power(0), model(""), number(""), owner("") {};
- Automobile(size_t power, string model, string number, string owner) :
- power(power),
- model(model),
- number(number),
- owner(owner) {};
- Automobile(const Automobile &obj) : power(obj.power), model(obj.model), number(obj.number), owner(obj.owner) {};
- virtual ~Automobile();
- inline auto getNumber() -> string {
- return this->number;
- }
- auto operator==(const Automobile &obj) -> bool {
- return (this->owner == obj.owner);
- }
- auto operator<(const Automobile &obj) -> bool {
- return (this->number < obj.number);
- }
- friend auto operator<<(ostream &output, const Automobile &obj) -> ostream & {
- output << "Owner: " << obj.owner << endl;
- output << "Model: " << obj.model << endl;
- output << "Number: " << obj.number << endl;
- output << "Power: " << obj.power << endl;
- output << "City: " << obj.code_to_city[obj.getCode(obj.number)] << endl;
- return output;
- }
- friend auto operator>>(istream &input, Automobile &obj) -> istream & {
- input >> obj.owner;
- input >> obj.model;
- input >> obj.number;
- input >> obj.power;
- obj.city_code = obj.number.substr(0, 2);
- obj.city_code.erase(remove_if(city_code.begin(), city_code.end(), isspace), city_code.end());
- return input;
- }
- /*!
- * Statics
- */
- static auto initStatics() -> void {
- code_to_city["V"] = "Varna";
- code_to_city["S"] = "Sofia";
- code_to_city["PV"] = "Plovdiv";
- city_to_code.insert(pair<string, string>("Varna", "V"));
- city_to_code.insert(pair<string, string>("Sofia", "S"));
- city_to_code.insert(pair<string, string>("Plovdiv", "PV"));
- }
- static string city_code;
- static map<string, string> code_to_city;
- static multimap<string, string> city_to_code;
- static auto getCode(string number) -> string;
- };
- #endif
- ------------------
- #include "Automobile.hpp"
- Automobile::~Automobile() {}
- /*!
- * Statics
- */
- string Automobile::city_code;
- map<string, string> Automobile::code_to_city;
- multimap<string, string> Automobile::city_to_code;
- auto Automobile::getCode(string number) -> string {
- city_code = number.substr(0, 2);
- city_code.erase(remove_if(city_code.begin(), city_code.end(), isspace), city_code.end());
- return city_code;
- }
- --------------------------
- #include "Automobile.hpp"
- int main() {
- Automobile test;
- cout << test.getCode("V 5400");
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement