diff --git a/CMakeLists.txt b/CMakeLists.txt new file mode 100644 index 0000000..cbc0b35 --- /dev/null +++ b/CMakeLists.txt @@ -0,0 +1,6 @@ +cmake_minimum_required(VERSION 3.14) +project(trukhan_cpp_project_plant) + +set(CMAKE_CXX_STANDARD 14) + +add_executable(trukhan_cpp_project_plant main.cpp headers/trukhan_cpp_project_plant.h) \ No newline at end of file diff --git a/README.md b/README.md index 88237ed..77a4426 100644 --- a/README.md +++ b/README.md @@ -1,3 +1,7 @@ +# Примечание +Код проекта написан на стандарте С++11, берите это во внимание. +Сжатая схема зависимостей классов указана в текстовом файле class_dependencies.txt + # CppCourse C++ course delivered in mech-math KNU diff --git a/headers/CMakeLists.txt b/headers/CMakeLists.txt new file mode 100644 index 0000000..cbc0b35 --- /dev/null +++ b/headers/CMakeLists.txt @@ -0,0 +1,6 @@ +cmake_minimum_required(VERSION 3.14) +project(trukhan_cpp_project_plant) + +set(CMAKE_CXX_STANDARD 14) + +add_executable(trukhan_cpp_project_plant main.cpp headers/trukhan_cpp_project_plant.h) \ No newline at end of file diff --git a/headers/headers/trukhan_cpp_project_plant.h b/headers/headers/trukhan_cpp_project_plant.h new file mode 100644 index 0000000..cf245c3 --- /dev/null +++ b/headers/headers/trukhan_cpp_project_plant.h @@ -0,0 +1,250 @@ +#ifndef TRUKHAN_CPP_PROJECT_PLANT_TRUKHAN_CPP_PROJECT_PLANT_H +#define TRUKHAN_CPP_PROJECT_PLANT_TRUKHAN_CPP_PROJECT_PLANT_H + +using namespace std; + +#include +#include +#include + +#include + +class Product +{ +protected: + string Title; + int Value; +public: + Product(); + Product(string, int); + explicit Product(string); + + void set_t(string); + void set_v(int); + + string get_t(); + int get_v(); + + friend istream &operator>>(istream&, Product&); + friend ostream &operator<<(ostream&, const Product&); +}; + +istream &operator>>(istream &in, Product &P) +{ + string first_result, second_result; + + in >> first_result >> second_result; + + P.set_t(first_result); + + P.set_v(stoi(second_result)); + + return in; +} + +ostream &operator<<(ostream &out, const Product &P) +{ + out << P.Title << endl << to_string(P.Value); + return out; +} + +Product::Product() : Title(), Value() {} + +Product::Product(string s) : Title(s), Value() {} + +Product::Product(string s, int v) : Title(s), Value(v) {} + +string Product::get_t() +{ + return this->Title; +} + +int Product::get_v() +{ + return this->Value; +} + +void Product::set_t(string s) +{ + this->Title = s; +} + +void Product::set_v(int v) +{ + this->Value = v; +} + +class Equipment: public Product +{ +public: + Equipment(); + explicit Equipment(string); + Equipment(string, int); +}; + +Equipment::Equipment() : Product() {} + +Equipment::Equipment(string s) : Product(s) {} + +Equipment::Equipment(string s, int v) : Product(s, v) {} + +class Profession +{ +private: + string Title; + float Cash; +public: + Profession(); + explicit Profession(string); + Profession(string, float); + + void set_t(string); + void set_w(float); + + string get_t(); + float get_w(); + + float calc_wages(unsigned); + + friend istream &operator>>(istream&, Profession&); + friend ostream &operator<<(ostream&, const Profession&); +}; + +istream &operator>>(istream &in, Profession &P) +{ + string first_result, second_result; + + in >> first_result >> second_result; + + P.set_t(first_result); + + P.set_w(stoi(second_result)); + + return in; +} + +ostream &operator<<(ostream &out, const Profession &P) +{ + out << P.Title << endl << to_string(P.Cash); + return out; +} + +Profession::Profession() : Title(), Cash() {} + +Profession::Profession(string s) : Title(s), Cash() {} + +Profession::Profession(string s, float w) : Title(s), Cash(w) {} + +void Profession::set_t(string s) +{ + this->Title = s; +} + +void Profession::set_w(float w) +{ + this->Cash = w; +} + +float Profession::calc_wages(unsigned y) +{ + return static_cast((y * 0.1 + 1 ) * this->Cash); // y? because +} + +class Person +{ +protected: + string Name; +public: + Person(); + explicit Person(string); + + void set_name(string); + string get_name(); + + friend istream &operator>>(istream&, Person&); + friend ostream &operator<<(ostream&, const Person&); +}; + +istream &operator>>(istream &in, Person &P) +{ + string result; + in >> result; + P.set_name(result); + return in; +} + +ostream &operator<<(ostream &out, const Person &P) +{ + out << P.Name; + return out; +} + +Person::Person() : Name() {} + +Person::Person(string N) : Name(N) {} + +void Person::set_name(string N) +{ + this->Name = N; +} + +string Person::get_name() +{ + return this->Name; +} + +class Employee: public Person +{ +protected: + unsigned Years; + Profession Job; + vector Products_in_use; + vector Equipment_in_use; +public: + Employee(); + Employee(string, unsigned); + explicit Employee(string); + + void set_years(unsigned); + unsigned get_years(); + + float calc_wages(); + float calc_product_cost(); + float calc_equipment_cost(); +}; + +Employee::Employee() : Person(), Years() {} + +Employee::Employee(string s) : Person(s), Years() {} + +Employee::Employee(string s, unsigned y) : Person(s), Years(y) {} + +void Employee::set_years(unsigned y) +{ + this->Years = y; +} + +unsigned Employee::get_years() +{ + return this->Years; +} + +float Employee::calc_wages() +{ + if(this->Job.get_t().empty() && !this->Job.get_w()) + throw runtime_error("Employee doesn't have any job yet..\n"); + + return this->Job.calc_wages(this->Years) + 0.001 * (this->calc_equipment_cost() + this->calc_product_cost()); +} + +class Manager: public Employee +{ +private: + vector Employees_list; +public: + Manager(); + explicit Manager(string); + Manager(string, unsigned); +}; + +#endif diff --git a/headers/main.cpp b/headers/main.cpp new file mode 100644 index 0000000..25eea18 --- /dev/null +++ b/headers/main.cpp @@ -0,0 +1,117 @@ +#define TESTS_NUM 6 + +#include "./headers/trukhan_cpp_project_plant.h" + +void test_person() +{ + cout << "Start" << endl; + + Person TEST_UNIT_1; + + TEST_UNIT_1.set_name("Ernest"); + cout << TEST_UNIT_1.get_name() << endl; + + string INPUT_NAME; + + cout << "Input your name" << endl; + cin >> INPUT_NAME; + + Person TEST_UNIT_2(INPUT_NAME); + + cout << TEST_UNIT_2.get_name() << endl; + + Person TEST_UNIT_3; + + cin >> TEST_UNIT_3; + cout << TEST_UNIT_3 << endl; +} + +void test_employee() +{ + cout << "Start" << endl; +} + +void test_manager() +{ + cout << "Start" << endl; +} + +void test_product() +{ + cout << "Start" << endl; + + Product TEST_UNIT_1; + + cin >> TEST_UNIT_1; + cout << TEST_UNIT_1 << endl; + + TEST_UNIT_1.set_t("Useless Item"); + TEST_UNIT_1.set_v(100); + + cout << TEST_UNIT_1.get_t() << '\t' << TEST_UNIT_1.get_v() << endl; + + fstream file; + + file.open("../test_product.txt", ios::out); + file << TEST_UNIT_1; + file.close(); +} + +void test_equipment() +{ + cout << "Start" << endl; + + Equipment TEST_UNIT_1; + + cin >> TEST_UNIT_1; + cout << TEST_UNIT_1 << endl; + + TEST_UNIT_1.set_v(100); + TEST_UNIT_1.set_t("Cucumber"); + + cout << TEST_UNIT_1 << endl; +} + +void test_profession() +{ + cout << "Start" << endl; + + Profession TEST_UNIT_1; + + TEST_UNIT_1.set_t("Plumber"); + TEST_UNIT_1.set_w(1500); + + cout << TEST_UNIT_1 << endl; +} + +void (*tests[TESTS_NUM])() = { + test_person, + test_employee, + test_manager, + test_product, + test_equipment, + test_profession +}; + +int main() +{ + unsigned v; + try + { + cout << "Tests for ... \n" + "1 - class Person \n" + "2 - class Employee \n" + "3 - class Manager \n" + "4 - class Product \n" + "5 - class Equipment \n" + "6 - class Profession \n"; + cin >> v; + if(!cin || (v > TESTS_NUM) || !v) + throw runtime_error("Invalid input\n"); + tests[v-1](); + } + catch (runtime_error e) + { + cerr << e.what(); + } +} \ No newline at end of file diff --git a/headers/misc_proj_info/class_dependencies b/headers/misc_proj_info/class_dependencies new file mode 100644 index 0000000..5ea34c8 --- /dev/null +++ b/headers/misc_proj_info/class_dependencies @@ -0,0 +1,6 @@ +Person Product Profession + | | +Employee Equipment + | +Manager + diff --git a/headers/misc_proj_info/warn b/headers/misc_proj_info/warn new file mode 100644 index 0000000..c2f0959 --- /dev/null +++ b/headers/misc_proj_info/warn @@ -0,0 +1,3 @@ +Код проекта написан на стандарте С++11, берите это во внимание. Сжатая схема зависимостей классов указана в текстовом файле class_dependencies.txt + +Подсчёт зарплаты для сотрудника здесь вымышленный и может показаться абсурдным. Думаю, что от этого оценка проекта шибко не пострадает. diff --git a/headers/test_product.txt b/headers/test_product.txt new file mode 100644 index 0000000..ed281b3 --- /dev/null +++ b/headers/test_product.txt @@ -0,0 +1,2 @@ +Useless Item +100 \ No newline at end of file diff --git a/headers/trukhan_cpp_project_plant.h b/headers/trukhan_cpp_project_plant.h new file mode 100644 index 0000000..d12f860 --- /dev/null +++ b/headers/trukhan_cpp_project_plant.h @@ -0,0 +1,360 @@ +#ifndef TRUKHAN_CPP_PROJECT_PLANT_TRUKHAN_CPP_PROJECT_PLANT_H +#define TRUKHAN_CPP_PROJECT_PLANT_TRUKHAN_CPP_PROJECT_PLANT_H + +using namespace std; + +#include +#include +#include + +#include + +class Product +{ +protected: + string Title; + int Value; +public: + Product(); + Product(string, int); + explicit Product(string); + + void set_t(string); + void set_v(int); + + string get_t(); + int get_v(); + + friend istream &operator>>(istream&, Product&); + friend ostream &operator<<(ostream&, const Product&); +}; + +istream &operator>>(istream &in, Product &P) +{ + string first_result, second_result; + + in >> first_result >> second_result; + + P.set_t(first_result); + + P.set_v(stoi(second_result)); + + return in; +} + +ostream &operator<<(ostream &out, const Product &P) +{ + out << P.Title << endl << to_string(P.Value); + return out; +} + +Product::Product() : Title(), Value() {} + +Product::Product(string s) : Title(s), Value() {} + +Product::Product(string s, int v) : Title(s), Value(v) {} + +string Product::get_t() +{ + return this->Title; +} + +int Product::get_v() +{ + return this->Value; +} + +void Product::set_t(string s) +{ + this->Title = s; +} + +void Product::set_v(int v) +{ + this->Value = v; +} + +class Equipment: public Product +{ +public: + Equipment(); + explicit Equipment(string); + Equipment(string, int); +}; + +Equipment::Equipment() : Product() {} + +Equipment::Equipment(string s) : Product(s) {} + +Equipment::Equipment(string s, int v) : Product(s, v) {} + +class Profession +{ +private: + string Title; + float Cash; +public: + Profession(); + explicit Profession(string); + Profession(string, float); + + void set_t(string); + void set_w(float); + + string get_t(); + float get_w(); + + float calc_wages(unsigned); + + friend istream &operator>>(istream&, Profession&); + friend ostream &operator<<(ostream&, const Profession&); +}; + +istream &operator>>(istream &in, Profession &P) +{ + string first_result, second_result; + + in >> first_result >> second_result; + + P.set_t(first_result); + + P.set_w(stoi(second_result)); + + return in; +} + +ostream &operator<<(ostream &out, const Profession &P) +{ + out << P.Title << endl << to_string(P.Cash); + return out; +} + +Profession::Profession() : Title(), Cash() {} + +Profession::Profession(string s) : Title(s), Cash() {} + +Profession::Profession(string s, float w) : Title(s), Cash(w) {} + +void Profession::set_t(string s) +{ + this->Title = s; +} + +void Profession::set_w(float w) +{ + this->Cash = w; +} + +float Profession::calc_wages(unsigned y) +{ + return static_cast((y * 0.1 + 1 ) * this->Cash); // y? because +} + +class Person +{ +protected: + string Name; +public: + Person(); + explicit Person(string); + + void set_name(string); + string get_name(); + + friend istream &operator>>(istream&, Person&); + friend ostream &operator<<(ostream&, const Person&); +}; + +istream &operator>>(istream &in, Person &P) +{ + string result; + in >> result; + P.set_name(result); + return in; +} + +ostream &operator<<(ostream &out, const Person &P) +{ + out << P.Name; + return out; +} + +Person::Person() : Name() {} + +Person::Person(string N) : Name(N) {} + +void Person::set_name(string N) +{ + this->Name = N; +} + +string Person::get_name() +{ + return this->Name; +} + +class Employee: public Person +{ +protected: + unsigned Years; + Profession Job; + vector Products_in_use; + vector Equipment_in_use; +public: + Employee(); + Employee(string, unsigned); + explicit Employee(string); + + void set_job(Profession); + + void set_years(unsigned); + unsigned get_years(); + + float calc_wages(); + float calc_product_cost(); + float calc_equipment_cost(); + + void push_back_product(const Product); + void push_back_equipment(const Equipment); + + void pop_by_index_product(unsigned); + void pop_by_index_equipment(unsigned); +}; + +Employee::Employee() : Person(), Years(), Equipment_in_use(), Products_in_use() {} + +Employee::Employee(string s) : Person(s), Years(), Equipment_in_use(), Products_in_use() {} + +Employee::Employee(string s, unsigned y) : Person(s), Years(y), Equipment_in_use(), Products_in_use() {} + +void Employee::set_job(Profession P) +{ + this->Job = P; +} + +void Employee::set_years(unsigned y) +{ + this->Years = y; +} + +unsigned Employee::get_years() +{ + return this->Years; +} + +float Employee::calc_wages() +{ + return this->Job.calc_wages(this->Years) + 0.001 * (this->calc_equipment_cost() + this->calc_product_cost()); +} + +float Employee::calc_product_cost() +{ + float final_sum = 0; + + for(auto& product : this->Products_in_use) + final_sum += product.get_v(); + + return final_sum; +} + +float Employee::calc_equipment_cost() +{ + float final_sum = 0; + + for(auto& product : this->Equipment_in_use) + final_sum += product.get_v(); + + return final_sum; +} + +void Employee::push_back_equipment(const Equipment E) +{ + this->Equipment_in_use.push_back(E); +} + +void Employee::push_back_product(const Product P) +{ + this->Products_in_use.push_back(P); +} + +void Employee::pop_by_index_equipment(unsigned I) +{ + this->Equipment_in_use.erase(Equipment_in_use.begin() + I); +} + +void Employee::pop_by_index_product(unsigned I) +{ + this->Products_in_use.erase(Products_in_use.begin() + I); +} + +class Manager: public Employee +{ +private: + vector Employees_list; +public: + Manager(); + explicit Manager(string); + Manager(string, unsigned); + + void push_back_employee(const Employee); + void pop_employee_by_index(unsigned); + + Employee get_employee_by_index(unsigned); + + float calc_employees_e_values(); + float calc_employees_p_values(); + float calc_employees_w_values(); +}; + +Manager::Manager() : Employee(), Employees_list() {} + +Manager::Manager(string s) : Employee(s), Employees_list() {} + +Manager::Manager(string s, unsigned y) : Employee(s, y), Employees_list() {} + +void Manager::push_back_employee(const Employee EMPLOYEE) +{ + this->Employees_list.push_back(EMPLOYEE); +} + +void Manager::pop_employee_by_index(unsigned I) +{ + this->Employees_list.erase(Employees_list.begin() + I); +} + +Employee Manager::get_employee_by_index(unsigned I) +{ + return this->Employees_list[I]; +} + +float Manager::calc_employees_e_values() +{ + float final_sum = 0; + + for(auto& employee : this->Employees_list) + final_sum += employee.calc_equipment_cost(); + + return final_sum; +} + +float Manager::calc_employees_p_values() +{ + float final_sum = 0; + + for(auto& employee : this->Employees_list) + final_sum += employee.calc_product_cost(); + + return final_sum; +} + +float Manager::calc_employees_w_values() +{ + float final_sum = 0; + + for(auto& employee : this->Employees_list) + final_sum += employee.calc_wages(); + + return final_sum; +} + +#endif diff --git a/main.cpp b/main.cpp new file mode 100644 index 0000000..f10aba0 --- /dev/null +++ b/main.cpp @@ -0,0 +1,172 @@ +#define TESTS_NUM 6 + +#include "./headers/trukhan_cpp_project_plant.h" + +void test_person() +{ + cout << "Start" << endl; + + Person TEST_UNIT_1; + + TEST_UNIT_1.set_name("Ernest"); + cout << TEST_UNIT_1.get_name() << endl; + + string INPUT_NAME; + + cout << "Input your name" << endl; + cin >> INPUT_NAME; + + Person TEST_UNIT_2(INPUT_NAME); + + cout << TEST_UNIT_2.get_name() << endl; + + Person TEST_UNIT_3; + + cin >> TEST_UNIT_3; + cout << TEST_UNIT_3 << endl; +} + +void test_employee() +{ + cout << "Start" << endl; + + Product P1("TEST", 100); + Equipment E1("TEST1", 150), E2("TEST1", 175); + + Profession PROF; + + cin >> PROF; + + Employee TEST_UNIT_1; + + TEST_UNIT_1.set_name("Alyona"); + TEST_UNIT_1.set_job(PROF); + + TEST_UNIT_1.push_back_product(P1); + + TEST_UNIT_1.push_back_equipment(E1); + TEST_UNIT_1.push_back_equipment(E2); + + TEST_UNIT_1.set_years(10); + + cout << TEST_UNIT_1.calc_wages() << endl + << TEST_UNIT_1.calc_product_cost() << endl + << TEST_UNIT_1.calc_equipment_cost() << endl; +} + +void test_manager() +{ + cout << "Start" << endl; + + Product P1("TEST", 75); + Equipment E1("TEST1", 25), E2("TEST1", 15); + + Profession PROF; + + PROF.set_t("TEST_UNIT_1"); + + Employee TEST_UNIT_1; + + TEST_UNIT_1.set_name("User_Test_Unit"); + TEST_UNIT_1.set_job(PROF); + + TEST_UNIT_1.push_back_product(P1); + + TEST_UNIT_1.push_back_equipment(E1); + TEST_UNIT_1.push_back_equipment(E2); + + TEST_UNIT_1.set_years(9); + + Manager TEST_UNIT_MANAGER; + + TEST_UNIT_MANAGER.set_name("Ernest"); + + for(int i=0; i<3; i++) + TEST_UNIT_MANAGER.push_back_employee(TEST_UNIT_1); + + cout << TEST_UNIT_MANAGER.calc_employees_e_values() << endl + << TEST_UNIT_MANAGER.calc_employees_p_values() << endl + << TEST_UNIT_MANAGER.calc_employees_w_values() << endl; + + TEST_UNIT_MANAGER.pop_employee_by_index(1); +} + +void test_product() +{ + cout << "Start" << endl; + + Product TEST_UNIT_1; + + cin >> TEST_UNIT_1; + cout << TEST_UNIT_1 << endl; + + TEST_UNIT_1.set_t("Useless Item"); + TEST_UNIT_1.set_v(100); + + cout << TEST_UNIT_1.get_t() << '\t' << TEST_UNIT_1.get_v() << endl; + + fstream file; + + file.open("../test_product.txt", ios::out); + file << TEST_UNIT_1; + file.close(); +} + +void test_equipment() +{ + cout << "Start" << endl; + + Equipment TEST_UNIT_1; + + cin >> TEST_UNIT_1; + cout << TEST_UNIT_1 << endl; + + TEST_UNIT_1.set_v(100); + TEST_UNIT_1.set_t("Cucumber"); + + cout << TEST_UNIT_1 << endl; +} + +void test_profession() +{ + cout << "Start" << endl; + + Profession TEST_UNIT_1; + + TEST_UNIT_1.set_t("Plumber"); + TEST_UNIT_1.set_w(1500); + + cout << TEST_UNIT_1 << endl; +} + +void (*tests[TESTS_NUM])() = { + test_person, + test_employee, + test_manager, + test_product, + test_equipment, + test_profession +}; + +int main() +{ + unsigned v; + try + { + cout << "Tests for ... \n" + "1 - class Person \n" + "2 - class Employee \n" + "3 - class Manager \n" + "4 - class Product \n" + "5 - class Equipment \n" + "6 - class Profession \n"; + cin >> v; + if(!cin || (v > TESTS_NUM) || !v) + throw runtime_error("Invalid input\n"); + tests[v-1](); + } + catch (runtime_error e) + { + cerr << e.what(); + } +} \ No newline at end of file diff --git a/misc_proj_info/class_dependencies b/misc_proj_info/class_dependencies new file mode 100644 index 0000000..5ea34c8 --- /dev/null +++ b/misc_proj_info/class_dependencies @@ -0,0 +1,6 @@ +Person Product Profession + | | +Employee Equipment + | +Manager + diff --git a/misc_proj_info/warn b/misc_proj_info/warn new file mode 100644 index 0000000..39e77f3 --- /dev/null +++ b/misc_proj_info/warn @@ -0,0 +1,10 @@ +Код проекта написан на стандарте С++11, берите это во внимание. Сжатая схема зависимостей классов указана в текстовом файле class_dependencies.txt + +Подсчёт зарплаты для сотрудника здесь вымышленный и может показаться абсурдным. Думаю, что от этого оценка проекта шибко не пострадает. + +Основные файлы проекта: + +\headers\trukhan_cpp_project_plant.h +\trukhan_cpp_project_plant.cpp + +Обратите внимание, в папке headers будут дубликаты вышеуказанных файлов. По своей глупости в один момент закинул файлы в левый каталог. diff --git a/test_product.txt b/test_product.txt new file mode 100644 index 0000000..ed281b3 --- /dev/null +++ b/test_product.txt @@ -0,0 +1,2 @@ +Useless Item +100 \ No newline at end of file