CSCI 261 - Programming Concepts - Spring 2021

A2 - Home On The Range

This assignment is due by Tuesday, February 09, 2021, 11:59 PM.
As with all assignments, this must be an individual effort and cannot be pair programmed. Any debugging assistance must be provided in accordance with the course collaboration policy.
Do not forget to complete the following labs with this set: L2A, L2B, L2C .
Do not forget to complete the APT for this set.

· Instructions · Rubric · Submission ·


Instructions: Part I - Classify The Ranges


Prompt the user to enter two ranges, each denoted by a min and a max. We'll denote the two references as [a, b] and [c, d] as long as a ≠ b and c ≠ d. Store these values as four real value measurements, i.e., your program should prompt the user to enter the four real values (which should be stored as four double variables). Once done, write code to determine each pair of real value measurements make a valid range. If yes, your program should then proceed to classify the relationship between the ranges (see hints below). If no, your program should politely terminate with an appropriate error message.

The user will first enter values a and b, then c and d. But the user is allowed to enter the pair of real values in any order; in other words, your program should not assume the first value is the smaller of the two values and that the first pair corresponds to the smaller of the two ranges.



Part I Hints


// The fabs function (defined in cmath) returns the
//   absolute value of a given floating point number.
// Thus, if the following equation is true, then we assume a == b.
//   fabs(a - b) <= TOLERANCE

Part I Test Values


Here are some known input/output values that you can test against. Be sure to try your own to verify the code works!


Inputs Classification Purpose of Test
3 4 5 6 Disjoint [3, 4] and [5, 6] have no shared values
4 3 6 5 Disjoint Values are not ordered
5 6 3 4 Disjoint Ranges are not ordered
0 2 1 3 Intersect [1, 2] is shared between the two ranges. [0, 1] and [2, 3] are unique to each range.
0 10 3 5 Subset [3, 5] is contained within [0, 10]
0 1 1 2 Extend Ranges share a common edge
-5 -3 -4 -2 Intersect Negative values
0.1 0.5 0.2 0.7 Intersect Ranges are floating point values
1 2 3 3 Not a Range Invalid range. c ≠ d fails


Instructions: Part II - Range Stats


If the result of Part I determines we do have valid ranges, then we will continue to print out some stats about our ranges. We first will want to print out the two ranges in increasing order (see hints below). Then we will print out the classification. An example is below:

Enter the first value of the first range: 5
Enter the second value of the first range: 7
Enter the first value of the second range: 6
Enter the second value of the second range: 2

Range #1: [2, 6]
Range #2: [5, 7]
Classification: Intersect

Part II Hints



Instructions: Part III - Classify a Value


Now ask the user to enter in a value x. Print out if this value is in the first range, the second range, both ranges, or neither range. Example runs of the program are shown below:

Enter the first value of the first range: 5
Enter the second value of the first range: 7
Enter the first value of the second range: 6
Enter the second value of the second range: 2

Range #1: [2, 6]
Range #2: [5, 7]
Classification: Intersect

Enter a value: 3

3 is in Range #1
Enter the first value of the first range: 5
Enter the second value of the first range: 7
Enter the first value of the second range: 6
Enter the second value of the second range: 2

Range #1: [2, 6]
Range #2: [5, 7]
Classification: Intersect

Enter a value: 6.5

6.5 is in Range #2
Enter the first value of the first range: 5
Enter the second value of the first range: 7
Enter the first value of the second range: 6
Enter the second value of the second range: 2

Range #1: [2, 6]
Range #2: [5, 7]
Classification: Intersect

Enter a value: 5

5 is in both Ranges
Enter the first value of the first range: 5
Enter the second value of the first range: 7
Enter the first value of the second range: 6
Enter the second value of the second range: 2

Range #1: [2, 6]
Range #2: [5, 7]
Classification: Intersect

Enter a value: 1

1 is in neither Range

Instructions: Part IV - Randomize The Value


Now for the tricky part. We are going to go back and edit what we did in Part III. Initially, the user was entering the value x. Instead, we need our program to generate a random real value that's within the range of the smallest and largest values represented by the two ranges. The rest of the program will then proceed as before using the randomly generated value. An example of the completed program is shown below.

Enter the first value of the first range: 5
Enter the second value of the first range: 7
Enter the first value of the second range: 6
Enter the second value of the second range: 2

Range #1: [2, 6]
Range #2: [5, 7]
Classification: Intersect

3.51363 is in Range #1
Enter the first value of the first range: 5
Enter the second value of the first range: 7
Enter the first value of the second range: 6
Enter the second value of the second range: 2

Range #1: [2, 6]
Range #2: [5, 7]
Classification: Intersect

6.55 is in Range #2
Enter the first value of the first range: 50
Enter the second value of the first range: 70
Enter the first value of the second range: 40
Enter the second value of the second range: 20

Range #1: [20, 40]
Range #2: [50, 70]
Classification: Disjoint

40.5 is in neither Range

Grading Rubric


Your submission will be graded according to the following rubric.

PointsRequirement Description
10 APT2 completed through AutoGrader.
2 All code submitted properly.
12 All labs completed and submitted.
+2 L2C Extra Credit.
5 Part IV value computed as valid random floating point value.
4 Ranges properly classified.
5 Ranges stats printed properly.
2 (1) Comments used.
(2) Coding style followed.
(3) Appropriate variable names, constants, and data types used.
(4) Instructions followed.
40 Total Points

This assignment is due by Tuesday, February 09, 2021, 11:59 PM.
As with all assignments, this must be an individual effort and cannot be pair programmed. Any debugging assistance must be provided in accordance with the course collaboration policy.
Do not forget to complete the following labs with this set: L2A, L2B, L2C .
Do not forget to complete the APT for this set.


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.

It is critical that you follow these steps when submitting homework. You can view these steps by watching the Windows / Mac video.

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.


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 Set2
    2. Inside Set2, create 4 sub-folders that are required for this Set. The name of each sub-folder is defined in that Set (e.g. L2A, L2B, L2C, and A2).
    3. Copy your files into the subdirectories ofSet2 (steps 1-2), zip this Set2 folder (steps 3-4), and then submit the zipped file (steps 5-11) to Canvas.
    4. For example, when you zip/submit Set2, there will be 4 sub-folders called L2A, L2B, L2C, and A2 inside the Set2 folder, and each of these sub-folders will have the associated files.

  2. 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?

  3. Now, for A2, right click on the main.cpp to copy the file. Then, return to the Set2/A2folder and right click to paste the file. In other words, put a copy of your homework's main.cpp source code into the Set2/A2 folder.

    Follow the same steps for L2A, to put a copy of your lab's main.cpp into the Set2/L2A folder. Repeat this process for Set2/L2B, Set2/L2C.

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

  4. Now, right-click on the "Set2" 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 Set2 folder with sub-folders that each contain a main.cpp file in it?

  5. After the previous step, you should now see a "Set2.zip" file.

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

  7. Find Set2, click on it, find the "Submit Assignment" area, and then click the "Choose File" button.

  8. Find the "Set2.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?

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

  10. No, really, make sure you click the "Submit Assignment" button to actually submit your homework. Clicking the "Choose File" 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!

  11. Canvas should say "Submitted!". Click "Submission Details" and you can download the zip file you just submitted. In other words, verify you submitted what you think you submitted!

In summary, you must zip the "Set2" folder and only the "Set2" 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 Assignment" 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 Tuesday, February 09, 2021, 11:59 PM.
As with all assignments, this must be an individual effort and cannot be pair programmed. Any debugging assistance must be provided in accordance with the course collaboration policy.
Do not forget to complete the following labs with this set: L2A, L2B, L2C .
Do not forget to complete the APT for this set.