1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108
|
#include <iostream>
#include<vector>
using namespace std;
//Function Prototypes
int roundDoubleToInt (double);
void sortArray(int[], int);
void display();
const int SIZE = 100; //used to limit array size
int main()
{
//Declare data objects
int numbers[SIZE] = {82, 77, 90, 89, 63, 71, 75, 86, 45,78,-1};
// sortArray(nums, 20);
double total, average;
//Definition of function display.
//Display name and lab number.
display();
//Input data
//Loops until user enters -1
cout <<"Enter test scores." << endl; //this is a priming read
do //until user enters a negative value
{
cin >> score;
do //error checking for values over 100
{
if (score > 100) //add code here for error checking
{
cout <<"you have enterered too large of a number" << endl;
}
} while (score > 100);
if (score >= 0)
{
//process valid entry
//store in array
//accumulate total
total = getTotal(numbers, SIZE)
//keep count of the number of values entered into
(i < -1 && SIZE[i] == SIZE[i+1])
}
} while (count < 100 && score >= 0);
//Calculate average score
average = total / (SIZE -1);
//Sort scores highest to lowest with bubble sort.
list = {82, 77, 90, 89, 63, 71, 75, 86, 45,78,-1};
//Pass array to sort routine for processing
//Output array in descending order and averages, totals, etc
system("pause");
return 0;
}
//sort scores descending
void sortArray(int nums[], int count)
{
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 numbs[1].
{
hold = nums[a]; //If first is bigger,
nums[a] = nums[b]; //swap the two
nums[b] = hold;
}
}
}
}
//display program information
void display()
{
cout <<"Array Lab." << endl;
cout <<"Programmed by you" <<endl;
}
//round a double to closest integer
int roundDoubleToInt(double d)
{
int result;
if (d > 0) result = (int)(d + 0.5); //result = dresult + 0.5
else result = (int)(d - 0.5); //result = deresult - 0.5
return result;
}
|