├── README.md └── main.cpp /README.md: -------------------------------------------------------------------------------- 1 | # CryptoTracker-9180 2 | A cool open-source project 3 | -------------------------------------------------------------------------------- /main.cpp: -------------------------------------------------------------------------------- 1 | Я вам надам основний код для обробки даних в C++, де створюється простий клас "Student" з деякими полями, демонструються основні операції обробки даних. 2 | 3 | ```cpp 4 | #include 5 | #include 6 | #include 7 | #include 8 | 9 | class Student { 10 | public: 11 | std::string name; 12 | int age; 13 | double grade; 14 | 15 | Student(const std::string &name, int age, double grade) { 16 | this->name = name; 17 | this->age = age; 18 | this->grade = grade; 19 | } 20 | }; 21 | 22 | bool compare_grades(const Student &s1, const Student &s2) { 23 | return s1.grade < s2.grade; 24 | } 25 | 26 | bool compare_age(const Student &s1, const Student &s2) { 27 | return s1.age < s2.age; 28 | } 29 | 30 | int main() { 31 | std::vector students; 32 | students.push_back(Student("John", 20, 90.5)); 33 | students.push_back(Student("Alice", 22, 85.1)); 34 | students.push_back(Student("Bob", 21, 92.3)); 35 | students.push_back(Student("Charlie", 19, 88.9)); 36 | 37 | std::cout << "Original list:" << std::endl; 38 | for (Student &student : students) { 39 | std::cout << student.name << " is " << student.age << " years old with a grade of " << student.grade << std::endl; 40 | } 41 | 42 | std::sort(students.begin(), students.end(), compare_grades); 43 | 44 | std::cout << "\nList sorted by grade:" << std::endl; 45 | for (Student &student : students) { 46 | std::cout << student.name << " is " << student.age << " years old with a grade of " << student.grade << std::endl; 47 | } 48 | 49 | std::sort(students.begin(), students.end(), compare_age); 50 | 51 | std::cout << "\nList sorted by age:" << std::endl; 52 | for (Student &student : students) { 53 | std::cout << student.name << " is " << student.age << " years old with a grade of " << student.grade << std::endl; 54 | } 55 | 56 | return 0; 57 | } 58 | ``` 59 | 60 | Цей код створює простий клас `Student`, додавати студентів до вектора, сортує вектор за оцінками та віком, а потім виводить відсортований список. --------------------------------------------------------------------------------