
|
|
[
Academic Dishonesty Policy ::
Lecture Notes ::
Lecture Example ::
Statements Table ::
Exercise #4 ]

|
You will be asked to sign the Cheating Policy Sheet so please bring a pen with you.
|
Top

|
When given a problem, one should transform the description of the problem into the solution of the problem using the following steps:
- Understand the problem thoroughly. Eliminate any ambiguities in the problem description.
- Analysis.
- Identify the inputs needed for the problem.
- Identify any special restraints or conditions of the input (Ex. range of values).
- Identify what output or outputs the problem will produce.
- Know how the output should be formatted.
- Be sure to understand any formulas given to be used in the problem.
- Design of Algorithm. An algorithm is a step-by-step set of instructions. Use pseudocode, a semiformal English-like language that shows the order of the steps to be taken in an outline type form (as opposed to a paragraph).
- Testing and Verification. Be sure that the program meets the problem requirements and the output produced is correct.
When testing:
- Use a large set of inputs, one or two inputs producing a correct output, does not guarantee that the program ALWAYS produces a correct output.
- Choose inputs that test each possible path through the program. (When using conditions, every possible result of the condition should be tested.)
- Test to make sure that the special restraints identified earlier are accounted for. Choose test input that falls inside the range, right at the edge of the range, and outside the range.
|
Top

|
Write a program that allows the user to calculate the area of a rectangle as many times as they want.
A) Input: length, width, continue/quit
B) Restrictions: inputs must be positive
C) Output: area
D) Formula: area = length * width
Pseudocode for algorithm (there are many different ways to write pseudocode, two are shown):
Pseudocode Example 1 |
Pseudocode Example 2 |
1. Ask user to input length |
1. Repeat until the user wants to stop |
2. Read in length |
2. Repeat until the length is positive |
3. If length is not positive, return to step 1 |
3. Ask user to input length |
4. Ask user to input width |
4. Read in length |
5. Read in width |
5. Repeat until the width is positive |
6. If width is not positive, return to step 4 |
6. Ask user to input width |
7. Calculate area |
7. Read in width |
8. Output area |
8. Calculate area |
9. Ask user if they want to do it again |
9. Output area |
10. Read in answer |
10. Ask user it they want to do it again |
11. If the answer is to continue, return to step 1 |
11. Read in user's response |
|
|
Selection Structure Program - make sure they have used both an
if and a
switch
|
|
Top

|
|
Top

|
Write a program that asks the user for their first name and their favorite number (1-12).
Then print all values 1-50 replacing all factors of their favorite number with their name.
For example, if their name was "Jane" and their favorite number was 4, then you would print the following.
1
2
3
Jane
5
6
7
Jane
9
10
11
Jane
13
14
15
Jane
...
Notice: Be sure to put all your information (login, lab section, …) at the top of your program. Your lab programs DO NOT get turned in electronically. I will come around and check you off individually.
|
|