## CS 115 Lab 2 Introduction to Mathematical Operators and Test Cases (Team)

### 80 Points

Due date: Monday September 11, by the end of your lab period.

Educational goals of this lab - verify that every student can

• gotten the email addresses of the team members and send a list to the TA
• work with their teammates to finish a project
• practice with mathematical operators
• begin to understand the testing process

Preparations:

INSTRUCTIONS:

• (10 points) Team Problem #1:
• Everyone on the same team should sit together. You will be working together. Exchange email addresses so that you can communicate with your team outside of lab. One member emails your TA with a list of the students on your team and their email addresses. Make sure to include which Team number (1-6) you are!
• (70 points total) Team Problem Introduction: Converting bits to bytes and kilobytes
• The program you are creates converts bits to bytes and kilobytes. Note that this is NOT converting binary to decimal!
• The output should look exactly like:
```Enter a number of bits: 256

There are 0 kilobytes and 32 bytes and 0 bits left over in 256 bits

That is 0 * 1024 * 8 + 32 * 8 + 0 bits =  256 bits
```

Another run

```Enter a number of bits: 50000

There are 6 kilobytes and 106 bytes and 0 bits left over in 50000 bits

That is 6 * 1024 * 8 + 106 * 8 + 0 bits =  50000 bits
```

Another run

```Enter a number of bits: 350

There are 0 kilobytes and 43 bytes and 6 bits left over in 350 bits

That is 0 * 1024 * 8 + 43 * 8 + 6 bits =  350 bits
```
• (20 points) Team Problem #2: Writing Test Cases
• Figure out what goes in each of the blanks in the table below. Use a calculator as needed. Calculate these FIRST, before writing the program! Using your program to get these answers means that you have not tested your program at all! Put them into a file called testcases2.txt. Put your Section number and Team number at the top of the file. Label each answer with its letter. Your answers don't have to include the input prompts. Just give the two lines of output for each case.
DescriptionInput
(number of bits)
Expected Output
Input giving 0 kilobytes, non-zero bytes, 0 bits 1000 ___A.___
Input giving non-zero kilobytes, 0 bytes, non-zero bits16389 ___B.___
Number of bits is zero0 ___C.___
Only the number of bits left over is non-zero7 ___D.___
All results are non-zero10753___E.___
• Submit your text file with the link above. Use the Lab 2 menu choice and "Other" as the type.
• (50 points) Team Problem #3: Writing the program
• Now actually write the program that implements the conversion described above. The program needs a header with your team's information in it. That is, the Team number, the section, the names of the people on the team who are present at the lab. Also put in the purpose of the program.
• Document your steps using the design below. Copy the design below into a new py file as comments, and insert the Python code in between the design steps.

Goal: Calculate the number of kilobytes and bytes in a given number of bits. Also state the number of leftover bits. Also show the calculation done.

1. Get the needed piece of data from the user, number of bits (a whole number).
2. Calculate and store number of bytes by dividing bits by 8. (8 bits in a byte)
3. Calculate and store the leftover bits. (Hint: It's the remainder when dividing the bits by 8.)
4. Calculate and store number of kilobytes by dividing bytes by 1024. (1024 bytes in a kilobyte)
5. Calculate and store the leftover bytes.
6. Output the results as described above.
• You MUST use the // and % operators. You don't need any other arithmetic operators.
• As always, use meaningful, multi-character identifiers!
• You MUST use assignment statements for your calculations. This is because it is more efficient to store the results of your calculations and then print the results in the two different output statements instead of to calculate the same values twice, in two different output statements.
• The output should look exactly as given above.
• Run your program on your test cases to see that it does what is expected. If it does not, fix the bugs.
• Save your program with the name convert.py.
• Submit your py file with the link above. Use the Lab 2 menu choice and "Code" as the type.
• Make sure that all members of the team get a copy of the team result. Also make sure that everyone understands the team result.

## If you do not attend lab, you will NOT get the points for the Team Problem, even if your team does submit a solution!

Make sure you sign the attendance sheet.
Remember NOT to leave files on the local hard drives on University computers. campus! Make sure you save your projects onto a portable storage device you take with you!