Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <algorithm>
- using namespace std;
- enum Gender{male, female};
- class Man {
- protected:
- char * name;
- Gender gender;
- int age;
- public:
- Man(char *, Gender, int);
- ~Man();
- const char * getname() const;
- };
- Man :: Man(char * s, Gender f, int x) : gender(f), age(x) {
- name = new char[strlen(s) + 1];
- for (int i = 0; i <= strlen(s); ++i) name[i] = s[i];
- }
- Man :: ~Man() {
- delete [] name;
- }
- const char * Man :: getname() const {
- return name;
- }
- class Student : public Man {
- private:
- int group, mark;
- public:
- Student(char *, Gender, int, int, int);
- int getgroup() const;
- };
- Student :: Student(char * s, Gender f, int x, int y, int z) : Man(s, f, x), group(y), mark(z) {}
- int Student :: getgroup() const {
- return group;
- }
- bool cmp1(Student * a, Student * b) {
- return strcmp(a -> getname(), b -> getname()) < 0;
- }
- bool cmp2(Student * a, Student * b) {
- return a -> getgroup() < b -> getgroup();
- }
- int main(){
- int n, b, c, d;
- char s[100], g;
- setlocale(LC_ALL, ".1251");
- cout << "Введите количество студентов: ";
- cin >> n;
- Student **a = new Student * [n];
- for (int i = 0; i < n; ++i) {
- cout << "Введите фамилию, пол(M/F), возраст, номер группы и оценку " << i + 1 << "-ого студента:\n";
- cin >> s >> g >> b >> c >> d;
- a[i] = new Student(s, g == 'M' ? male : female, b, c, d);
- }
- sort(a, a + n, cmp1);
- cout << "\nСписок студентов после сортировки:\n";
- for (int i = 0; i < n; ++i)
- cout << a[i] -> getname() << endl;
- sort(a, a + n, cmp2);
- int i = 0;
- while (i < n) {
- int j = i + 1;
- while (j < n && a[j] -> getgroup() == a[i] -> getgroup()) ++j;
- cout << a[i] -> getgroup() << "-ая группа:\n";
- for (; i < j; ++i)
- cout << a[i] -> getname() << endl;
- }
- for (int i = 0; i < n; ++i) delete a[i];
- delete [] a;
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement