Presentation is loading. Please wait.

Presentation is loading. Please wait.

Computational Tools1 Structured Programming Spreadsheets.

Similar presentations


Presentation on theme: "Computational Tools1 Structured Programming Spreadsheets."— Presentation transcript:

1 Computational Tools1 Structured Programming Spreadsheets

2 Structured Programming Flowcharts Flow control Functions Computational Tools2

3 Start/Stop Operation Decision Input/Output Flowchart Symbols Computational Tools3

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

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

6 When the program represented by the following flowchart is run, what is the resulting sum? A.10 B.15 C.20 D.21 sum = 15 B Computational Tools6 start sum = 0 n = 0 n=5? end print sum n = n + 1 sum = sum + n no yes nsum 00 11 23 36 410 515

7 Structured Programming Flowcharts Flow control Functions Computational Tools7

8 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 A.0.25 B.0.5 C.0.75 D.1 A

9 Computational Tools9 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 A.1 B.5 C.6 D.8 x = 1 y = 2 x = 5 x = 1 A

10 Computational Tools10 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 A.0 B.0.25 C.0.5 D.1 A

11 Computational Tools11 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 A. 3 B. 4 C. 6 D. 8 x = 6 C

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 A. 7 B. 15 C.105 D.945 Computational Tools12 xy 11 33 515 7105 y = 105 C

13 A. 8 B.10 C.12 D.20 Computational Tools13 xy 00 22 46 612 820 y = 20 D

14 read x, m s = 1 t = 1 for k = 1 to m t = t*x/k s = s + t end A.s = 1 + x + x/2 + x/3 + … + x/m B.s = 1 + x/1! + x/2! + x/3! + … + x/m! C.s = 1 + x/1 + x 2 /2 + x 3 /3 + … + x m /m D.s = 1 + x/1! + x 2 /2! + x 3 /3! + … + x m /m! s = 1 + … k = 1; t = x; s = 1 + x + … k = 2; t = x 2 /2; s = 1 + x + x 2 /2 + … k = 3; t = x 3 /(2·3); s = 1 + x + x 2 /2 + x 3 /3! + … D Computational Tools14 What formula is implemented by this program?

15 Structured Programming Flowcharts Flow control Functions Computational Tools15

16 Function Main Program:Function: a = 0; x = 1; y = 2function y = special(x) d = special(a)y = x + 1 Print dreturn 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 Tools16

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 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 A.12 B.10 C. 5 D. 7 Computational Tools17

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 A.x 2 + 1 B.x 2 C.2x 2 D.This program will result in an error message. The function squareof returns x 2 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 x 2 + 1. A Computational Tools18

19 Spreadsheets Formulas Copying and Pasting Formulas Computational Tools19

20 Formulas in Cells ABCD 123C2 2A1 3A1-C2 4A1*D3 ABCD 123 2 30 40 Computational Tools20

21 Colon ABCD 110 22 33 4SUM(B1:B3) ABCD 110 22 33 415 ABCD 1 2 31023SUM(A3:C3) 4 ABCD 1 2 3102315 4 Computational Tools21

22 Spreadsheets Formulas Copying and Pasting Formulas Computational Tools22

23 Absolute and Relative Addresses ABCD 18A1 2$A$1 3$A1 4A$1 ABCD 188 28 38 48 Computational Tools23

24 Copy and Paste a Cell: $A$1 ABCD 187 254 3$A$1 4 ABCD 187 254 3 4 ABCD 187 254 38 48 Computational Tools24

25 Copy and Paste a Cell: A1 ABCD 187 254 3A1 4 ABCD 187 254 3 4C2 ABCD 187 254 38 44 Computational Tools25

26 Copy and Paste a Cell: $A1 ABCD 187 254 3$A1 4 ABCD 187 254 3 4$A2 ABCD 187 254 38 45 Computational Tools26

27 Copy and Paste a Cell: A$1 ABCD 187 254 3A$1 4 ABCD 187 254 3 4C$1 ABCD 187 254 38 47 Computational Tools27

28 Copy and Paste a Column ABCD 185A1 2$A$1 3$A1 4A$1 ABCD 185A1B1 2$A$1 3$A1 4A$1B$1 ABCD 18585 288 388 485 Computational Tools28

29 Copy and Paste a Row ABCD 18 25 3A1$A$1$A1A$1 4 ABCD 18 25 3A1$A$1$A1A$1 4A2$A$1$A2A$1 ABCD 18 25 38888 45858 Computational Tools29

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 A 34 4 5 6 A 34 48 5 6 A 34 48 512 6 A 34 48 5 616 C Computational Tools30

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 Tools31

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? A.67 B.55 C.93 D.77 The formula (2*C2)+7 in cell D3 employs the number in the cell one column to the left and one row up. C 25 310 415 520 625 730 A 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 Computational Tools32

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? ABCD 12$A$1 24A2 30A3+B2 45A$3*B3 ABCD 12$A$1 24A2B2C2 30A3+B2B3+C2C3+D2 45A$3*B3B$3*C3C$3*D3 ABCD 12222 24444 304812 4503296 A. 32 B. 64 C. 96 D.128 C Computational Tools33

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? ABCD 1123 2456 3789 4 A.15 B.12 C.14 D.18 ABCD 11232 2456 3789 4 ABCD 11232 24565 37898 415 A Computational Tools34


Download ppt "Computational Tools1 Structured Programming Spreadsheets."

Similar presentations


Ads by Google