Answered step by step
Verified Expert Solution
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:
- Create an empty vector of int elements.
- 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.
- Use the rand function to generate a random number whole number between 0 and RAND_MAX (using Dev-C++, RAND_MAX is 32,767).
- Convert this number into a number between 1 and 10.
- hint: use the % operator.
- 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.
- Use an iterator to insert the random number into the vector at that position.
- Go back to step 3 and perform again until the vector contains 30 random numbers
- After all 30 numbers have been generated and inserted into the vector, they should appear in descending order in the vector.
- 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
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started