From ab2fee535d24e3fd23b6442071b82ac93fa26321 Mon Sep 17 00:00:00 2001 From: ErnestTrukhan <55176484+ErnestTrukhan@users.noreply.github.com> Date: Thu, 12 Sep 2019 00:43:32 +0300 Subject: [PATCH 01/12] Trukhan Ernest. Group Statistics. Project #18 Plant --- CMakeLists.txt | 6 + headers/trukhan_cpp_project_plant.h | 182 ++++++++++++++++++++++++++++ main.cpp | 87 +++++++++++++ 3 files changed, 275 insertions(+) create mode 100644 CMakeLists.txt create mode 100644 headers/trukhan_cpp_project_plant.h create mode 100644 main.cpp 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/headers/trukhan_cpp_project_plant.h b/headers/trukhan_cpp_project_plant.h new file mode 100644 index 0000000..ae1b0a9 --- /dev/null +++ b/headers/trukhan_cpp_project_plant.h @@ -0,0 +1,182 @@ +#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 + +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; + int second_result; + in >> first_result; + P.set_t(first_result); + + return in; +} + +ostream &operator<<(ostream &out, const Product &P) +{ + out << static_cast("Class Person Data:\t") << P.Name; + 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: + +}; +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 << static_cast("Class Person Data:\t") << 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 Equipment_in_use; +public: + Employee(); + Employee(string, unsigned); + explicit Employee(string); + + void set_years(unsigned); + unsigned get_years(); +}; + +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; +} + +class Manager: public Employee +{ +private: + vector Employees_list; +public: + Manager(); + explicit Manager(string); + Manager(string, unsigned); +}; + +class Pluralist: public Employee +{ + +}; + +#endif diff --git a/main.cpp b/main.cpp new file mode 100644 index 0000000..33bfefa --- /dev/null +++ b/main.cpp @@ -0,0 +1,87 @@ +#define TESTS_NUM 6 + +#include "./headers/trukhan_cpp_project_plant.h" + +#include +#include + +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; +} + +void test_employee() +{ + cout << "Start" << endl; +} + +void test_manager() +{ + cout << "Start" << endl; +} + +void test_product() +{ + cout << "Start" << endl; +} + +void test_equipment() +{ + cout << "Start" << endl; +} + +void test_profession() +{ + cout << "Start" << 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 From a87819fc98d9f3c5ffddbce7a4d20a0c8bd05fcd Mon Sep 17 00:00:00 2001 From: ErnestTrukhan <55176484+ErnestTrukhan@users.noreply.github.com> Date: Thu, 12 Sep 2019 00:54:38 +0300 Subject: [PATCH 02/12] upd tests --- headers/trukhan_cpp_project_plant.h | 10 ++++++---- main.cpp | 12 +++++++++++- 2 files changed, 17 insertions(+), 5 deletions(-) diff --git a/headers/trukhan_cpp_project_plant.h b/headers/trukhan_cpp_project_plant.h index ae1b0a9..bc4f77a 100644 --- a/headers/trukhan_cpp_project_plant.h +++ b/headers/trukhan_cpp_project_plant.h @@ -28,17 +28,19 @@ class Product istream &operator>>(istream &in, Product &P) { - string first_result; - int second_result; - in >> first_result; + 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 << static_cast("Class Person Data:\t") << P.Name; + out << static_cast("Class Product Data:\t") << P.Title << static_cast("\t") << to_string(P.Value); return out; } diff --git a/main.cpp b/main.cpp index 33bfefa..81939e9 100644 --- a/main.cpp +++ b/main.cpp @@ -26,7 +26,7 @@ void test_person() Person TEST_UNIT_3; cin >> TEST_UNIT_3; - cout << TEST_UNIT_3; + cout << TEST_UNIT_3 << endl; } void test_employee() @@ -42,6 +42,16 @@ void test_manager() 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; } void test_equipment() From 505a52877a2c77ec4269ea461ba781cda920ac41 Mon Sep 17 00:00:00 2001 From: ErnestTrukhan <55176484+ErnestTrukhan@users.noreply.github.com> Date: Thu, 12 Sep 2019 01:06:08 +0300 Subject: [PATCH 03/12] upd --- headers/trukhan_cpp_project_plant.h | 25 ++++++++++++++++++++----- misc_proj_info/class_dependencies | 6 ++++++ 2 files changed, 26 insertions(+), 5 deletions(-) create mode 100644 misc_proj_info/class_dependencies diff --git a/headers/trukhan_cpp_project_plant.h b/headers/trukhan_cpp_project_plant.h index bc4f77a..ef2b9f2 100644 --- a/headers/trukhan_cpp_project_plant.h +++ b/headers/trukhan_cpp_project_plant.h @@ -90,8 +90,28 @@ class Profession 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&, Product&); + friend ostream &operator<<(ostream&, const Product&); }; + +Profession::Profession() : Title(), Cash() {} + +Profession::Profession(string s) : Title(s), Cash() {} + +Profession::Profession(string s, float w) : Title(s), Cash(w) {} + class Person { protected: @@ -176,9 +196,4 @@ class Manager: public Employee Manager(string, unsigned); }; -class Pluralist: public Employee -{ - -}; - #endif 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 + From bfb5a6ac0a29a005e5b5db07a5429032001f6baa Mon Sep 17 00:00:00 2001 From: ErnestTrukhan <55176484+ErnestTrukhan@users.noreply.github.com> Date: Thu, 12 Sep 2019 01:44:04 +0300 Subject: [PATCH 04/12] Add files via upload --- headers/trukhan_cpp_project_plant.h | 25 +++++++++++++++++++++---- main.cpp | 23 +++++++++++++++++++++++ test_product.txt | 2 ++ 3 files changed, 46 insertions(+), 4 deletions(-) create mode 100644 test_product.txt diff --git a/headers/trukhan_cpp_project_plant.h b/headers/trukhan_cpp_project_plant.h index ef2b9f2..f9b2a9b 100644 --- a/headers/trukhan_cpp_project_plant.h +++ b/headers/trukhan_cpp_project_plant.h @@ -3,9 +3,12 @@ using namespace std; +#include #include #include +#include + class Product { protected: @@ -33,6 +36,7 @@ istream &operator>>(istream &in, Product &P) in >> first_result >> second_result; P.set_t(first_result); + P.set_v(stoi(second_result)); return in; @@ -40,7 +44,7 @@ istream &operator>>(istream &in, Product &P) ostream &operator<<(ostream &out, const Product &P) { - out << static_cast("Class Product Data:\t") << P.Title << static_cast("\t") << to_string(P.Value); + out << P.Title << endl << to_string(P.Value); return out; } @@ -102,8 +106,8 @@ class Profession float calc_wages(unsigned); - friend istream &operator>>(istream&, Product&); - friend ostream &operator<<(ostream&, const Product&); + friend istream &operator>>(istream&, Profession&); + friend ostream &operator<<(ostream&, const Profession&); }; Profession::Profession() : Title(), Cash() {} @@ -112,6 +116,18 @@ 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; +} + + + class Person { protected: @@ -137,7 +153,7 @@ istream &operator>>(istream &in, Person &P) ostream &operator<<(ostream &out, const Person &P) { - out << static_cast("Class Person Data:\t") << P.Name; + out << P.Name; return out; } @@ -160,6 +176,7 @@ class Employee: public Person protected: unsigned Years; Profession Job; + vector Products_in_use; vector Equipment_in_use; public: Employee(); diff --git a/main.cpp b/main.cpp index 81939e9..1ad1bfd 100644 --- a/main.cpp +++ b/main.cpp @@ -52,16 +52,39 @@ void test_product() 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])() = { 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 From 2e97673188d92cdb56d1d95e0880bc25a522b119 Mon Sep 17 00:00:00 2001 From: ErnestTrukhan <55176484+ErnestTrukhan@users.noreply.github.com> Date: Thu, 12 Sep 2019 01:46:17 +0300 Subject: [PATCH 05/12] Update README.md --- README.md | 4 ++++ 1 file changed, 4 insertions(+) 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 From ae114aa186ec916ee7df5f79334fbfd1deb5a32d Mon Sep 17 00:00:00 2001 From: ErnestTrukhan <55176484+ErnestTrukhan@users.noreply.github.com> Date: Thu, 12 Sep 2019 01:47:06 +0300 Subject: [PATCH 06/12] Add files via upload --- misc_proj_info/warn | 1 + 1 file changed, 1 insertion(+) create mode 100644 misc_proj_info/warn diff --git a/misc_proj_info/warn b/misc_proj_info/warn new file mode 100644 index 0000000..6bb12b1 --- /dev/null +++ b/misc_proj_info/warn @@ -0,0 +1 @@ +Код проекта написан на стандарте С++11, берите это во внимание. Сжатая схема зависимостей классов указана в текстовом файле class_dependencies.txt From 16a7567b5cf009e810542e59257dae22e4a9cf1f Mon Sep 17 00:00:00 2001 From: ErnestTrukhan <55176484+ErnestTrukhan@users.noreply.github.com> Date: Thu, 12 Sep 2019 02:01:59 +0300 Subject: [PATCH 07/12] new upload --- headers/CMakeLists.txt | 6 + headers/headers/trukhan_cpp_project_plant.h | 250 ++++++++++++++++++++ headers/main.cpp | 117 +++++++++ headers/misc_proj_info/class_dependencies | 6 + headers/misc_proj_info/warn | 3 + headers/test_product.txt | 2 + 6 files changed, 384 insertions(+) create mode 100644 headers/CMakeLists.txt create mode 100644 headers/headers/trukhan_cpp_project_plant.h create mode 100644 headers/main.cpp create mode 100644 headers/misc_proj_info/class_dependencies create mode 100644 headers/misc_proj_info/warn create mode 100644 headers/test_product.txt 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 From edf54e6392196a2e2a5f6a53549324391d1036e5 Mon Sep 17 00:00:00 2001 From: ErnestTrukhan <55176484+ErnestTrukhan@users.noreply.github.com> Date: Thu, 12 Sep 2019 02:09:28 +0300 Subject: [PATCH 08/12] more methods --- headers/trukhan_cpp_project_plant.h | 56 ++++++++++++++++++++++++++++- main.cpp | 3 -- misc_proj_info/warn | 2 ++ 3 files changed, 57 insertions(+), 4 deletions(-) diff --git a/headers/trukhan_cpp_project_plant.h b/headers/trukhan_cpp_project_plant.h index f9b2a9b..ca3e30f 100644 --- a/headers/trukhan_cpp_project_plant.h +++ b/headers/trukhan_cpp_project_plant.h @@ -110,6 +110,25 @@ class 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() {} @@ -126,7 +145,10 @@ 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 { @@ -185,6 +207,10 @@ class Employee: public Person void set_years(unsigned); unsigned get_years(); + + float calc_wages(); + float calc_product_cost(); + float calc_equipment_cost(); }; Employee::Employee() : Person(), Years() {} @@ -203,6 +229,34 @@ 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()); +} + +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; +} + class Manager: public Employee { private: diff --git a/main.cpp b/main.cpp index 1ad1bfd..25eea18 100644 --- a/main.cpp +++ b/main.cpp @@ -2,9 +2,6 @@ #include "./headers/trukhan_cpp_project_plant.h" -#include -#include - void test_person() { cout << "Start" << endl; diff --git a/misc_proj_info/warn b/misc_proj_info/warn index 6bb12b1..c2f0959 100644 --- a/misc_proj_info/warn +++ b/misc_proj_info/warn @@ -1 +1,3 @@ Код проекта написан на стандарте С++11, берите это во внимание. Сжатая схема зависимостей классов указана в текстовом файле class_dependencies.txt + +Подсчёт зарплаты для сотрудника здесь вымышленный и может показаться абсурдным. Думаю, что от этого оценка проекта шибко не пострадает. From 24d98d8a1512f9294299e777ee050bff3a8b4c66 Mon Sep 17 00:00:00 2001 From: ErnestTrukhan <55176484+ErnestTrukhan@users.noreply.github.com> Date: Thu, 12 Sep 2019 02:13:14 +0300 Subject: [PATCH 09/12] info + other --- misc_proj_info/warn | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/misc_proj_info/warn b/misc_proj_info/warn index c2f0959..39e77f3 100644 --- a/misc_proj_info/warn +++ b/misc_proj_info/warn @@ -1,3 +1,10 @@ Код проекта написан на стандарте С++11, берите это во внимание. Сжатая схема зависимостей классов указана в текстовом файле class_dependencies.txt Подсчёт зарплаты для сотрудника здесь вымышленный и может показаться абсурдным. Думаю, что от этого оценка проекта шибко не пострадает. + +Основные файлы проекта: + +\headers\trukhan_cpp_project_plant.h +\trukhan_cpp_project_plant.cpp + +Обратите внимание, в папке headers будут дубликаты вышеуказанных файлов. По своей глупости в один момент закинул файлы в левый каталог. From 05b45d1c10a49a9852ba24e16b83a1f50bf37295 Mon Sep 17 00:00:00 2001 From: ErnestTrukhan <55176484+ErnestTrukhan@users.noreply.github.com> Date: Thu, 12 Sep 2019 02:22:27 +0300 Subject: [PATCH 10/12] pre-last upd --- headers/trukhan_cpp_project_plant.h | 49 +++++++++++++++++++++++++++++ 1 file changed, 49 insertions(+) diff --git a/headers/trukhan_cpp_project_plant.h b/headers/trukhan_cpp_project_plant.h index ca3e30f..6f9453b 100644 --- a/headers/trukhan_cpp_project_plant.h +++ b/headers/trukhan_cpp_project_plant.h @@ -265,6 +265,55 @@ class Manager: public Employee 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(); }; +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; +} + #endif From 18fb646f0ec4807a035f50814b0a6f9f76723093 Mon Sep 17 00:00:00 2001 From: ErnestTrukhan <55176484+ErnestTrukhan@users.noreply.github.com> Date: Thu, 12 Sep 2019 02:46:59 +0300 Subject: [PATCH 11/12] upd-new --- headers/trukhan_cpp_project_plant.h | 57 +++++++++++++++++++++++++---- 1 file changed, 49 insertions(+), 8 deletions(-) diff --git a/headers/trukhan_cpp_project_plant.h b/headers/trukhan_cpp_project_plant.h index 6f9453b..d12f860 100644 --- a/headers/trukhan_cpp_project_plant.h +++ b/headers/trukhan_cpp_project_plant.h @@ -205,19 +205,32 @@ class Employee: public Person 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() {} +Employee::Employee() : Person(), Years(), Equipment_in_use(), Products_in_use() {} -Employee::Employee(string s) : Person(s), Years() {} +Employee::Employee(string s) : Person(s), Years(), Equipment_in_use(), Products_in_use() {} -Employee::Employee(string s, unsigned y) : Person(s), Years(y) {} +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) { @@ -231,9 +244,6 @@ unsigned Employee::get_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()); } @@ -257,6 +267,26 @@ float Employee::calc_equipment_cost() 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: @@ -266,13 +296,14 @@ class Manager: public Employee explicit Manager(string); Manager(string, unsigned); - void push_back_employee(const Employee&); + 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() {} @@ -281,7 +312,7 @@ 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) +void Manager::push_back_employee(const Employee EMPLOYEE) { this->Employees_list.push_back(EMPLOYEE); } @@ -316,4 +347,14 @@ float Manager::calc_employees_p_values() 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 From af4ab26f6cad6f196317921e30e164a73c28bfd6 Mon Sep 17 00:00:00 2001 From: ErnestTrukhan <55176484+ErnestTrukhan@users.noreply.github.com> Date: Thu, 12 Sep 2019 02:51:42 +0300 Subject: [PATCH 12/12] upd1-new --- main.cpp | 55 +++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 55 insertions(+) diff --git a/main.cpp b/main.cpp index 25eea18..f10aba0 100644 --- a/main.cpp +++ b/main.cpp @@ -29,11 +29,66 @@ void test_person() 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()