Name: ________________________________________ COMPUTER SCIENCE PROGRAM SETS 6W3
Add Text boxes to each of the problems in program set 1 (sample code) to describe the output content.
You must have at least 3 function calls for each of the 4 programs you typed.
Test yourself by writing the functions by your self without looking at the code until the process is mastered.
You will have 2 of these functions to write on your programming test tomorrow plus one other math formula.
- Write a function that finds the slope of a line given two points.
- Draw 4 lines using the 4-quadrant plane with a factor of 10:
- 2 with a positive slope 2 with a negative slope
- 2 of the lines should be perpendicular
- Plan your lines on graph paper first!
- Use that data to test the function that finds the slope of a line given two points.
1. Click on the TeachPak link and study the explanation. Then complete programs for Exercise 2.2.1 through 2.2.5.
- Use the 4-corner design recipe to help develop a solution
- Follow the design recipe in section 2.5 showing the contract, purpose and header.
Define the program Fahrenheit->Celsius, which consumes a temperature, measured in Fahrenheit and produces the Celsius equivalent. Use a chemistry or physics book to look up the conversion formula.
Test with freezing, boiling and 100 degrees.
When the function is fully developed, test it using the teachpack convert.ss applying the functions (convert-gui Fahrenheit->Celsius) and(convert-repl Fahrenheit->Celsius)
- Define the program dollar->euro, which consumes a number of dollars and produces the euro equivalent. Use the currency table in the newspaper to look up the current exchange rate.
- Define a second program that uses the currency of your origin.
- Test both using $100 and $150
- Define the program triangle. It consumes the length of a triangle's side and the perpendicular height. The program produces the area of the triangle. Use a geometry book to look up the formula for computing the area of a triangle.
- Test with 3 sets of data where side1 is between 10 and 30 pixels: 10 < side1 < 30 and side2 is between 20 and 40 pixels: 20 < side2 < 40
- ADDED: Draw three right triangles using the same data that was applied to the area program with sides parallel to the x-y axis.
- Define the program convert3. It consumes three digits, starting with the least significant digit, followed by the next most significant one, and so on.
- The program produces the corresponding number. For example, the expected value of (convert3 1 2 3) is 321.
- Use an algebra book or search Internet to find out how such a conversion works.
A typical exercise in an algebra book asks the reader to evaluate an expression like N/3 + 2 for n = 2, n = 5, and n = 9. Using Scheme, we can formulate such an expression as a program and use the program as many times as necessary. Here is the program that corresponds to the above expression: (define (f n)
(+ (/ n 3) 2))
First determine the result of the expression at n = 2, n = 5, and n = 9 by hand, then with DrScheme's stepper.
Next, formulate the following three expressions as programs:
- n2 + 10
- (1/2) · n2 + 20
Determine their results for n = 2 and n = 9 by hand and with DrScheme.
- Draw some more shapes and write functions to calculate the area and perimeter of those shapes; for example, a parallelogram, a trapezoid.
- Write a function that draws a ring that consumes the inner and outer radius.
SEMESTER PORTFOLIO WEB PAGE
- Type up the Program at a Glance Chart in section 2.5.
- Add your own examples and rules similar to my web page.
- Turn your content into a well designed organized web page showing mastery of Chapter 2 content.
- Add graphics you have completed in your programs.
- Add correlation to concepts in Algebra