Arrays Lab 

Project - Test Scores
Project will have three functions: main, round, sort_Array

  1. Declare an array to store a maximum of 100 integer test scores.
  2. Use a loop to permit operator entry of the scores into the array.
  3. Scores will be positive, so use a negative number as a sentinel.
  4. Display the following information:
    1. The test scores in descending order - (sort the array using a modification of bubble sort function below)
    2. The total of all test scores.
    3. The average score rounded to the nearest whole number.

    4. (Code a generic function to receive a double and return the nearest integer - for use here and in future)
Test Data:
82, 77, 90, 89, 63, 71, 75, 86, 45, 78, -1

Submit:
Source code
Drawings of array with subscripts (before & after sorting)
Output and Proofs of calculations

Bubble Sort Function - Ascending Order

 Prototype: void sortArray(int[ ], int);
 Call: sortArray(nums, 20);    // pass array of 20 ints
 Implementation:
 void sortArray(intnums[],int count) //store array addr & size
 {
   int hold, a, b;               // a and b are subscripts
   for(a = 0; a < count-1; a++)  //start first loop with 0
   {
     for(b = a+1; b < count; b++) //start second loop with 1
     {
       if(nums[a] > nums[b])     //compare nums[0] to nums[1]
       {
         hold = nums[a];        // if first is bigger
         nums[a] = nums[b];     // swap the two
         nums[b] = hold;
       }
     }
   }
 }


Return to TOP

! You are using a version 4 browser or older. If you are experiencing any problems with scrolling, please reload the page.