Skip to content

Instantly share code, notes, and snippets.

@king-menin
Created September 20, 2018 05:47
Show Gist options
  • Save king-menin/35c25353ae89a51cf697f97db60ca39e to your computer and use it in GitHub Desktop.
Save king-menin/35c25353ae89a51cf697f97db60ca39e to your computer and use it in GitHub Desktop.
// structures.cpp : sem 2
//
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
// �������� ��������� 1
struct Student {
// �������� �����
std::string name;
int age;
};
void PrintStudent(const Student& student) {
std::cout << student.name << " " << student.age << std::endl;
}
// ��������� ���� ���������
void IncAge(Student *student) {
// ++(*student).age;
++student->age;
}
bool ByNameAge(const Student& left, const Student& right) {
return left.name < right.name || left.name == right.name && left.age < right.age;
}
void SortStudents(std::vector<Student>* students) {
std::sort(students->begin(), students->end(), ByNameAge);
}
int main() {
// �������� ������� ��������� 1
Student student1;
student1.name = "Anton";
student1.age = 25;
// �������� ������� ��������� 2
Student student2{"Vasya", 26};
Student student3 = {"Vasya", 26};
IncAge(&student1);
std::vector<Student> students{student1, student2, student3};
// ���������� ���������
SortStudents(&students);
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment