CS 160 - Programming Concepts and Applications

Summer II 2018 - A5 - The Power of Vectors!

Quick Links: Canvas | John Cabot | Piazza | zyBooks

|   Home |  Contact |  Syllabus |  Assignments |  Schedule |  Resources   |

This assignment is due by Thursday, July 19, 2018 11:59 PM.

· Instructions · Rubric · Submission ·


Part I - Working With Vectors



This assignment will make Lab5B more flexible. Instead of requiring the user to enter 15 numbers every time, we will allow the user to enter as many numbers as they wish (assume they will enter at least 1 number). The user will enter non-negative numbers (greater than or equal to zero) one at a time. When the user wishes to no longer enter numbers, the user should enter -1 to signal they are done.

When the user is done entering numbers, print in order:

  1. How many numbers the user entered.
  2. The numbers the user entered in order.
  3. The smallest number they entered.
  4. The largest number they entered.
  5. The first number they entered.
  6. The last number they entered.
An example interaction follows:

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.

A second interaction may look like:

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: -1
So awesome! You entered 4 numbers.
The numbers are: 8 6 7 9
Have a nice day!
The smallest number is: 6
The largest number is: 9
The first number is: 8
The last number is: 9
Gaze at my awesome.


Part II - Sorting the Vector



Now 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.


Part III - Search for a Value



Finally, 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.


Functional Requirements



  • Your program cannot make a call to the STL Algorithm method sort(). You must implement selection sort 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.


Grading Rubric


Your submission will be graded according to the following rubric.

PointsRequirement Description
2 All code submitted properly.
8 All labs completed and submitted
4 User interaction matches examples above
4 Vector information printed as demonstrated above
12 Functional requirements above met.
2 (1) Comments used
(2) Coding style followed
(3) Appropriate variable names, constants, and data types used
(4) Instructions followed
32 Total Points

This assignment is due by Thursday, July 19, 2018 11:59 PM.


Submission


Always, always, ALWAYS update the header comments at the top of your main.cpp file. And if you ever get stuck, remember that there is LOTS of help available. The following instructions are copied from How to Submit Homework.


It is critical that you follow these steps when submitting homework.

If you do not follow these instructions, your assignment will receive a major deduction. Why all the fuss? Because we have several hundred of these assignments to grade, and we use computer tools to automate as much of the process as possible. If you deviate from these instructions, our grading tools will not work. And that makes us very unhappy. And when we're unhappy, we give penalties. Thus, make us happy.


Submission Instructions



Here are step-by-step instructions for submitting your homework properly:
  1. File and folder names are extremely important in this process. Please double-check carefully, to ensure things are named correctly.
    1. The top-level folder of your project must be named Set5
    2. Inside Set5, create 5 sub-folders that are required for this Set. The name of each sub-folder is defined in that Set (e.g. L5A, L5B, L5C, L5D, and A5).
    3. Copy your program main.cpp and supporting files into the subdirectories of Set5 (steps 1-2), zip this Set5 folder (steps 3-4), and then submit the zipped file (steps 5-11) to Canvas.
    4. For example, when you zip/submit Set5, there will be 5 sub-folders called L5A, L5B, L5C, L5D, and A5 inside the Set5 folder, and each of these sub-folders will have a file called main.cpp and nothing else.

  2. You will need to download each project file(s) from Codenvy to your computer.

  3. Using Windows Explorer (not to be confused with Internet Explorer), find the file named "main.cpp" located inside the folder for the particular lab or homework assignment you will submit.

    STOP: Are you really sure you are viewing the correct assignment's folder?

  4. Now, for A5, right click on the main.cpp to copy the file. Then, return to the Set5/A5 folder and right click to paste the file. In other words, put a copy of your homework's main.cpp source code and supporting files into the Set5/A5 folder.

    Follow the same steps for L5A, to put a copy of your lab's main.cpp and supporting files into the Set5/L5A folder. Repeat this process for Set5/L5B, Set5/L5C, Set5/L5D.

    STOP: Are you sure your Set5 folder now has all your code to submit?

  5. Now, right-click on the "Set5" folder.
    1. In the pop-up menu that opens, move the mouse "Send to..." and expand the sub-menu.
    2. In the sub-menu that opens, select "Compressed (zipped) folder".

    STOP: Are you really sure you are zipping a Set5 folder with sub-folders that each contain a main.cpp file in it?

  6. After the previous step, you should now see a "Set5.zip" file.

  7. Now visit the Canvas page for this course and click the "Assignments" button in the sidebar.

  8. Find Set5, click on it, find the "Attach file" area, and then click the "Browse My Computer" button.

  9. Find the "Set5.zip" file created earlier and click the "Open" button.

    STOP: Are you really sure you are selecting the right homework assignment? Are you double-sure?

  10. WAIT! There's one more super-important step. Click on the blue "Submit" button to submit your homework.

  11. No, really, make sure you click the "Submit" button to actually submit your homework. Clicking the "Open" button in the previous step kind of makes it feel like you're done, but you must click the Submit button as well! And you must allow the file time to upload before you turn off your computer!

  12. Canvas should say "This assignment is complete. Click OK to review the results.". Click "OK" and view the files within the zip file you submitted. In other words, verify you submitted what you think you submitted!
In summary, you must zip the "Set5" folder and only the "Set5" folder, this zip folder must have several sub-folders, you must name all these folders correctly, you must submit the correct zip file for this homework, and you must click the "Submit" button. Not doing these steps is like bringing your homework to class but forgetting to hand it in. No concessions will be made for incorrectly submitted work. If you incorrectly submit your homework, we will not be able to give you full credit. And that makes us unhappy.


This assignment is due by Thursday, July 19, 2018 11:59 PM.

Last Updated: 07/05/18 16:23


Valid HTML 4.01 Strict Valid CSS! Level Triple-A conformance, W3C WAI Web Content Accessibility Guidelines 2.0