Question: Project 1 - Use a vector to sort numbers (10 points) The purpose of this project is to generate thirty random whole numbers between 1

Project 1 - Use a vector to sort numbers (10 points)

The purpose of this project is to generate thirty random whole numbers between 1 and 10, insert them into a vector in descending order, then and print the numbers in ascending order:

Use the following plan of attack:

  1. Create an empty vector of int elements.
  2. Use the srand function to change the "seed" for generating random numbers, meaning that the rand function will generate a different set of random numbers every time your program is run.
  3. Use the rand function to generate a random number whole number between 0 and RAND_MAX (using Dev-C++, RAND_MAX is 32,767).
  4. Convert this number into a number between 1 and 10.
    • hint: use the % operator.
  5. Use a loop to scan the vector until you find the position of an element containing a number that is less than the random number just generated above.
  6. Use an iterator to insert the random number into the vector at that position.
  7. Go back to step 3 and perform again until the vector contains 30 random numbers
  8. After all 30 numbers have been generated and inserted into the vector, they should appear in descending order in the vector.
  9. Use the pop_back function in a loop to print the numbers in ascending order on the console until the vector is empty.

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!