Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- using namespace std;
- int main()
- {
- cout << "This program sorts the marks of a student in a certain way.\n";
- bool isIncorrect;
- int* arr, n, i, n1, lastPos, helpVariable, mark;
- cout << "Input a number of marks\n";
- do {
- isIncorrect = true;
- cin >> n;
- if (cin.fail() || (cin.get() != '\n'))
- {
- cout << "Error! Input a number" << endl;
- cin.clear();
- while (cin.get() != '\n');
- }
- else
- {
- cin.clear();
- if (n > 0)
- {
- isIncorrect = false;
- }
- else
- {
- cout << "Error! Input a number greater than 0" << endl;
- }
- }
- } while (isIncorrect);
- arr = new int[n];
- cout << "Input all of the marks.!\n";
- n1 = n + 1;
- for (i = 0; i < n; i++)
- {
- do {
- isIncorrect = true;
- cin >> arr[i];
- if (cin.fail() || (cin.get() != '\n'))
- {
- cout << "Error! Input a number" << endl;
- cin.clear();
- while (cin.get() != '\n');
- }
- else
- {
- cin.clear();
- if (arr[i] < 0 || arr[i] > 10)
- {
- isIncorrect = false;
- }
- else
- {
- cout << "Error! Input a number ftom 0 to 10" << endl;
- }
- }
- } while (isIncorrect);
- }
- mark = 10;
- lastPos = 0;
- while (mark > 4)
- {
- for (i = lastPos; i < n1; i++)
- if (arr[i] == mark)
- {
- helpVariable = arr[lastPos];
- arr[lastPos] = arr[i];
- arr[i] = helpVariable;
- lastPos++;
- }
- mark = mark - 2;
- }
- cout << "Here are the sorted marks:\n";
- for (i = 0; i < n; i++)
- {
- cout << arr[i]<< " ";
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement