-
-
Save copleykj/8f4e5f46673cdfe1c4b2e7b94502fffe to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/*This program is intended to help you refresh your memory with programming in C++ and consists only of concepts from 146. | |
Write a program that reads the appropriate number of integers into an array, and sorts these numbers in reverse order | |
(decreasing order). The data will consist of 3 sets of data (Please use a loop instead of running the program 3 times). | |
Each set of data begins with an integer that indicates the number of integers on the next newline that are to be read | |
and sorted. So, unnecessary (i.e., to be ignored-not sorted)numbers may exist in the data. | |
The 3rd and 5th will be set up like the 1st. Likewise, the 4th and 6th will be set up like the 2nd. | |
Requirements: | |
Function to print the array of numbers; pass be value must be used | |
Function to sort the numbers in reverse order; pass by reference must be used | |
An array must be used; assume the maximum number of elements to be 100. | |
Extraneous numbers are to be ignored*/ | |
#include <iostream> | |
#include <string> | |
using namespace std; | |
void Sort(double list[], int Size) | |
{ | |
double tempHolder; | |
for (int i = 0; i < Size; ++i) | |
{ | |
for (int j = i + 1; j < Size; ++j) | |
{ | |
if (list[i] < list[j]) | |
{ | |
tempHolder = list[i]; | |
list[i] = list[j]; | |
list[j] = tempHolder; | |
} | |
} | |
} | |
} | |
int main() | |
{ | |
const int size = 6; | |
double list[size] = {1,9,4.5,6.6,5.7,-4.5}; | |
Sort(list, size); | |
cout << "The sorted values are:" << endl; | |
for (int i = 0; i < size; ++i) | |
{ | |
cout << list[i] << endl; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment