fork download
  1. #include <iostream>
  2. #include <list>
  3. #include <string>
  4. using namespace std;
  5.  
  6. struct Student {
  7. string lastname;
  8. int course;
  9. int mathAn;
  10. int mathAl;
  11. };
  12.  
  13. void printList( list<Student> lst) {
  14. for (list<Student>::iterator it = lst.begin(); it != lst.end(); it++)
  15. {
  16. cout << (*it).lastname <<" " << (*it).course << " " << (*it).mathAn << " "<< (*it).mathAl << endl;
  17. }
  18. }
  19.  
  20. bool compare (const Student& first, const Student& second) {
  21. return first.lastname < second.lastname;
  22. }
  23.  
  24. bool compare_course (const Student& first, const Student& second) {
  25. return first.course < second.course;
  26. }
  27. bool digit (const Student& value) { return (value.mathAn < 60 || value.mathAl < 60); }
  28. int main() {
  29. Student student1;
  30. list<Student> students;
  31. for( int i = 3; i > 0; i--) {
  32. cout << "Enter student lastname: ";
  33. cin >> student1.lastname;
  34. cout << "Enter student course: ";
  35. cin >> student1.course;
  36. cout << "Enter student mathAn: ";
  37. cin >> student1.mathAn;
  38. cout << "Enter student mathAl: ";
  39. cin >> student1.mathAl;
  40. students.push_back(student1);
  41. }
  42. printList(students);
  43. students.sort(compare);
  44. printList(students);
  45. students.sort(compare_course);
  46. printList(students);
  47.  
  48. for (list<Student>::iterator it = students.begin(); it != students.end(); it++)
  49. {
  50. if((*it).mathAn > 60 && (*it).mathAl > 60){
  51. (*it).course++;
  52. }
  53. }
  54. printList(students);
  55.  
  56. for (list<Student>::iterator it = students.begin(); it != students.end(); it++)
  57. {
  58. if((*it).mathAn > 60 && (*it).mathAl > 60){
  59. (*it).course++;
  60. }
  61. }
  62. printList(students);
  63. students.remove_if(digit);
  64. cout << "After remove students with mathAn < 60 or mathAl < 60: " << endl;
  65. printList(students);
  66. return 0;
  67. }
Success #stdin #stdout 0.01s 5288KB
stdin
fdjfjhdjk 3 64 58
jhff 5 67 98
fijdijf 4 56 55
stdout
Enter student lastname: Enter student course: Enter student mathAn: Enter student mathAl: Enter student lastname: Enter student course: Enter student mathAn: Enter student mathAl: Enter student lastname: Enter student course: Enter student mathAn: Enter student mathAl: fdjfjhdjk 3 64 58
jhff 5 67 98
fijdijf 4 56 55
fdjfjhdjk 3 64 58
fijdijf 4 56 55
jhff 5 67 98
fdjfjhdjk 3 64 58
fijdijf 4 56 55
jhff 5 67 98
fdjfjhdjk 3 64 58
fijdijf 4 56 55
jhff 6 67 98
fdjfjhdjk 3 64 58
fijdijf 4 56 55
jhff 7 67 98
After remove students with mathAn < 60 or mathAl < 60: 
jhff 7 67 98