Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <fstream>
- #include <map>
- #include <ctime>
- #include <string>
- #include <stdlib.h>
- #include <vector>
- #include <list>
- #include <iterator>
- #include <algorithm>
- #include <utility>
- #include <Windows.h>
- #include <tchar.h>
- using namespace std;
- class CPerson
- {
- private:
- string name;
- string EGN;
- public:
- CPerson()
- {
- name = " ";
- EGN = " ";
- }
- CPerson(const string n, const string e)
- {
- name = n;
- EGN = e;
- }
- string getname()const
- {
- return name;
- }
- string getEGN()const
- {
- return EGN;
- }
- void setname(const string n)
- {
- name = n;
- }
- void setEGN(const string e)
- {
- EGN = e;
- }
- virtual void print() = 0; //1.1
- /*
- int getAge() const //1.2
- {
- int age;
- struct tm buf;
- time_t now = time(0);
- tm *ltm = localtime_s(&now,&buf);
- int year = atoi(getEGN().substr(0, 2).c_str());
- int month = atoi(getEGN().substr(2, 2).c_str());
- int day = atoi(getEGN().substr(4, 2).c_str());
- int cyear = 1900 + ltm->tm_year;
- int cmonth = 1 + ltm->tm_mon;
- int cday = 1 + ltm->tm_mday;
- age = cyear - (year + 1900);
- if (cmonth < month)
- age--;
- if (cmonth == month && cday < day)
- age--;
- return age;
- }
- */
- int getAge() const //1.2
- {
- int age;
- time_t now = time(0);
- tm *ltm = localtime(&now);
- int year = atoi(getEGN().substr(0, 2).c_str());
- int month = atoi(getEGN().substr(2, 2).c_str());
- int day = atoi(getEGN().substr(4, 2).c_str());
- int cyear = 1900 + ltm->tm_year;
- int cmonth = 1 + ltm->tm_mon;
- int cday = 1 + ltm->tm_mday;
- age = cyear - (year + 1900);
- if (cmonth < month)
- age--;
- if (cmonth == month && cday < day)
- age--;
- return age;
- }
- /*
- SYSTEMTIME time;
- while (true)
- {
- GetLocalTime(&time);
- }
- return 0;
- */
- };
- class CStudent : public CPerson
- {
- private:
- string FN;
- map<int, int> st_tests;
- public:
- CStudent()
- {
- FN = " ";
- }
- CStudent(const string n)
- {
- FN = n;
- }
- CStudent(const string o, const string p, const string n) :CPerson(o, p)
- {
- FN = n;
- }
- void setFN(const string n)
- {
- FN = n;
- }
- void setst_tests(map<int, int> m)
- {
- st_tests = m;
- }
- string getFN() const
- {
- return FN;
- }
- bool operator () (CStudent a, CStudent b) const
- {
- return a.average() < b.average();
- }
- map<int, int> getst_tests()
- {
- return st_tests;
- }
- void print()
- {
- cout << "Ime: " << getname() << endl;
- cout << "EGN: " << getEGN() << endl;
- cout << "FN: " << getFN() << endl;
- auto it = st_tests.begin();
- while (it != st_tests.end())
- {
- cout << it->first << " " << it->second << endl;
- it++;
- }
- }
- void add_st_tests(int a, int b)
- {
- st_tests.insert(pair<int, int>(a, b));
- }
- double average() //2.1
- {
- double sum = 0;
- auto it = st_tests.begin();
- for (it = st_tests.begin(); it != st_tests.end(); it++)
- sum += it->second;
- if (st_tests.size() != 0)
- return sum / st_tests.size();
- return -1;
- }
- int search(const int a) //2.2
- {
- return st_tests.find(a)->second;
- }
- };
- class CSpeciality
- {
- private:
- string spec;
- int kurs;
- int grupa;
- vector<CStudent> students;
- public:
- string getspec() const
- {
- return spec;
- }
- int getkurs() const
- {
- return kurs;
- }
- int getgrupa() const
- {
- return grupa;
- }
- vector<CStudent> getstudents()
- {
- return students;
- }
- void setstudents(vector<CStudent> a)
- {
- students = a;
- }
- void setspec(const string n)
- {
- spec = n;
- }
- void setkurs(const int n)
- {
- kurs = n;
- }
- void setgrupa(const int n)
- {
- grupa = n;
- }
- CSpeciality(const string s, const int k, const int g)
- {
- spec = s;
- kurs = k;
- grupa = g;
- }
- void addstudent(CStudent &a)
- {
- students.push_back(a);
- }
- /* int ReadFile() //3.1
- {
- ifstream st;
- st.open("students.txt",ios::in);
- if(!st)
- {
- cout<<"Cannot open students.txt or file does not exist."<<endl;
- return 0;
- }
- string a, b, c;
- int d, e, i=0;
- if (st.is_open())
- {
- do
- {
- st >> a >> b >> c;
- students[i].setname(a);
- students[i].setEGN(b);
- students[i].setFN(c);
- do
- {
- st >> d >> e;
- students[i].add_st_tests(d,e);
- }while(st.peek() != '\n' || st.peek() != '\r');
- i++;
- }while(!st.eof());
- }
- st.close();
- }*/
- double averagetest(int a) //3.2
- {
- double sum = 0;
- int br = 0;
- vector<CStudent>::iterator itt;
- for (itt = students.begin(); itt != students.end(); itt++)
- {
- map<int, int>::iterator it = (*itt).getst_tests().find(a);
- while (itt != students.end())
- sum += it->second;
- br++;
- }
- cout << sum / br;
- return sum / br;
- }
- list<CStudent> averageparam(const int a, const int b) //3.3
- {
- list<CStudent> l;
- int i = 0;
- vector<CStudent>::iterator itt = students.begin();
- for (itt = students.begin(); itt != students.end(); itt++)
- {
- if ((*itt).average() >= a && (*itt).average() <= b)
- l.push_back(*itt);
- i++;
- }
- cout << "List ot studenti sus sreden broi tochki mejdu " << a << " - " << b << endl;
- list<CStudent>::iterator it = l.begin();
- for (it = l.begin(); it != l.end(); it++)
- (*it).print();
- return l;
- }
- int averageabove(const int a) //3.4
- {
- int br = 0;
- vector<CStudent>::iterator itt = students.begin();
- for (itt = students.begin(); itt != students.end(); itt++)
- if ((*itt).average() > a)
- br++;
- cout << "Broi studenti sus sreden broi tochki nad " << a << ": " << br << endl;
- return br;
- }
- /*
- void averageage(const int a) //3.5
- {
- cout << "Sreden uspeh na " << a << " godishni studenti." << endl;
- vector<CStudent>::iterator itt = students.begin();
- for (itt = students.begin(); itt != students.end(); itt++)
- {
- int b = (*itt).getAge();
- if (a == b)
- cout << (*itt).getname() << " " << (*itt).average() << endl;
- }
- }
- */
- void beststudent() //3.6
- {
- cout << "Student s nai-visoka uspevaemost." << endl;
- CStudent temp;
- vector<CStudent>::iterator itt = students.begin();
- for (itt = students.begin(); itt != students.end(); itt++)
- if ((*itt).average() > temp.average())
- temp = (*itt);
- temp.print();
- }
- void sortaverage() //3.7
- {
- sort(students.begin(), students.end(), CStudent());
- }
- /*
- bool compare(CStudent &a, CStudent &b)
- {
- return a.average() < b.average();
- }
- void sortaverage() //3.7
- {
- sort(students.begin(), students.end(), compare);
- }
- */
- };
- int main()
- {
- CStudent p1("Ivan", "9711156070", "61360140");
- CStudent p2("Petar", "9703041020", "61360127");
- CStudent p3("Mihail", "9708032540", "61360134");
- p1.add_st_tests(1, 55);
- p1.add_st_tests(2, 80);
- p1.add_st_tests(3, 69);
- p2.add_st_tests(1, 9);
- p2.add_st_tests(2, 25);
- p2.add_st_tests(3, 56);
- p3.add_st_tests(1, 32);
- p3.add_st_tests(2, 87);
- p3.add_st_tests(3, 57);
- CSpeciality g1("SIT", 1, 1);
- g1.addstudent(p1);
- g1.addstudent(p2);
- g1.addstudent(p3);
- g1.averagetest(2);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement