fork download
  1. #include <iostream>
  2. using namespace std;
  3.  
  4. void ascendingorder(int *a, int *b, int c);
  5. int average(int *a, int b);
  6.  
  7. int main()
  8. {
  9. int SIZE;
  10.  
  11. cout << "Enter Amount of Test Scores: ";
  12. cin >> SIZE;
  13. while (SIZE <= 0)
  14. {
  15. cout << "Enter Positive Value" << endl;
  16. cout << "Enter Amount of Test Scores: ";
  17. cin >> SIZE;
  18. }
  19.  
  20. int *test = new int[SIZE];
  21. int *testnumber = new int[SIZE];
  22.  
  23. for(int count = 0; count < SIZE; count++)
  24. {
  25. cout << "Test " << (count + 1) << ": ";
  26. cin >> *(test + count);
  27. while(*(test + count) < 0)
  28. {
  29. cout << "Please Enter Positive Value." << endl;
  30. cout << "Test " << (count + 1) << ": ";
  31. cin >> *(test + count);
  32. }
  33.  
  34. *(testnumber + count) = count + 1;
  35. }
  36. cout << "\n";
  37. ascendingorder(test, testnumber, SIZE);
  38.  
  39. for(int count = 0; count < SIZE; count++)
  40. {
  41. cout << "Test " << *(testnumber + count)
  42. << ": " << *(test + count) << endl;
  43. }
  44. cout << "\n";
  45.  
  46. int averagescore = average(test, SIZE);
  47.  
  48. cout << "Average Score: " << averagescore << endl;
  49.  
  50. delete [] test;
  51. delete [] testnumber;
  52.  
  53. return 0;
  54. }
  55.  
  56. void ascendingorder(int *a, int *b, int c)
  57. {
  58. int startscan, minIndex; //Used to scan through the array
  59. int minValue; //Holds lowest value found
  60. int temp; //Temporary Position
  61. //
  62. //Initializing For Loop
  63. for (startscan = 0; startscan < (c - 1); startscan++)
  64. {
  65. minIndex = startscan; //Assigns starting position as lowest
  66. minValue = *(a + startscan); //Assigns starting number as lowest
  67. //
  68. //Searches for lowest account number value
  69. for (int index = startscan + 1; index < c; index++)
  70. {
  71. if(*(a + index) < minValue)
  72. {
  73. minValue = *(a + index); //Updates lowest number value
  74. minIndex = index; //stores position of lowest value
  75. }
  76. }
  77. //
  78. //Swaps Values
  79. *(a + minIndex) = *(a + startscan);
  80. *(a + startscan) = minValue;
  81.  
  82. temp = *(b + minIndex);
  83. *(b + minIndex) = *(b + startscan);
  84. *(b + startscan) = temp;
  85. }
  86. }
  87.  
  88. int average(int *a, int b)
  89. {
  90. int total = 0;
  91. int average;
  92. for(int count = 0; count < b; count++)
  93. {
  94. total += *(a + count);
  95. }
  96. average = total / b;
  97. return average;
  98. }
  99.  
Success #stdin #stdout 0s 544KB
stdin
Standard input is empty
stdout
Standard output is empty