cse-110-lab-1

# cse-110-lab-1 - carpet(dollars per square foot Calculate...

This preview shows page 1. Sign up to view the full content.

CSE 110 Laboratory Assignment 1 You may turn your completed assignment in to your lab TA at the end of today ʼ s lab, or you may hand it in at the start of class on Monday, September 20. Be sure to include your name and lab section information (day and time) on your paper! In class, we discussed algorithms and Fowcharts. This week ʼ s lab will give you additional practice with these concepts. Part 1: Drawing Flowcharts Draw Fowcharts that describe the algorithms necessary to solve the problems that follow. Be sure to represent each individual step of the algorithm (i.e., getting a single input value) as a separate step in your Fowchart. 1. Get three data values ( x , y , and z ) as input and output the average of these values if x is positive. If the value of x is either zero or negative, your algorithm should not compute the average but should print the error message “Bad Data” instead. 2. Read in the length and width (in feet) of a rectangular carpet, along with the price of the
This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: carpet (dollars per square foot). Calculate the total cost of the carpet and print a message stating whether whether we can afford to purchase the carpet if our total budget is \$500. Part 2: Algorithm Verifcation The following algorithm multiplies two values (a and b) by adding a to itself b times: Get values for a and b If (either a = 0 or b = 0) then Set the value of product to 0 Else Set the value of count to 0 Set the value of product to 0 W h i l e ( count < b ) do Set the value of product to ( product + a ) Set the value of count to ( count + 1 ) End of loop Print the value of product Stop 1. Describe exactly what this algorithm will produce as output for each of the following two cases. State whether that output is correct or incorrect. Case 1: a = -2, b = 4 Case 2: a = 2, b = -4 2. If the algorithm produces the incorrect result for either of the two cases above, explain why it does not work correctly....
View Full Document

{[ snackBarMessage ]}

Ask a homework question - tutors are online