1 / 34

Computational Tools Structured Programming Spreadsheets

Computational Tools Structured Programming Spreadsheets. Structured Programming Flowcharts Flow control Functions. Flowchart Symbols. Start/Stop. Operation. Decision. Input/Output. Example Flowchart. start. read x. y = f(x). yes. y > 4?. y = 4. no. print y. end.

alice
Download Presentation

Computational Tools Structured Programming Spreadsheets

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. Computational Tools • Structured Programming • Spreadsheets Computational Tools

  2. Structured Programming • Flowcharts • Flow control • Functions Computational Tools

  3. Flowchart Symbols Start/Stop • Operation • Decision • Input/Output Computational Tools

  4. Example Flowchart start read x y = f(x) yes y > 4? y = 4 no print y end Computational Tools

  5. Flowchart with Iteration start sum = 0 n = 0 n = n + 1 sum = sum + n n=5? no yes print sum end Computational Tools

  6. When the program represented by the following flowchart is run, what is the resulting sum? 10 15 20 21 start sum = 0 n = 0 n = n + 1 sum = sum + n n=5? no yes print sum sum = 15 B end Computational Tools

  7. Structured Programming • Flowcharts • Flow control • Functions Computational Tools

  8. In this program, if a value of 0.5 is read for x, what value is assigned to y? read x if x < 0 then y = 0 else if x > 1 then y = 1 else y = x*x end 0.25 0.5 0.75 1 A Computational Tools

  9. In this program, what is the final value of x? x = 1 y = 2*x x = x + y*y if x > 4 then x = x/5 1 5 6 8 x = 1 y = 2 x = 5 x = 1 A Computational Tools

  10. In this program, if a value of 0.5 is read for x, what is the final value of x? read x if x > -1 and x < 1 then x = 0 else x = x*x 0 0.25 0.5 1 A Computational Tools

  11. In this program, if a value of 3 is read for n, what value is assigned to x? read n switch n case 1 x = 2 case 2 x = 4 case 3 x = 6 otherwise x = 8 end 3 4 6 8 x = 6 C Computational Tools

  12. In this program, what is the final value of y? x = 1 y = 1 for n = 1 to 3 x = x + 2 y = y*x end 7 15 105 945 y = 105 C Computational Tools

  13. In this program, what is the final value of y? x = 0 y = 0 while x 6 x = x + 2 y = y + x end 8 10 12 20 y = 20 D Computational Tools

  14. What formula is implemented by this program? read x, m s = 1 t = 1 for k = 1 to m t = t*x/k s = s + t end • s = 1 + x + x/2 + x/3 + … + x/m • s = 1 + x/1! + x/2! + x/3! + … + x/m! • s = 1 + x/1 + x2/2 + x3/3 + … + xm/m • s = 1 + x/1! + x2/2! + x3/3! + … + xm/m! s = 1 + … k = 1; t = x; s = 1 + x + … k = 2; t = x2/2; s = 1 + x + x2/2 + … k = 3; t = x3/(2·3); s = 1 + x + x2/2 + x3/3! + … D Computational Tools

  15. Structured Programming • Flowcharts • Flow control • Functions Computational Tools

  16. Function • Main Program: Function: • a = 0; x = 1; y = 2 function y = special(x) • d = special(a) y = x + 1 • Print d return y • Notice that: • The function input is named a in the main program and x in the function. • The function output is named d in the main program and y in the function. • The variables x and y in the function do not affect the variables x and y in the main program. • The only effect of the function is to set d equal to a + 1. Computational Tools

  17. The following program is run. It uses the function simplefunction, which is also shown below. What is the value of h at the end of the program? g = 3; h = 5 p = simplefunction(g) function y = simplefunction(x) h = 7 y = x + h return y 12 10 5 7 • The function simplefunction returns 10 to the main program. The fact that the function uses h as the name of a local variable does not affect the h in the main program. The variable h in the main program remains 5. C Computational Tools

  18. The following program is run. It uses the function squareof, which is also shown below. What is the value of s at the end of the program? read x s = 1 y = squareof(x) s = s + y function s = squareof(x) s = x*x return s x2 + 1 x2 2x2 This program will result in an error message. • The function squareof returns x2 to the main program. The fact that the function uses the name s for the square does not affect the s in the main program. The assignment statement s = s + y produces x2+ 1. A Computational Tools

  19. Spreadsheets • Formulas • Copying and Pasting Formulas Computational Tools

  20. Formulas in Cells Computational Tools

  21. Colon Computational Tools

  22. Spreadsheets • Formulas • Copying and Pasting Formulas Computational Tools

  23. Absolute and Relative Addresses Computational Tools

  24. Copy and Paste a Cell: $A$1 Computational Tools

  25. Copy and Paste a Cell: A1 Computational Tools

  26. Copy and Paste a Cell: $A1 Computational Tools

  27. Copy and Paste a Cell: A$1 Computational Tools

  28. Copy and Paste a Column Computational Tools

  29. Copy and Paste a Row Computational Tools

  30. In a spreadsheet, the number in cell A3 is 4. Cell A4 contains the formula A3 + $A$3. This formula is copied into cells A5 and A6. What is the value of cell A6? A. 4 B. 8 C. 16 D. 32 C Computational Tools

  31. In a spreadsheet, the formula $A$3 + $B3 + D2 is entered into cell C2. The contents of cell C2 are copied and pasted into cell D5. The formula in cell D5 is: A. $A$3 + C$2 + C4 B. $B$6 + $C4 + C4 C. $A$3 + $B6 + E5 D. $A$3 + $B2 + B2 cell C2: $A$3 + $B3 + D2 • cell D5: $A$3 + $B6 + E5 C Computational Tools

  32. A spreadsheet contains the series of numbers 5,10,15,… in cells C2:C7. Cell D3 contains the formula (2*C2)+7. If the formula is copied and pasted into cells D4:D8, what is the numeric value in cell D8? 67 55 93 77 The formula (2*C2)+7 in cell D3 employs the number in the cell one column to the left and one row up. • In cell D8, this formula employs the number in the cell one column to the left and one row up (cell C7). This number is 30. (2*30)+7 = 67 A Computational Tools

  33. In this spreadsheet, the contents of column B are copied and pasted into columns C and D. What numeric value will cell D4 have? 32 64 96 128 C Computational Tools

  34. In this spreadsheet, the cell D1 contains the formula (A1+B1+C1)/3. This formula is copied into the range of cells D2:D3. Cell D4 contains the formula SUM(D1:D3). What is the numeric value in cell D4? 15 12 14 18 A Computational Tools

More Related