Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -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)
4 changes: 4 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
# Примечание
Код проекта написан на стандарте С++11, берите это во внимание.
Сжатая схема зависимостей классов указана в текстовом файле class_dependencies.txt

# CppCourse
C++ course delivered in mech-math KNU

Expand Down
6 changes: 6 additions & 0 deletions headers/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -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)
250 changes: 250 additions & 0 deletions headers/headers/trukhan_cpp_project_plant.h
Original file line number Diff line number Diff line change
@@ -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 <fstream>
#include <string>
#include <vector>

#include <iostream>

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<float>((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<Product> Products_in_use;
vector<Equipment> 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<Employee> Employees_list;
public:
Manager();
explicit Manager(string);
Manager(string, unsigned);
};

#endif
117 changes: 117 additions & 0 deletions headers/main.cpp
Original file line number Diff line number Diff line change
@@ -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();
}
}
Loading