Explore BrainMass
Share

C++ Vector sorting program

This content was STOLEN from BrainMass.com - View the original, and get the already-completed solution here!

Directions Points
The file must be called week3-4Prog.cpp
This program will store in miniVector v a list of 15 random integers from 0 to 99, then it will output the vector, sort the vector, then output it again sorted.

Program Definition
1. Create program definition with the following templates and methods:

// output miniVector v
template <typename T>
void writeMiniVector(const miniVector<T>& v);
// use insertion sort to place miniVector v in descending order
template <typename T>
void sortMiniVector(miniVector<T>& v);

Main Method
1. Declare: miniVector<int> v;
2. Declare: randomNumber rnd;
3. call v.push_back(rnd.random(100)); to push 15 entries from 0-99 onto the vector
4. call writeMiniVector to output vector
5. call sortMiniVector to sort the vector
6. call writeMiniVector to output the sorted vector.

After you output the sorted vector:
Include: system("PAUSE"); after your output to pause the screen.

writeMiniVector Method (const miniVector<T>& v)
1. Iterate through the vector v and output each element to the screen.

sortMiniVector Method (miniVector<T>& v)
1. Sort the elements of vector v.
2. Since it is passed-by-reference, no return is necessary.

Example output of your program
Original: 59 18 60 91 49 47 83 93 55 52 15 36 83 56 91
Sorted: 93 91 91 83 83 60 59 56 55 52 49 47 36 18 15

© BrainMass Inc. brainmass.com October 25, 2018, 2:39 am ad1c9bdddf
https://brainmass.com/computer-science/cpp/c-vector-sorting-program-309752

Attachments

Solution Preview

Dear student, please find attached the C++ source file that implements required functionality. ...

Solution Summary

Attached the C++ source file for a program that will store in miniVector a list of 15 random integers from 0 to 99, then it will output the vector, sort the vector, then output it again sorted. The resulting data is displayed as:

original content:(0 96 90 63 82 28 29 66 29 94 78 63 75 7 87)
sorted content:(96 94 90 87 82 78 75 66 63 63 29 29 28 7 0)
Press any key to continue . . .

The numbers are generated randomly each time.

$2.19
See Also This Related BrainMass Solution

We have been given a file of chemical formulae, specifically hydrocarbons that consist of only hydrogen and carbon atoms.

We have been given a file of chemical formulae, specifically hydrocarbons that consist of only hydrogen and carbon atoms.

Each line of the file contains the name of the chemical followed by its molecular formula in the form C#H# where # is the number of carbon (C) and hydrogen (H) atoms. No name in the file contains blanks.

Because hydrocarbons with the same molecular formula can appear in many structural forms and each of the forms has a different name, the same molecular formula might appear more than once in the file with different names. (e.g.: Butane and 2-methylpropane both have the molecular formula C4H10.)

We would like to keep one entry for each unique molecular formula along with all the names for that formula and then display all these entries in order by ascending number of carbon atoms.

Please refer to the attachment for further details.

View Full Posting Details