.


:




:

































 

 

 

 


1

 

1. .

2. .

3. .

4. .

5. .

6. .

7. .

8. .

 

, ,

, . , ++ ( c Qt).

 

 

:

;

( );

;

;

, .

 

, , . . .

5.

. STL

 

: STL.

 

, 3. STL list vector.

- .

UML.

1 , Student, - (Stud_Sport), (Group_stud). (Group_stud) Stud_Sport. Group_stud : add_st(Student* st1) ; stud_max_grade() ; diskOut() Stud_Sport ; showData() , ; del_obj() . main() .

 

Qt Creator 3.0.0 ( Qt 5.2.0). 1 .

 

 

1

 

Qt Creator: -> -> Qt -> ++.

: -> -> ++ -> ++.

, : -> .

2 .

 

1

 

// student.h

 

#define STUDENT_H

#include <string>

using namespace std;

 

class ErrorStud

{ public:

string message; //

ErrorStud(const string& s): message(s) {}

};

 

class Student

{ protected:

string fam;

string name;

int grade;

public:

Student();

Student(string fam1, string name1, int grade1);

~Student(){}

 

string getfam();

string getname();

int getgrade();

void setfam(string fam1);

void setname(string name1);

void setgrade(int grade1);

};

 

#endif // STUDENT_H

// student.cpp

 

#include "student.h"

#include <iostream>

using namespace std;

 

Student::Student()

{ fam = "";

name = "";

grade = 0;

}

Student::Student(string fam1, string name1, int grade1)

{ fam = fam1;

name = name1;

if (grade1 <0 ||grade1 >100) throw ErrorStud(" 0 100!");

else grade = grade1;

}

string Student::getfam() { return fam;}

string Student::getname(){ return name;}

int Student::getgrade(){ return grade;}

void Student::setfam(string fam1){ fam = fam1;}

void Student::setname(string name1){name = name1;}

void Student::setgrade(int grade1){grade = grade1;}

// stud_sport.h

#ifndef STUD_SPORT_H

#define STUD_SPORT_H

#include "student.h"

 

class Stud_Sport: public Student

{ string vid_sporta;

public:

string getvid_sporta();

void setvid_sporta(string vid_sporta1);

Stud_Sport();

Stud_Sport(string fam1, string name1, int grade1, string vid_sporta1);

~ Stud_Sport() {}

void display();

};

 

#endif // STUD_SPORT_H

// stud_sport.cpp

#include "stud_sport.h"

#include <iostream>

using namespace std;

 

Stud_Sport::Stud_Sport():Student(){vid_sporta = "";}

Stud_Sport::Stud_Sport(string fam1, string name1, int grade1, string vid_sporta1): Student(fam1,name1,grade1)

{ vid_sporta = vid_sporta1;}

string Stud_Sport::getvid_sporta() {return vid_sporta;}

void Stud_Sport::setvid_sporta(string vid_sporta1){vid_sporta = vid_sporta1;}

 

void Stud_Sport::display()

{

cout << " \n: " << fam;

cout << " : " << name;

cout << " : " << grade;

cout << " : " << vid_sporta;

}

// group_stud.h

#ifndef GROUP_STUD_H

#define GROUP_STUD_H

#include "stud_sport.h"

#include <list>

#include <string>

using namespace std;

 

class Group_stud

{ string name_gr;

list <Stud_Sport*> st;

public:

Group_stud();

string getname();

void setname(const string name_gr1);

void add_st(Stud_Sport *st1);

void stud_max_grade();

void diskOut();

void showData();

void del_obj();

};

 

#endif // GROUP_STUD_H

// group_stud.cpp

#include "group_stud.h"

#include <iostream>

#include <fstream>

using namespace std;

 

bool compare_fam(Stud_Sport* st1, Stud_Sport* st2)

{

return st1->getfam() < st2->getfam();

}

 

Group_stud::Group_stud(){ name_gr = "";}

 

string Group_stud::getname(){ return name_gr;}

void Group_stud::setname(const string name_gr1){name_gr = name_gr1;}

 

void Group_stud::add_st(Stud_Sport* st1)

{

st.push_back(st1);

}

 

void Group_stud::stud_max_grade()

{ list <Stud_Sport*>::iterator itr;

itr = st.begin();

int max = (*itr)->getgrade();

for(itr = st.begin(); itr!= st.end(); ++itr)

if ((*itr)->getgrade() > max) max = (*itr)->getgrade();

cout << "\n " << name_gr;

cout << "\n : \n";

for(itr = st.begin(); itr!= st.end(); ++itr)

if ((*itr)->getgrade() == max)

(*itr)->display();

}

 

void Group_stud::diskOut()

{ ofstream fout("C:\\1.txt");

fout << st.size() << endl;

//for (int i = 0; i < n; i++)

list <Stud_Sport*>::iterator itr;

for(itr = st.begin(); itr!= st.end(); ++itr)

{ fout << (*itr)->getfam() << endl;

fout << (*itr)->getname() << endl;

fout << (*itr)->getgrade() << endl;

fout << (*itr)->getvid_sporta() << endl;

}

fout.close();

}

 

void Group_stud::showData()

{ st.sort(compare_fam);

list <Stud_Sport*>::iterator itr;

cout << "\n " << name_gr;

cout << "\n -: \n";

for(itr = st.begin(); itr!= st.end(); ++itr)

(*itr)->display();

}

 

void Group_stud::del_obj()

{ int fl = 0;

string fam;

cout << "\nInput fam for del: "; cin >> fam;

list <Stud_Sport*>::iterator itr;

for(itr = st.begin(); itr!= st.end();++itr)

if ((*itr)->getfam() == fam)

{st.erase(itr);fl = 1; break;}

if (fl == 0) cout << "\n ! \n";

}

// main.cpp

#include "student.h"

#include "stud_sport.h"

#include "group_stud.h"

#include <iostream>

#include <fstream>

#include <list>

using namespace std;

 

 

void vvod2(string &fam2,string &name2, int &grade2, string &vid_sporta2)

{ cout << ": "; cin >> fam2;

cout << ": "; cin >> name2;

cout << ": "; cin >> grade2;

cout << " : "; cin >> vid_sporta2;

}

 

int main()

{ int pr;

string fam2, name2, vid_sporta2;

int grade2;

int nMenu;

int m;

Group_stud gr;

string name_gr1;

cout << "\n :"; cin >> name_gr1;

gr.setname(name_gr1);

Stud_Sport *st;

list <Stud_Sport*> spisok;

 

//

cout << "\n: " << endl;

cout << "\n1 - ";

cout << "\n2 - ";

cout << "\n>";

cin >> nMenu;

 

try { switch (nMenu)

{ case 1: cout << "\n :\n";

do

{ vvod2(fam2, name2, grade2,vid_sporta2);

st = new Stud_Sport(fam2, name2, grade2,vid_sporta2);

spisok.push_back(st);

gr.add_st(st);

cout << "\n ? 1- , 0 - " << endl;

cin >> pr;

}while(pr == 1);

gr.diskOut();

gr.showData();

break;

case 2:

ifstream fin("C:\\1.txt");

fin >> m; fin.get();

for (int i = 0; i < m; i++)

{ getline(fin, fam2);

getline(fin, name2);

fin >> grade2; fin.get();

getline(fin, vid_sporta2);

st = new Stud_Sport(fam2, name2, grade2,vid_sporta2);

spisok.push_back(st);

gr.add_st(st);

}

gr.showData();

break;

}

 

gr.stud_max_grade();

gr.del_obj();

gr.showData();

//gr.diskOut();

 

list <Stud_Sport*>::iterator itr;

for(itr = spisok.begin(); itr!= spisok.end(); ++itr)

delete (*itr);

spisok.clear();

}

catch(const ErrorStud& e)

{ cout << e.message << endl;}

return 0;

}

 

 

 

 

2

 



<== | ==>
| 
:


: 2015-09-20; !; : 443 |


:

:

, .
==> ...

1640 - | 1505 -


© 2015-2024 lektsii.org - -

: 0.251 .