Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // ConsoleApplication18.cpp: определяет точку входа для консольного приложения.
- //
- #include "stdafx.h"
- #include <string>
- #include <vector>
- #include <ctime>
- #include <iostream>
- using namespace std;
- string RandomName()
- {
- switch (rand() % 15)
- {
- case 0: {
- return "John";
- }
- case 1: {return "Josh";
- case 2: {return "Bob";
- }
- case 3: {return "Tony";
- }
- case 4: {return "David";
- }
- case 5: {return "Shawn";
- }
- case 6: {return "Paul";
- }
- case 7: {return "Toby";
- }
- case 8: { return"Bill";
- }
- case 9: { return"Nail";
- }
- case 10: {return "Bill";
- }
- case 11: {return "Spenser";
- }
- case 12: {return "Homer";
- }
- case 13: { return"Gabriel";
- }
- case 14: {return "Dennis";
- }
- }
- }
- }
- string RandomSurname()
- {
- switch (rand() % 15)
- {
- case 0: {
- return "Smith";
- }
- case 1: {return "White";
- }
- case 2: {return "Brown";
- }
- case 3: {return "Muller";
- }
- case 4: {return "Garcia"; }
- case 5: {return "Nowak";
- }
- case 6: {return "Anderson";
- }
- case 7: {return "Martin";
- }
- case 8: {return "Rossi";
- }
- case 9: {return "Silva";
- }
- case 10: {return "Gruber";
- }
- case 11: {return "Russu";
- }
- case 12: {return "Hodja";
- }
- case 13: {return "Murphy";
- }
- case 14: {return "Borg";
- }
- }
- }
- class CrewMember
- {
- protected:
- string m_name;
- string m_surname;
- int m_expiriance;
- public:
- string GetName() { return m_name; }
- string GetSurname() { return m_surname; }
- int GetExp() { return m_expiriance; }
- void PrintInfo()
- {
- cout << "This crew member name is " << m_name << " " << m_surname << endl
- << "This crew member expiriance at this role is " << m_expiriance << endl;
- }
- virtual ~CrewMember() {}
- };
- class Capitan :public CrewMember
- {
- private:
- void CheckExp()
- {
- if (m_expiriance == 300)
- {
- cout << "Congratsulations! Your Capitan reached max expiriance and now he is leaving you." << endl;
- Capitan::GenerateNewCapitan();
- }
- }
- public:
- //build random Capitan
- Capitan()
- {
- //set name
- m_name = RandomName();
- //set surname
- m_surname = RandomSurname();
- //set exp
- m_expiriance = rand() % 150 + 150;
- }
- Capitan(string name, string surname, int expiriance)
- {
- m_name = name;
- m_surname = surname;
- m_expiriance = expiriance;
- }
- void Sail()
- {
- m_expiriance += 1;
- Capitan::CheckExp();
- }
- static Capitan GenerateNewCapitan()
- {
- Capitan NewCapitan;
- string answer;
- cout << "Do you want to choose new random Capitan or create one by yourself?"
- << endl << "Input \"create\" to create new Capitan. Else it would be randomed." << endl;
- cin >> answer;
- if (answer == "create")
- {
- cout << "Input new capitans name" << endl;
- string name;
- cin >> name;
- cout << "Input new capitans surname" << endl;
- string surname;
- cin >> surname;
- cout << "Input new capitans expiriance" << endl;
- int expiriance;
- cin >> expiriance;
- try
- {
- Capitan capitan(name, surname, expiriance);
- if (capitan.GetName().find_first_of
- ("~`1234567890-=!@#$%^&*()_+!! \" №;%:?*{}[]'|\\,./+=-*<>") != string::npos)
- throw invalid_argument("Invalid symbol at the name!");
- if (capitan.GetSurname().find_first_of
- ("~`1234567890-=!@#$%^&*()_+!! \" №;%:?*{}[]'|\\,./+=-*<>") != string::npos)
- throw invalid_argument("Invalid symbol at the surname!");
- if (capitan.GetExp()<75)
- throw invalid_argument("Invalid value of Capitan expiriance!");
- }
- catch (const invalid_argument& e)
- {
- cout << "Error:" << e.what() << endl;
- }
- NewCapitan = Capitan::Capitan(name, surname, expiriance);
- }
- else
- NewCapitan = Capitan::Capitan();
- cout << "This is your new Capitan!" << endl;
- NewCapitan.PrintInfo();
- return NewCapitan;
- }
- };
- class Mate :public CrewMember
- {
- private:
- void CheckExp()
- {
- if (m_expiriance == 75)
- {
- cout << "Congratsulations! Your Mate became Capitan and now you need someone to become new Mate!" << endl;
- Mate::GenerateNewMate();
- }
- }
- public:
- Mate GenerateNewMate()
- {
- Mate NewMate;
- string answer;
- cout << "Do you want to choose random Mate or create one by yourself?"
- << endl << "Input \"create\" to create new mate. Else he would be randomed." << endl;
- cin >> answer;
- if (answer == "create")
- {
- cout << "Input new Mates name" << endl;
- string name;
- cin >> name;
- cout << "Input new Mates surname" << endl;
- string surname;
- cin >> surname;
- cout << "Input new Mates expiriance" << endl;
- int expiriance;
- cin >> expiriance;
- try
- {
- Mate mate(name, surname, expiriance);
- if (mate.GetName().find_first_of
- ("~`1234567890-=!@#$%^&*()_+!! \" №;%:?*{}[]'|\\,./+=-*<>") != string::npos)
- throw invalid_argument("Invalid symbol at the name!");
- if (mate.GetSurname().find_first_of
- ("~`1234567890-=!@#$%^&*()_+!! \" №;%:?*{}[]'|\\,./+=-*<>") != string::npos)
- throw invalid_argument("Invalid symbol at the surname!");
- if (mate.GetExp()<75 || mate.GetExp()>150)
- throw invalid_argument("Invalid value of Mates expiriance!");
- }
- catch (invalid_argument e)
- {
- cout << "Error:" << e.what() << endl;
- }
- NewMate = Mate::Mate(name, surname, expiriance);
- }
- else
- NewMate = Mate::Mate();
- cout << "This is your new Mate!" << endl;
- NewMate.PrintInfo();
- return NewMate;
- }
- void Sail()
- {
- m_expiriance += 1;
- Mate::CheckExp();
- }
- Mate()
- {
- //set name
- m_name = RandomName();
- //set surname
- m_surname = RandomSurname();
- //set exp
- m_expiriance = rand() % 100 + 50;
- }
- Mate(string name, string surname, int expiriance)
- {
- m_name = name;
- m_surname = surname;
- m_expiriance = expiriance;
- }
- };
- class OlderEngineer :public CrewMember {
- private:
- void CheckExp()
- {
- if (m_expiriance == 50)
- {
- cout << "Congratsulations! Your Older Engeneer reached max expiriance and now he is leaving you." << endl;
- OlderEngineer::GenerateNewOlderEngineer();
- }
- }
- public:
- OlderEngineer GenerateNewOlderEngineer()
- {
- OlderEngineer NewOlderEngineer;
- string answer;
- cout << "Do you want to choose new random Older Engineer or create one by yourself?"
- << endl << "Input \"create\" to create new Older Engineer. Else it would be randomed." << endl;
- cin >> answer;
- if (answer == "create")
- {
- cout << "Input new Older Engineer name" << endl;
- string name;
- cin >> name;
- cout << "Input new Older Engineer surname" << endl;
- string surname;
- cin >> surname;
- cout << "Input new Older Engineer expiriance" << endl;
- int expiriance;
- cin >> expiriance;
- try
- {
- OlderEngineer NewOlderEngineer(name, surname, expiriance);
- if (NewOlderEngineer.GetName().find_first_of
- ("~`1234567890-=!@#$%^&*()_+!! \" №;%:?*{}[]'|\\,./+=-*<>") != string::npos)
- throw invalid_argument("Invalid symbol at the name!");
- if (NewOlderEngineer.GetSurname().find_first_of
- ("~`1234567890-=!@#$%^&*()_+!! \" №;%:?*{}[]'|\\,./+=-*<>") != string::npos)
- throw invalid_argument("Invalid symbol at the surname!");
- if (NewOlderEngineer.GetExp()<150)
- throw invalid_argument("Invalid value of Older Engineer expiriance!");
- }
- catch (invalid_argument e)
- {
- cout << "Error:" << e.what() << endl;
- }
- NewOlderEngineer = OlderEngineer::OlderEngineer(name, surname, expiriance);
- }
- else
- NewOlderEngineer = OlderEngineer::OlderEngineer();
- cout << "This is your new Older Engineer!" << endl;
- NewOlderEngineer.PrintInfo();
- return NewOlderEngineer;
- }
- OlderEngineer()
- {
- //set name
- m_name = RandomName();
- //set surname
- m_surname = RandomSurname();
- //set exp
- m_expiriance = rand() % 15 + 35;
- }
- OlderEngineer(string name, string surname, int expiriance)
- {
- m_name = name;
- m_surname = surname;
- m_expiriance = expiriance;
- }
- void FixSmth()
- {
- m_expiriance += 1;
- OlderEngineer::CheckExp();
- }
- };
- class OlderOfficer :public CrewMember {
- private:
- void CheckExp()
- {
- if (m_expiriance == 50)
- {
- cout << "Congratsulations! Your Older Engeneer reached max expiriance and now he is leaving you." << endl;
- OlderOfficer::GenerateNewOlderOfficer();
- }
- }
- public
- :OlderOfficer GenerateNewOlderOfficer()
- {
- OlderOfficer NewOlderOfficer;
- string answer;
- cout << "Do you want to choose new random Older Officer or create one by yourself?"
- << endl << "Input \"create\" to create new Older Officer. Else it would be randomed." << endl;
- cin >> answer;
- if (answer == "create")
- {
- cout << "Input new Older Officer name" << endl;
- string name;
- cin >> name;
- cout << "Input new Older Officer surname" << endl;
- string surname;
- cin >> surname;
- cout << "Input new Older Officer expiriance" << endl;
- int expiriance;
- cin >> expiriance;
- try
- {
- OlderEngineer NewOlderOfficer(name, surname, expiriance);
- if (NewOlderOfficer.GetName().find_first_of
- ("~`1234567890-=!@#$%^&*()_+!! \" №;%:?*{}[]'|\\,./+=-*<>") != string::npos)
- throw invalid_argument("Invalid symbol at the name!");
- if (NewOlderOfficer.GetSurname().find_first_of
- ("~`1234567890-=!@#$%^&*()_+!! \" №;%:?*{}[]'|\\,./+=-*<>") != string::npos)
- throw invalid_argument("Invalid symbol at the surname!");
- if (NewOlderOfficer.GetExp()<15 || NewOlderOfficer.GetExp()>50)
- throw invalid_argument("Invalid value of Older Officer expiriance!");
- }
- catch (invalid_argument e)
- {
- cout << "Error:" << e.what() << endl;
- }
- NewOlderOfficer = OlderOfficer::OlderOfficer(name, surname, expiriance);
- }
- else
- NewOlderOfficer = OlderOfficer::OlderOfficer();
- cout << "This is your new Older Engineer!" << endl;
- NewOlderOfficer.PrintInfo();
- return NewOlderOfficer;
- }
- OlderOfficer()
- {
- //set name
- m_name = RandomName();
- //set surname
- m_surname = RandomSurname();
- //set exp
- m_expiriance = rand() % 150 + 150;
- }
- OlderOfficer(string name, string surname, int expiriance)
- {
- m_name = name;
- m_surname = surname;
- m_expiriance = expiriance;
- }
- void EmergState()
- {
- m_expiriance += 1;
- OlderOfficer::CheckExp();
- }
- };
- class OlderSailor :public CrewMember {
- private:
- void CheckExp()
- {
- if (m_expiriance == 50)
- {
- cout << "Congratsulations! Your Older Sailor reached max expiriance and now he is leaving you." << endl;
- OlderSailor::GenerateNewOlderSailor();
- }
- }
- public:
- OlderSailor GenerateNewOlderSailor()
- {
- OlderSailor NewOlderSailor;
- string answer;
- cout << "Do you want to choose new random Older Sailor or create one by yourself?"
- << endl << "Input \"create\" to create new Older Sailor. Else it would be randomed." << endl;
- cin >> answer;
- if (answer == "create")
- {
- cout << "Input new Older Sailor name" << endl;
- string name;
- cin >> name;
- cout << "Input new Older Sailor surname" << endl;
- string surname;
- cin >> surname;
- cout << "Input new Older Sailor expiriance" << endl;
- int expiriance;
- cin >> expiriance;
- try
- {
- OlderEngineer NewOlderOfficer(name, surname, expiriance);
- if (NewOlderOfficer.GetName().find_first_of
- ("~`1234567890-=!@#$%^&*()_+!! \" №;%:?*{}[]'|\\,./+=-*<>") != string::npos)
- throw invalid_argument("Invalid symbol at the name!");
- if (NewOlderOfficer.GetSurname().find_first_of
- ("~`1234567890-=!@#$%^&*()_+!! \" №;%:?*{}[]'|\\,./+=-*<>") != string::npos)
- throw invalid_argument("Invalid symbol at the surname!");
- if (NewOlderOfficer.GetExp()<150)
- throw invalid_argument("Invalid value of Capitan expiriance!");
- }
- catch (invalid_argument e)
- {
- cout << "Error:" << e.what() << endl;
- }
- NewOlderSailor = OlderSailor::OlderSailor(name, surname, expiriance);
- }
- else
- NewOlderSailor = OlderSailor::OlderSailor();
- cout << "This is your new Older Engineer!" << endl;
- NewOlderSailor.PrintInfo();
- return NewOlderSailor;
- }
- OlderSailor()
- {
- //set name
- m_name = RandomName();
- //set surname
- m_surname = RandomSurname();
- //set exp
- m_expiriance = rand() % 25 + 25;
- }
- OlderSailor(string name, string surname, int expiriance)
- {
- m_name = name;
- m_surname = surname;
- m_expiriance = expiriance;
- }
- void Sail()
- {
- m_expiriance += 1;
- OlderSailor::CheckExp();
- }
- };
- class Engineer :public CrewMember
- {
- private:
- void CheckExp()
- {
- if (m_expiriance == 50)
- {
- cout << "Congratsulations! Your Engeneer reached max expiriance and now he is leaving you." << endl;
- Engineer::GenerateNewEngineer();
- }
- }
- public:
- Engineer GenerateNewEngineer()
- {
- Engineer NewEngineer;
- string answer;
- cout << "Do you want to choose new Engineer or create one by yourself?"
- << endl << "Input \"create\" to create new Engineer. Else it would be randomed." << endl;
- cin >> answer;
- if (answer == "create")
- {
- cout << "Input new Engineer name" << endl;
- string name;
- cin >> name;
- cout << "Input new Engineer surname" << endl;
- string surname;
- cin >> surname;
- cout << "Input new Engineer expiriance" << endl;
- int expiriance;
- cin >> expiriance;
- try
- {
- OlderEngineer NewEngineer(name, surname, expiriance);
- if (NewEngineer.GetName().find_first_of
- ("~`1234567890-=!@#$%^&*()_+!! \" №;%:?*{}[]'|\\,./+=-*<>") != string::npos)
- throw invalid_argument("Invalid symbol at the name!");
- if (NewEngineer.GetSurname().find_first_of
- ("~`1234567890-=!@#$%^&*()_+!! \" №;%:?*{}[]'|\\,./+=-*<>") != string::npos)
- throw invalid_argument("Invalid symbol at the surname!");
- if (NewEngineer.GetExp()<0 || NewEngineer.GetExp()>15)
- throw invalid_argument("Invalid value of Engineer expiriance!");
- }
- catch (invalid_argument e)
- {
- cout << "Error:" << e.what() << endl;
- }
- NewEngineer = Engineer::Engineer(name, surname, expiriance);
- }
- else
- NewEngineer = Engineer::Engineer();
- cout << "This is your new Engineer!" << endl;
- NewEngineer.PrintInfo();
- return NewEngineer;
- }
- Engineer()
- {
- //set name
- m_name = RandomName();
- //set surname
- m_surname = RandomSurname();
- //set exp
- m_expiriance = rand() % 15;
- }
- Engineer(string name, string surname, int expiriance)
- {
- m_name = name;
- m_surname = surname;
- m_expiriance = expiriance;
- }
- void FixSmth()
- {
- m_expiriance += 1;
- Engineer::CheckExp();
- }
- };
- class Sailor :public CrewMember {
- private:
- void CheckExp()
- {
- if (m_expiriance == 25)
- {
- cout << "Congratsulations! Your Sailor reached max expiriance and now he is leaving you." << endl;
- Sailor::GenerateNewSailor();
- }
- }
- public:
- Sailor()
- {
- //set name
- m_name = RandomName();
- //set surname
- m_surname = RandomSurname();
- //set exp
- m_expiriance = rand() % 25;
- }
- Sailor(string name, string surname, int expiriance)
- {
- m_name = name;
- m_surname = surname;
- m_expiriance = expiriance;
- }
- void Sail()
- {
- m_expiriance += 1;
- Sailor::CheckExp();
- }
- Sailor GenerateNewSailor()
- {
- Sailor NewSailor;
- string answer;
- cout << "Do you want to choose new random Sailor or create one by yourself?"
- << endl << "Input \"create\" to create new Sailor. Else it would be randomed." << endl;
- cin >> answer;
- if (answer == "create")
- {
- cout << "Input new Sailor name" << endl;
- string name;
- cin >> name;
- cout << "Input new Sailor surname" << endl;
- string surname;
- cin >> surname;
- cout << "Input new Sailor expiriance" << endl;
- int expiriance;
- cin >> expiriance;
- try
- {
- Sailor sailor(name, surname, expiriance);
- if (sailor.GetName().find_first_of
- ("~`1234567890-=!@#$%^&*()_+!! \" №;%:?*{}[]'|\\,./+=-*<>") != string::npos)
- throw invalid_argument("Invalid symbol at the name!");
- if (sailor.GetSurname().find_first_of
- ("~`1234567890-=!@#$%^&*()_+!! \" №;%:?*{}[]'|\\,./+=-*<>") != string::npos)
- throw invalid_argument("Invalid symbol at the surname!");
- if (sailor.GetExp()<0 || sailor.GetExp()>25)
- throw invalid_argument("Invalid value of expiriance!");
- }
- catch (invalid_argument e)
- {
- cout << "Error:" << e.what() << endl;
- }
- NewSailor = Sailor::Sailor(name, surname, expiriance);
- }
- else
- NewSailor = Sailor::Sailor();
- cout << "This is your new Sailor!" << endl;
- NewSailor.PrintInfo();
- return NewSailor;
- }
- };
- class Officer :public CrewMember {
- private:
- void CheckExp()
- {
- if (m_expiriance == 15)
- {
- cout << "Congratsulations! Your Officer reached max expiriance and now he is leaving you." << endl;
- Officer::GenerateNewOfficer();
- }
- }
- public:
- Officer()
- {
- //set name
- m_name = RandomName();
- //set surname
- m_surname = RandomSurname();
- //set exp
- //set exp
- m_expiriance = rand() % 15;
- }
- Officer(string name, string surname, int expiriance)
- {
- m_name = name;
- m_surname = surname;
- m_expiriance = expiriance;
- }
- void EmergState()
- {
- m_expiriance += 1;
- Officer::CheckExp();
- }
- Officer GenerateNewOfficer()
- {
- Officer NewOfficer;
- string answer;
- cout << "Do you want to choose new random Officer or create one by yourself?"
- << endl << "Input \"create\" to create new Officer. Else it would be randomed." << endl;
- cin >> answer;
- if (answer == "create")
- {
- cout << "Input new Officer name" << endl;
- string name;
- cin >> name;
- cout << "Input new Officer surname" << endl;
- string surname;
- cin >> surname;
- cout << "Input new Officer expiriance" << endl;
- int expiriance;
- cin >> expiriance;
- try
- {
- Officer NewOfficer(name, surname, expiriance);
- if (NewOfficer.GetName().find_first_of
- ("~`1234567890-=!@#$%^&*()_+!! \" №;%:?*{}[]'|\\,./+=-*<>") != string::npos)
- throw invalid_argument("Invalid symbol at the name!");
- if (NewOfficer.GetSurname().find_first_of
- ("~`1234567890-=!@#$%^&*()_+!! \" №;%:?*{}[]'|\\,./+=-*<>") != string::npos)
- throw invalid_argument("Invalid symbol at the surname!");
- if (NewOfficer.GetExp()<0 || NewOfficer.GetExp()>15)
- throw invalid_argument("Invalid value of expiriance!");
- }
- catch (invalid_argument e)
- {
- cout << "Error:" << e.what() << endl;
- }
- NewOfficer = Officer::Officer(name, surname, expiriance);
- }
- else
- NewOfficer = Officer::Officer();
- cout << "This is your new Older Engineer!" << endl;
- NewOfficer.PrintInfo();
- return NewOfficer;
- }
- };
- class Chief :public CrewMember {
- private:
- void CheckExp()
- {
- if (m_expiriance == 300)
- {
- cout << "Congratsulations! Your Chief reached max expiriance and now he is leaving you." << endl;
- Chief::GenerateNewChief();
- }
- }
- public:
- Chief()
- {
- //set name
- m_name = RandomName();
- //set surname
- m_surname = RandomSurname();
- //set exp
- m_expiriance = rand() % 15 + 35;
- }
- Chief(string name, string surname, int expiriance)
- {
- m_name = name;
- m_surname = surname;
- m_expiriance = expiriance;
- }
- void Sail()
- {
- m_expiriance += 1;
- Chief::CheckExp();
- }
- Chief GenerateNewChief()
- {
- Chief NewChief;
- string answer;
- cout << "Do you want to choose new random Chief or create one by yourself?"
- << endl << "Input \"create\" to create new Chief. Else it would be randomed." << endl;
- cin >> answer;
- if (answer == "create")
- {
- cout << "Input new Chief name" << endl;
- string name;
- cin >> name;
- cout << "Input new Chief surname" << endl;
- string surname;
- cin >> surname;
- cout << "Input new Chief expiriance" << endl;
- int expiriance;
- cin >> expiriance;
- try
- {
- Chief NewChief(name, surname, expiriance);
- if (NewChief.GetName().find_first_of
- ("~`1234567890-=!@#$%^&*()_+!! \" №;%:?*{}[]'|\\,./+=-*<>") != string::npos)
- throw invalid_argument("Invalid symbol at the name!");
- if (NewChief.GetSurname().find_first_of
- ("~`1234567890-=!@#$%^&*()_+!! \" №;%:?*{}[]'|\\,./+=-*<>") != string::npos)
- throw invalid_argument("Invalid symbol at the surname!");
- if (NewChief.GetExp()<0 || NewChief.GetExp()>300)
- throw invalid_argument("Invalid value of Chief expiriance!");
- }
- catch (invalid_argument e)
- {
- cout << "Error:" << e.what() << endl;
- }
- NewChief = Chief::Chief(name, surname, expiriance);
- }
- else
- NewChief = Chief::Chief();
- cout << "This is your new Chief!" << endl;
- NewChief.PrintInfo();
- return NewChief;
- }
- };
- class Crew
- {
- private:
- const int StockSailorsNum = 10;
- const int StockEngineersNum = 3;
- int SailorNum;
- int EngineerNum;
- Capitan m_Capitan;
- Mate m_Mate;
- OlderEngineer m_OlderEngineer;
- OlderOfficer m_OlderOfficer;
- OlderSailor m_OlderSailor;
- Chief m_Chief;
- vector<Sailor> m_Sailors;
- vector<Engineer> m_Engineers;
- public:
- // 6 основных членов команды
- int CrewSize() { return (6 + m_Engineers.size() + m_Sailors.size()); }
- Crew& operator=(const Crew & other);
- Crew()
- {
- m_Capitan = Capitan::Capitan();
- m_Mate = Mate::Mate();
- m_OlderEngineer = OlderEngineer::OlderEngineer();
- m_OlderOfficer = OlderOfficer::OlderOfficer();
- m_OlderSailor = OlderSailor::OlderSailor();
- m_Chief = Chief::Chief();
- for (int i = 0; i<StockSailorsNum; i++)
- m_Sailors.push_back(Sailor::Sailor());
- for (int i = 0; i<StockEngineersNum; i++)
- m_Engineers.push_back(Engineer::Engineer());
- }
- Crew(const Capitan& capitan, Mate mate, OlderEngineer older_engineer, OlderOfficer older_officer, OlderSailor older_sailor,
- vector<Sailor>& sailors, vector<Engineer>& engineers, Chief chief)
- {
- m_Capitan = capitan;
- m_Mate = mate;
- m_OlderEngineer = older_engineer;
- m_OlderOfficer = older_officer;
- m_OlderSailor = older_sailor;
- m_Sailors = sailors;
- m_Engineers = engineers;
- m_Chief = chief;
- }
- void GenerateNewCrew()
- {
- cout << "Do you want to create new team? Or choose it randomly?" << endl <<
- "Input \"create\" to create new team. Else it would be randomed" << endl;
- string answer;
- cin >> answer;
- if (answer == "create")
- {
- m_Capitan = m_Capitan.GenerateNewCapitan();
- m_Mate = m_Mate.GenerateNewMate();
- m_OlderOfficer = m_OlderOfficer.GenerateNewOlderOfficer();
- m_OlderEngineer = m_OlderEngineer.GenerateNewOlderEngineer();
- m_OlderSailor = m_OlderSailor.GenerateNewOlderSailor();
- for (int i = 0; i < m_Sailors.size(); i++)
- {
- m_Sailors[i] = m_Sailors[i].GenerateNewSailor();
- }
- for (int i = 0; i < m_Engineers.size(); i++)
- {
- m_Engineers[i] = m_Engineers[i].GenerateNewEngineer();
- }
- //Crew NewCrew(m_Capitan, m_Mate, m_OlderEngineer, m_OlderOfficer, m_OlderSailor, m_Sailors, m_Engineers, m_Chief);
- //return NewCrew;
- }
- else
- {
- Crew NewCrew = Crew::Crew();
- }
- }
- void Info()
- {
- m_Capitan.PrintInfo();
- cout << endl;
- m_Mate.PrintInfo();
- cout << endl;
- m_OlderOfficer.PrintInfo();
- cout << endl;
- m_OlderEngineer.PrintInfo();
- cout << endl;
- m_OlderSailor.PrintInfo();
- cout << endl;
- m_Chief.PrintInfo();
- cout << endl;
- for (int i = 0; i < m_Sailors.size(); i++)
- {
- m_Sailors[i].PrintInfo();
- cout << endl;
- }
- for (int i = 0; i < m_Engineers.size(); i++)
- {
- m_Engineers[i].PrintInfo();
- cout << endl;
- }
- }
- };
- class Ship
- {
- protected:
- double perc;
- double m_EnginePower;
- double m_Displacement;
- string m_ShipName;
- string m_PortName;
- Crew m_Crew;
- bool CheckPerc(int perc)
- {
- return (perc > 0);
- }
- public:
- virtual ~Ship()
- {
- }
- double UpgradeEngine()
- {
- cout << "Input percenatge of upgrade" << endl;
- cin >> perc;
- if (CheckPerc(perc) == 1)
- m_EnginePower *= (1 + perc / 100);
- return m_EnginePower;
- }
- double UpgradeDisplacement()
- {
- cout << "Input percenatge of upgrade" << endl;
- cin >> perc;
- if (CheckPerc(perc) == 1)
- m_Displacement *= (1 + perc / 100);
- return m_Displacement;
- }
- string& UpgradeShipName()
- {
- cout << "Input New Ships name" << endl;
- cin >> m_ShipName;
- return m_ShipName;
- }
- string& UpdatePort()
- {
- cout << "Input new Home Port" << endl;
- cin >> m_PortName;
- return m_PortName;
- }
- Ship()
- {
- m_EnginePower = 1000;
- m_Displacement = 1000;
- m_ShipName = "Ship";
- m_PortName = "Port";
- m_Crew = Crew();
- }
- Ship(int EnginePower, int Displacement, string ShipName, string PortName, const Crew& crew): m_Crew(crew)
- {
- if (EnginePower < 1000)
- {
- throw invalid_argument("- Invalid value of Engine Power!");
- }
- m_EnginePower = EnginePower;
- if (Displacement < 1000)
- {
- throw invalid_argument("- Invalid value of Displacement!");
- }
- m_Displacement = Displacement;
- m_ShipName = ShipName;
- m_PortName = PortName;
- }
- void ModifyShip()
- {
- string str;
- cout << "Do you want to modify your ship?" << endl << "Input y or yes to continue. Input smth else to exit" << endl;
- cin >> str;
- while (str == "yes" || str == "y")
- {
- {
- int x;
- cout << "What do you want to upgrade?" << endl <<
- "Input 0 for upgrading Engine Power" << endl <<
- "Input 1 for upgrading Displacement" << endl <<
- "Input 2 to refresh Ship Name" << endl <<
- "Input 3 to change Port Name" << endl <<
- "Input 4 to change team" << endl;
- cin >> x;
- try
- {
- if (x < 0)
- {
- throw (invalid_argument("x cant be more then 4 or less then 0"));
- }
- switch (x)
- {
- case(0):
- {
- Ship::UpgradeEngine();
- cout << m_EnginePower << endl;
- break;
- }
- case(1):
- {
- Ship::UpgradeDisplacement();
- cout << m_Displacement << endl;
- break;
- }
- case(2):
- {
- Ship::UpgradeShipName();
- cout << m_ShipName << endl;;
- break;
- }
- case(3):
- {
- Ship::UpdatePort();
- cout << m_PortName << endl;
- break;
- }
- case(4):
- {
- m_Crew.GenerateNewCrew();
- m_Crew.Info();
- break;
- }
- default:
- {
- break;
- }
- }
- }
- catch (invalid_argument e)
- {
- cout << "Error:" << e.what() << endl;
- }
- }
- cout << "Do you want to continue modifiying your ship?" << endl <<
- "Input y or yes to continue.Input smth else to exit" << endl;
- cin >> str;
- }
- }
- };
- class PassangerShip : public Ship
- {
- private:
- const int BoatSize = 15;
- int m_BoatNum;
- int m_PassNum;
- public:
- void Info()
- {
- cout << "Engine power is " << m_EnginePower << endl;
- cout << "Displacement is " << m_Displacement << endl;
- cout << "EShip Name is " << m_ShipName << endl;
- cout << "Home Port is " << m_PortName << endl;
- cout << "Boat Number is " << m_BoatNum << endl;
- cout << "Passenger number is " << m_PassNum << endl;
- m_Crew.Info();
- }
- bool CheckBoatNum()
- {
- return (m_BoatNum * BoatSize > m_PassNum + m_Crew.CrewSize());
- }
- void AddBoat()
- {
- if (PassangerShip::CheckBoatNum() == 0)
- {
- m_BoatNum += ((m_PassNum + BoatSize * m_BoatNum) % BoatSize + 1);
- }
- }
- PassangerShip()
- {
- m_EnginePower = 1000;
- m_Displacement = 1000;
- m_ShipName = "Ship";
- m_PortName = "Port";
- m_Crew = Crew::Crew();
- m_PassNum = 10;
- m_BoatNum = 2;
- }
- PassangerShip(int EnginePower, int Displacement, string ShipName, string PortName, Crew crew, int PassNum, int BoatNum)
- :Ship(EnginePower, Displacement, ShipName, PortName, crew)
- {
- try
- {
- if (EnginePower < 1000)
- {
- throw invalid_argument("Engine Power is too small");
- }
- m_EnginePower = EnginePower;
- }
- catch (invalid_argument e)
- {
- cout << "Error:" << e.what() << endl;
- }
- try
- {
- if (Displacement < 1000)
- {
- throw invalid_argument("Displacement is too small");
- }
- m_Displacement = Displacement;
- }
- catch (invalid_argument e)
- {
- cout << "Error:" << e.what() << endl;
- }
- m_ShipName = ShipName;
- m_PortName = PortName;
- m_Crew = crew;
- try
- {
- if (PassNum < 15)
- {
- throw invalid_argument("not enough passangers");
- }
- m_PassNum = PassNum;
- }
- catch (invalid_argument e)
- {
- cout << "Error:" << e.what() << endl;
- }
- try
- {
- if (BoatNum < 1)
- {
- throw invalid_argument("Number of boas cant be less then 1");
- }
- m_BoatNum = BoatNum;
- }
- catch (invalid_argument e)
- {
- cout << "Error:" << e.what() << endl;
- }
- }
- void AddExtraBoats(int AddictibleBoats)
- {
- m_BoatNum += AddictibleBoats;
- }
- };
- class CargoShip :public Ship
- {
- private:
- int m_LoadCapacity;
- public:
- CargoShip()
- {
- m_EnginePower = 1000;
- m_Displacement = 1000;
- m_ShipName = "Ship";
- m_PortName = "Port";
- m_Crew = Crew::Crew();
- m_LoadCapacity = 1000;
- }
- CargoShip(int EnginePower, int Displacement, string ShipName, string PortName, Crew crew, int LoadCapacity)
- :Ship(EnginePower, Displacement, ShipName, PortName, crew)
- {
- m_EnginePower = EnginePower;
- m_Displacement = Displacement;
- m_ShipName = ShipName;
- m_PortName = PortName;
- m_Crew = crew;
- try
- {
- if (LoadCapacity < 1000)
- {
- throw (invalid_argument(" - Invalid value of this field!"));
- }
- m_LoadCapacity = LoadCapacity;
- }
- catch (invalid_argument e)
- {
- cout << "Error!" << e.what() << endl;
- }
- }
- };
- void StartProgram()
- {
- cout << "What dou you want to do?" << endl;
- cout << "1) Generate Passanger ship" << endl;
- cout << "2) Generate Cargo ship" << endl;
- int x;
- cin >> x;
- switch (x)
- {
- case 1:
- {
- try
- {
- string name, port;
- int EnginePower, Displacement, BoatNum, PassNum;
- Crew crew;
- cout << "Input ships name" << endl;
- cin >> name;
- cout << "Input ships Home Port" << endl;
- cin >> port;
- cout << "Input ships Engine Power" << endl;
- cin >> EnginePower;
- cout << "Input ships Displacement" << endl;
- cin >> Displacement;
- cout << "Input Boat number" << endl;
- cin >> BoatNum;
- cout << "Input Passenger number" << endl;
- cin >> PassNum;
- crew.GenerateNewCrew();
- PassangerShip ship(EnginePower, Displacement, name, port, crew, PassNum, BoatNum);
- ship.AddBoat();
- ship.Info();
- cout << "Do you want to modify ship?" << endl;
- string answer;
- cin >> answer;
- if (answer == "yes" || answer == "y")
- ship.ModifyShip();
- }
- catch (const invalid_argument& e)
- {
- cout << "Error:" << e.what() << endl;
- }
- catch (const exception& e)
- {
- cout << "Unexpected Error:" << e.what() << endl;
- }
- break;
- }
- case 2:
- {
- string name, port;
- int EnginePower, Displacement, LoadCapacity;
- Crew crew;
- cout << "Input ships name" << endl;
- cin >> name;
- cout << "Input ships Home Port" << endl;
- cin >> port;
- cout << "Input ships Engine Power" << endl;
- cin >> EnginePower;
- cout << "Input ships Displacement" << endl;
- cin >> Displacement;
- cout << "Input Load Capacity" << endl;
- cin >> LoadCapacity;
- crew.GenerateNewCrew();
- CargoShip ship(EnginePower, Displacement, name, port, crew, LoadCapacity);
- break;
- }
- default:
- {
- cout << "Gool Luck!" << endl;
- }
- }
- }
- int main()
- {
- srand(time(NULL));
- StartProgram();
- return 0;
- }
- Crew& Crew::operator=(const Crew & other)
- {
- this->m_Capitan = other.m_Capitan;
- this->m_Mate = other.m_Mate;
- this->m_Chief = other.m_Chief;
- this->m_OlderOfficer = other.m_OlderOfficer;
- this->m_OlderEngineer = other.m_OlderEngineer;
- this->SailorNum = other.SailorNum;
- this->EngineerNum = other.EngineerNum;
- this->m_OlderSailor = other.m_OlderSailor;
- this->m_Sailors = other.m_Sailors;
- this->m_Engineers = other.m_Engineers;
- return *this;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement