diff --git a/CMakeLists.txt b/CMakeLists.txt new file mode 100644 index 0000000..73f81dd --- /dev/null +++ b/CMakeLists.txt @@ -0,0 +1,6 @@ +cmake_minimum_required(VERSION 3.14) +project(university_sulyma_mariia) + +set(CMAKE_CXX_STANDARD 11) + +add_executable(university_sulyma_mariia src/university_sulyma.cpp headers/univeristy_sulyma.h tests/university_tests_sulyma.cpp) \ No newline at end of file diff --git a/README.md b/README.md index 915cb30..e18cd13 100644 --- a/README.md +++ b/README.md @@ -10,3 +10,5 @@ C - projects : https://github.com/albatros78/C-Projects C++ projects + +Программный проект написан за стандартом С++11! diff --git a/headers/univeristy_sulyma.h b/headers/univeristy_sulyma.h new file mode 100644 index 0000000..f36127a --- /dev/null +++ b/headers/univeristy_sulyma.h @@ -0,0 +1,110 @@ +#ifndef UNIVERSITY_SULYMA_MARIIA_UNIVERISTY_SULYMA_H +#define UNIVERSITY_SULYMA_MARIIA_UNIVERISTY_SULYMA_H + +#include +#include + +namespace University +{ + class Human; + class Recordbook; + class Profession; + + class Student; + class Teacher; + class Worker; +} + +class University::Human +{ + virtual int getSalary() = 0; +}; + +class University::Recordbook +{ +private: + int math; + int computerScience; + int philosophy; + int pe; +public: + Recordbook(); + Recordbook(int i1, int i2, int i3, int i4); + + double getAverage(); + + friend std::istream &operator>>(std::istream &in, Recordbook &r) + { + in >> r.math; + in >> r.computerScience; + in >> r.philosophy; + in >> r.pe; + return in; + } + friend std::ostream &operator<<(std::ostream &out, const Recordbook &r) + { + out << r.math << std::endl; + out << r.computerScience << std::endl; + out << r.philosophy << std::endl; + out << r.pe << std::endl; + return out; + } +}; + +class University::Profession +{ + const static int base = 8000; +public: + std::string title; + int experience; + int k; + + Profession(); + Profession(std::string s, int i1, int i2); + + int premium(); +}; + +class University::Student : public Human +{ + Recordbook rb; + std::string name; + std::string surname; + + Student(); + Student(int i1, int i2, int i3, int i4, std::string s1, std::string s2); + + int getSalary() override; +}; + +class University::Teacher : public Human +{ + std::string name; + std::string surname; + bool rate; + int experience; + + Teacher(); + Teacher(std::string s1, std::string s2, bool b, int i); + + int getSalary() override + { + if (!rate) + { + return 15000 + 1000 * experience; + } + return 25000 + 1000 * experience; + } +}; + +class University::Worker : public Human +{ + std::string name; + std::string surname; + Profession profession; + + Worker(); + Worker(std::string s1, std::string s2, std::string s3, int i1, int i2); +}; + +#endif \ No newline at end of file diff --git a/output_data_recordbook.txt b/output_data_recordbook.txt new file mode 100644 index 0000000..5a2248d --- /dev/null +++ b/output_data_recordbook.txt @@ -0,0 +1,4 @@ +100 +99 +88 +79 diff --git a/src/university_sulyma.cpp b/src/university_sulyma.cpp new file mode 100644 index 0000000..087e524 --- /dev/null +++ b/src/university_sulyma.cpp @@ -0,0 +1,56 @@ +#include "../headers/univeristy_sulyma.h" + +University::Recordbook::Recordbook(): +math(), computerScience(), philosophy(), pe() +{} + +University::Recordbook::Recordbook(int i1, int i2, int i3, int i4): +math(i1), computerScience(i2), philosophy(i3), pe(i4) +{} + +double University::Recordbook::getAverage() +{ + return (math + computerScience + philosophy + pe) / 4.; +} + +University::Profession::Profession(): +title(), experience(), k() +{} + +University::Profession::Profession(std::string s, int i1, int i2): +title(s), experience(i1), k(i2) +{} + +int University::Profession::premium() +{ + return k * experience; +} + +University::Student::Student(): +rb(Recordbook()), name(), surname() +{} + +University::Student::Student(int i1, int i2, int i3, int i4, std::string s1, std::string s2): +rb(Recordbook(i1, i2, i3, i4)), name(s1), surname(s2) +{} + +int University::Student::getSalary() +{ + return (int)(4000 * rb.getAverage()); +} + +University::Teacher::Teacher(): +name(), surname(), rate(), experience() +{} + +University::Teacher::Teacher(std::string s1, std::string s2, bool b, int i): +name(s1), surname(s2), rate(b), experience(i) +{} + +University::Worker::Worker(): +profession(Profession()), name(), surname() +{} + +University::Worker::Worker(std::string s1, std::string s2, std::string s3, int i1, int i2): +profession(Profession(s1, i1, i2)), name(s2), surname(s3) +{} \ No newline at end of file diff --git a/tests/university_tests_sulyma.cpp b/tests/university_tests_sulyma.cpp new file mode 100644 index 0000000..67ca138 --- /dev/null +++ b/tests/university_tests_sulyma.cpp @@ -0,0 +1,102 @@ +#define _ERR_INVALID_INPUT 1 + +#include "../headers/univeristy_sulyma.h" + +#include +#include + +using namespace University; + +void TestStudent() +{ + +} + +void TestTeacher() +{ + +} + +void TestWorker() +{ + +} + +void TestRecordbook() +{ + Recordbook r; + + std::cout << "Input marks for math, cs, philosophy, p.e.:" << std::endl; + std::cin >> r; + + std::cout << "Output marks:" << std::endl; + std::cout << r; + + std::cout << "Writing data..." << std::endl; + + std::fstream i_text_file_stream("../output_data_recordbook.txt", std::ios::out); + + i_text_file_stream << r; + + i_text_file_stream.close(); + + std::cout << "Done." << std::endl; + + Recordbook q; + + std::cout << "Reading data from text file..." << std::endl; + + std::fstream o_text_file_stream("../output_data_recordbook.txt", std::ios::in); + + o_text_file_stream >> q; + + o_text_file_stream.close(); + + std::cout << q; + + std::cout << "Done." << std::endl; + + std::cout << "Avg. is " << r.getAverage() << std::endl; +} + +int main() +{ + short m; + + std::cout << "\tEnter mode:\n" + "1 - test Student class\n" + "2 - test Teacher class\n" + "3 - test Worker class\n" + "4 - test Recordbook class\n" << std::endl; + + std::cin >> m; + + switch (m) + { + case 1: + { + TestStudent(); + break; + } + case 2: + { + TestTeacher(); + break; + } + case 3: + { + TestWorker(); + break; + } + case 4: + { + TestRecordbook(); + break; + } + default: + { + std::cout << "Error: Invalid input" << std::endl; + exit(_ERR_INVALID_INPUT); + } + } +} \ No newline at end of file