Computational Tools1 Structured Programming Spreadsheets
Structured Programming Flowcharts Flow control Functions Computational Tools2
Start/Stop Operation Decision Input/Output Flowchart Symbols Computational Tools3
start Example Flowchart Computational Tools4 y = 4 y > 4? end print y y = f(x) no yes read x
start Flowchart with Iteration Computational Tools5 sum = 0 n = 0 n=5? end print sum n = n + 1 sum = sum + n no yes
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
Structured Programming Flowcharts Flow control Functions Computational Tools7
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
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
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
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
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 y = 105 C
A. 8 B.10 C.12 D.20 Computational Tools13 xy y = 20 D
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?
Structured Programming Flowcharts Flow control Functions Computational Tools15
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
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
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 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 A Computational Tools18
Spreadsheets Formulas Copying and Pasting Formulas Computational Tools19
Formulas in Cells ABCD 123C2 2A1 3A1-C2 4A1*D3 ABCD Computational Tools20
Colon ABCD SUM(B1:B3) ABCD ABCD SUM(A3:C3) 4 ABCD Computational Tools21
Spreadsheets Formulas Copying and Pasting Formulas Computational Tools22
Absolute and Relative Addresses ABCD 18A1 2$A$1 3$A1 4A$1 ABCD Computational Tools23
Copy and Paste a Cell: $A$1 ABCD $A$1 4 ABCD ABCD Computational Tools24
Copy and Paste a Cell: A1 ABCD A1 4 ABCD C2 ABCD Computational Tools25
Copy and Paste a Cell: $A1 ABCD $A1 4 ABCD $A2 ABCD Computational Tools26
Copy and Paste a Cell: A$1 ABCD A$1 4 ABCD C$1 ABCD Computational Tools27
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 Computational Tools28
Copy and Paste a Row ABCD A1$A$1$A1A$1 4 ABCD A1$A$1$A1A$1 4A2$A$1$A2A$1 ABCD Computational Tools29
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 A A A C Computational Tools30
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
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 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
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 A. 32 B. 64 C. 96 D.128 C Computational Tools33
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 A.15 B.12 C.14 D.18 ABCD ABCD A Computational Tools34