Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Sulyma Mariia. Group Statistics. Project #19 University #20

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
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(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)
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,3 +10,5 @@ C - projects :
https://github.com/albatros78/C-Projects

C++ projects

Программный проект написан за стандартом С++11!
110 changes: 110 additions & 0 deletions headers/univeristy_sulyma.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,110 @@
#ifndef UNIVERSITY_SULYMA_MARIIA_UNIVERISTY_SULYMA_H
#define UNIVERSITY_SULYMA_MARIIA_UNIVERISTY_SULYMA_H

#include <iostream>
#include <string>

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
4 changes: 4 additions & 0 deletions output_data_recordbook.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
100
99
88
79
56 changes: 56 additions & 0 deletions src/university_sulyma.cpp
Original file line number Diff line number Diff line change
@@ -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)
{}
102 changes: 102 additions & 0 deletions tests/university_tests_sulyma.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,102 @@
#define _ERR_INVALID_INPUT 1

#include "../headers/univeristy_sulyma.h"

#include <iostream>
#include <fstream>

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);
}
}
}