Advertisement
lithie_oce

Untitled

Oct 24th, 2023
24
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.50 KB | None | 0 0
  1. #include <iostream>
  2.  
  3. using namespace std;
  4.  
  5. int main()
  6. {
  7. cout << "This program sorts the marks of a student in a certain way.\n";
  8. bool isIncorrect;
  9. int* arr, n, i, n1, lastPos, helpVariable, mark;
  10. cout << "Input a number of marks\n";
  11. do {
  12. isIncorrect = true;
  13. cin >> n;
  14. if (cin.fail() || (cin.get() != '\n'))
  15. {
  16. cout << "Error! Input a number" << endl;
  17. cin.clear();
  18. while (cin.get() != '\n');
  19. }
  20. else
  21. {
  22. cin.clear();
  23. if (n > 0)
  24. {
  25. isIncorrect = false;
  26. }
  27. else
  28. {
  29. cout << "Error! Input a number greater than 0" << endl;
  30. }
  31. }
  32.  
  33. } while (isIncorrect);
  34. arr = new int[n];
  35. cout << "Input all of the marks.!\n";
  36. n1 = n + 1;
  37. for (i = 0; i < n; i++)
  38. {
  39. do {
  40. isIncorrect = true;
  41. cin >> arr[i];
  42. if (cin.fail() || (cin.get() != '\n'))
  43. {
  44. cout << "Error! Input a number" << endl;
  45. cin.clear();
  46. while (cin.get() != '\n');
  47. }
  48. else
  49. {
  50. cin.clear();
  51. if (arr[i] < 0 || arr[i] > 10)
  52. {
  53. isIncorrect = false;
  54. }
  55. else
  56. {
  57. cout << "Error! Input a number ftom 0 to 10" << endl;
  58. }
  59. }
  60.  
  61. } while (isIncorrect);
  62. }
  63. mark = 10;
  64. lastPos = 0;
  65. while (mark > 4)
  66. {
  67. for (i = lastPos; i < n1; i++)
  68. if (arr[i] == mark)
  69. {
  70. helpVariable = arr[lastPos];
  71. arr[lastPos] = arr[i];
  72. arr[i] = helpVariable;
  73. lastPos++;
  74. }
  75. mark = mark - 2;
  76. }
  77. cout << "Here are the sorted marks:\n";
  78. for (i = 0; i < n; i++)
  79. {
  80. cout << arr[i]<< " ";
  81. }
  82. return 0;
  83. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement