CS 115 Lab 2
Introduction to Math Operators and Test Cases (Individual)
Due Sunday, September 10, 2017, midnight
Educational goals of this lab - verify that every student can
- begin to understand the testing process
- write a simple program to calculate slopes
Submit your files with this link. Use the Lab 2 menu choice.
and the "Code" menu choice.
(50 points) Individual Problem:
- The program you are writing test cases for and implementing
has input of four numbers, 2 per point: x1, y1, x2, y2.
- Point coordinates can be either integer or float.
- The program calculates the slope of the line determined by those two points.
- The formula for a slope of a line with points (x1, y1) and (x2, y2) is
- (24 points) Problem #1: Complete a test plan.
|Normal line, positive slope || 1, 2, 3, 4 || A. |
|Normal line, negative slope || 9, 2, 3, 5 || B. |
|Vertical line || C. || Error, division by zero|
|Near Vertical line || D. || some very large number|
|Horizontal line|| E. || 0 |
|Near Horizontal line|| F. || some very small number |
- Calculate what A. and B. should be. Choose numbers for C., D., E. and F.
that make the test case complete. There are many sets of numbers possible!
- For D. and F. use float numbers to get the slopes to go into scientific notation.
- Put these answers as comments at the bottom of the program you write for
- (26 points) Problem #2: Write the program
- Actually write the program in Python to do what is described above.
The program needs a header and it should have documentation (comments) in the code.
The header should contain your name, section, email address (uky.edu).
State a purpose to the program at the top in a comment.
- You MUST use this design as documentation for your program.
Make the design steps comments in the Python file.
Put each Python code statement immediately after its design step comment.
1. Input a number from the user (first x)
2. Input second number from the user (first y)
3. Input third number from the user (second x)
4. Input fourth number from the user (second y)
5. Compute and print the slope using the formula given
- Your program's output should look like the sample run.
Note that there is a blank line output between the title and the
input statements and output statements.
Note that the numbers the user types in are on the SAME LINE as the input
prompt, that is, "First x: 4". Make yours do that too.
First x: 4
First y: 9
Second x: 31.5
Second y: 22
The slope is 0.4727272727272727
- Remember that ALL programs in this class MUST have a main function "def main():" and a call to main "main()" at the bottom of the file.
- Be sure to run your test cases to make sure that the program is correct.
- Save the program to a file called lab2.py.
Submit your Python file using the link above
and the menu choices Lab 2 and Code.
Log off properly - you don't want your account misused by someone else!
Remember NOT to leave files
on the local hard drives in a lab or anywhere else on
campus! Make sure you save your projects on a portable
storage device you take with you!