Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

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

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Students also viewed these Databases questions