Home >  T.A >  cs10 ( Spring 2002 ) >  Lab 4

  CS10 Sec#24,#29,#30 : Topics covered in Lab #4
T.A: Demetris Zeinalipour
(Spring 2002)
Print this Page   
 [  Academic Dishonesty Policy  ::   Lecture Notes  ::   Lecture Example  ::   Statements Table  ::   Exercise #4 ]



Academic Dishonesty Policy

You should have signed the Cheating Policy Sheet by now. If you haven't please talk to me.
Top


Problem Solving

When given a problem, one should transform the description of the problem into the solution of the problem using the following steps:
  1. Understand the problem thoroughly. Eliminate any ambiguities in the problem description.
  2. 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.
  3. 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).
  4. 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


Problem Solving Example:

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

View C++ Source Code for above Example here
Top


Statements Reference Table

Top


Lab 4 Assignment-Exercise

Write a program that determines what students need to have a letter of notification sent to them. The course is dependent on two tests. You should initially ask the user what are the maximum points for each of the two tests. Then for each student ask the user to enter both scores. You should not need to know how many students are in the class. Give the user some way to let your program know when they are finished entering student scores. As you get each set of test scores, determine if the student needs a notification letter or not and if so output what type. Students get notification letters for the following reasons:

Honors notification: Grade of 95% or higher

Warning notification: D grade

Failure notification: F grade


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.

Top