This lab is due by Thursday, June 6, 2019, 11:59 PM.
As with all labs you may, and are encouraged, to pair program a solution to this lab.
Instructions
This lab will make Lab6E more useful. As before, have the user enter as
many numbers that they desire, using -1 to signify the end of input. The output at this point
should match the previous version:
Hey! Witness my first vector mojo!
Enter as many non-negative numbers as you'd like and I will tell you what they are. When you wish to be done, enter -1 to stop entering numbers.
Your Number Is: 8
Your Number Is: 6
Your Number Is: 7
Your Number Is: 9
Your Number Is: 3
Your Number Is: 2
Your Number Is: 4
Your Number Is: -1
So awesome! You entered 7 numbers.
The numbers are: 8 6 7 9 3 2 4
Have a nice day!
The smallest number is: 2
The largest number is: 9
The first number is: 8
The last number is: 4
Gaze at my awesome.
Enter as many non-negative numbers as you'd like and I will tell you what they are. When you wish to be done, enter -1 to stop entering numbers.
Your Number Is: 8
Your Number Is: 6
Your Number Is: 7
Your Number Is: 9
Your Number Is: 3
Your Number Is: 2
Your Number Is: 4
Your Number Is: -1
So awesome! You entered 7 numbers.
The numbers are: 8 6 7 9 3 2 4
Have a nice day!
The smallest number is: 2
The largest number is: 9
The first number is: 8
The last number is: 4
Gaze at my awesome.
Now for the extension Part 1. First print the values entered by the user in ascending order. Create a function called
vectorSort
that
accepts the vector passed by reference as input and has no output.
Hey! Witness my first vector mojo!
Enter as many non-negative numbers as you'd like and I will tell you what they are. When you wish to be done, enter -1 to stop entering numbers.
Your Number Is: 8
Your Number Is: 6
Your Number Is: 7
Your Number Is: 9
Your Number Is: 3
Your Number Is: 2
Your Number Is: 4
Your Number Is: -1
So awesome! You entered 7 numbers.
The numbers are: 8 6 7 9 3 2 4
Have a nice day!
The smallest number is: 2
The largest number is: 9
The first number is: 8
The last number is: 4
The numbers sorted are: 2 3 4 6 7 8 9
Gaze at my awesome.
Enter as many non-negative numbers as you'd like and I will tell you what they are. When you wish to be done, enter -1 to stop entering numbers.
Your Number Is: 8
Your Number Is: 6
Your Number Is: 7
Your Number Is: 9
Your Number Is: 3
Your Number Is: 2
Your Number Is: 4
Your Number Is: -1
So awesome! You entered 7 numbers.
The numbers are: 8 6 7 9 3 2 4
Have a nice day!
The smallest number is: 2
The largest number is: 9
The first number is: 8
The last number is: 4
The numbers sorted are: 2 3 4 6 7 8 9
Gaze at my awesome.
Then, ask the user to enter a number to check if it was previously entered. The user should be able to enter as
many numbers as they wish, again using -1 to signify they are done. Use the following output as a guide
for the desired interaction. Create a function called
binarySearch
that accepts two parameters as input,
the vector & target value, and returns a boolean as output. Be sure to use const
appropriately.
Hey! Witness my first vector mojo!
Enter as many non-negative numbers as you'd like and I will tell you what they are. When you wish to be done, enter -1 to stop entering numbers.
Your Number Is: 8
Your Number Is: 6
Your Number Is: 7
Your Number Is: 9
Your Number Is: 3
Your Number Is: 2
Your Number Is: 4
Your Number Is: -1
So awesome! You entered 7 numbers.
The numbers are: 8 6 7 9 3 2 4
Have a nice day!
The smallest number is: 2
The largest number is: 9
The first number is: 8
The last number is: 4
The numbers sorted are: 2 3 4 6 7 8 9
Enter a number to check if you previously entered it: 4
Yes you did!
Enter a number to check if you previously entered it: 62
No, sorry you didn't.
Enter a number to check if you previously entered it: -1
Gaze at my awesome.
Enter as many non-negative numbers as you'd like and I will tell you what they are. When you wish to be done, enter -1 to stop entering numbers.
Your Number Is: 8
Your Number Is: 6
Your Number Is: 7
Your Number Is: 9
Your Number Is: 3
Your Number Is: 2
Your Number Is: 4
Your Number Is: -1
So awesome! You entered 7 numbers.
The numbers are: 8 6 7 9 3 2 4
Have a nice day!
The smallest number is: 2
The largest number is: 9
The first number is: 8
The last number is: 4
The numbers sorted are: 2 3 4 6 7 8 9
Enter a number to check if you previously entered it: 4
Yes you did!
Enter a number to check if you previously entered it: 62
No, sorry you didn't.
Enter a number to check if you previously entered it: -1
Gaze at my awesome.
Functional Requirements
- Your program cannot make a call to the STL Algorithm method
sort()
. You must implement the sorting algorithm yourself. - When printing the number of numbers entered by the user, do not use a counter inside the loop. Instead, make use of one of our vector functions to determine this value.
- You must iterate through the vector again after printing all the values. You should not keep track of the smallest and largest value as the user is entering them.
- Checking for an existing value must follow binary search.
Lab Submission
You will submit your solution to this lab with the rest of Set6. Detailed instructions for doing this are posted in Assignment 6.
This lab is due by Thursday, June 6, 2019, 11:59 PM.
As with all labs you may, and are encouraged, to pair program a solution to this lab.