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
|
//Aidan Satterwhite
//Assignment 1
#include <iostream>
using namespace std;
void input(int ulist[30], int& n);
void Bubblesort(int ulist[30], int slist[30], int n);
void print(int list[30], int n);
void minMaxRange(int ulist[30], int n);
double average;
int n, sum;
void main(){
int ulist[30], slist[30];
input(ulist, n);
print(ulist, n);
Bubblesort(ulist, slist, n);
print(slist, n);
minMaxRange(ulist, n);
cin >> n;
}
void input(int ulist[30], int& n){
int i(0), value;
cout << "Enter value: " << endl;
cin >> value;
while (i < 29 && value != -999){
i++;
ulist[i] = value;
if (i < 29){
cin >> value;
}
}
n = i;
}
void Bubblesort(int ulist[30], int slist[30], int n){
int i, j, temp;
for (i = 1; i <= n; i++){
slist[i] = ulist[i];
}
for (j = 1; j <= n; j++){
for (i = 1; i <= n; i++){
if (slist[i] > slist[i + 1]){
temp = slist[i];
slist[i] = slist[i + 1];
slist[i + 1] = temp;
}
}
}
}
void print(int list[30], int n){
int i;
sum = 0;
cout << "Unsorted list of numbers: ";
for (i = 1; i <= n; i++){
cout << list[i] << " ";
sum = sum + list[i];
}
average = sum / n;
cout << endl;
cout << "Average: " << average << endl;
}
void minMaxRange(int ulist[30], int n){
int i, max = ulist[0], min = ulist[0], range;
for (i = 1; i <= n; i++){
if (ulist[i] < min){
ulist[i] = min;
}
if (ulist[i] > max){
ulist[i] = max;
}
}
range = max - min;
cout << "Largest number: " << max << endl;
cout << "Smallest number: " << min << endl;
cout << "Range: " << range << endl;
}
|