Computational Tools1 Structured Programming Spreadsheets.
Post on 11-Jan-2016
219 Views
Preview:
Transcript
Computational Tools 1
Computational Tools
• Structured Programming
• Spreadsheets
Computational Tools 2
Structured Programming
• Flowcharts
• Flow control
• Functions
Computational Tools 3
Start/Stop
Operation
Decision
Input/Output
Flowchart Symbols
Computational Tools 4
start
Example Flowchart
y = 4y > 4?
end
print y
y = f(x)
no
yes
read x
Computational Tools 5
start
Flowchart with Iteration
sum = 0n = 0
n=5?
end
print sum
n = n + 1sum = sum + n
noyes
Computational Tools 6
When the program represented by the following flowchart is run, what is the resulting sum?
A. 10B. 15C. 20D. 21
sum = 15 B
start
sum = 0n = 0
n=5?
end
print sum
n = n + 1sum = sum + n
noyes
n sum0 01 12 33 64 105 15
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 xif x < 0 then y = 0else if x > 1 then y = 1else y = x*xend
A. 0.25B. 0.5C. 0.75D. 1
A
Computational Tools 9
In this program, what is the final value of x?
x = 1y = 2*xx = x + y*yif x > 4 then x = x/5
A. 1B. 5C. 6D. 8
x = 1y = 2x = 5x = 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 xif x > -1 and x < 1 then x = 0else x = x*x
A. 0B. 0.25C. 0.5D. 1
A
Computational Tools 11
In this program, if a value of 3 is read for n, what value is assigned to x?
read nswitch n case 1 x = 2 case 2 x = 4 case 3 x = 6 otherwise x = 8end
A. 3B. 4C. 6D. 8
x = 6 C
Computational Tools 12
In this program, what is the final value of y?
x = 1y = 1for n = 1 to 3 x = x + 2 y = y*xend
A. 7B. 15C. 105D. 945
x y1 13 35 157 105
y = 105 C
Computational Tools 13
In this program, what is the final value of y?
x = 0y = 0while x 6 x = x + 2 y = y + xend
A. 8B. 10C. 12D. 20
x y0 02 24 66 128 20
y = 20 D
Computational Tools 14
read x, ms = 1t = 1for k = 1 to m t = t*x/k s = s + tend
A. s = 1 + x + x/2 + x/3 + … + x/mB. s = 1 + x/1! + x/2! + x/3! + … + x/m!C. s = 1 + x/1 + x2/2 + x3/3 + … + xm/mD. 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
What formula is implemented by this program?
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 + 1Print 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 = 5p = simplefunction(g)
function y = simplefunction(x)h = 7y = x + hreturn 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. 12B. 10C. 5D. 7
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 xs = 1y = squareof(x)s = s + y
function s = squareof(x)s = x*xreturn s
A. x2 + 1B. x2
C. 2x2
D. 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
A B C D
1 23 C2
2 A1
3 A1-C2
4 A1*D3
A B C D
1 23 23
2 23
3 0
4 0
Computational Tools 21
Colon
A B C D
1 10
2 2
3 3
4 SUM(B1:B3)
A B C D
1 10
2 2
3 3
4 15
A B C D
1
2
3 10 2 3 SUM(A3:C3)
4
A B C D
1
2
3 10 2 3 15
4
Computational Tools 22
Spreadsheets
• Formulas
• Copying and Pasting Formulas
Computational Tools 23
Absolute and Relative Addresses
A B C D
1 8 A1
2 $A$1
3 $A1
4 A$1
A B C D
1 8 8
2 8
3 8
4 8
Computational Tools 24
Copy and Paste a Cell: $A$1
A B C D
1 8 7
2 5 4
3 $A$1
4
A B C D
1 8 7
2 5 4
3 $A$1
4 $A$1
A B C D
1 8 7
2 5 4
3 8
4 8
Computational Tools 25
Copy and Paste a Cell: A1
A B C D
1 8 7
2 5 4
3 A1
4
A B C D
1 8 7
2 5 4
3 A1
4 C2
A B C D
1 8 7
2 5 4
3 8
4 4
Computational Tools 26
Copy and Paste a Cell: $A1
A B C D
1 8 7
2 5 4
3 $A1
4
A B C D
1 8 7
2 5 4
3 $A1
4 $A2
A B C D
1 8 7
2 5 4
3 8
4 5
Computational Tools 27
Copy and Paste a Cell: A$1
A B C D
1 8 7
2 5 4
3 A$1
4
A B C D
1 8 7
2 5 4
3 A$1
4 C$1
A B C D
1 8 7
2 5 4
3 8
4 7
Computational Tools 28
Copy and Paste a Column
A B C D
1 8 5 A1
2 $A$1
3 $A1
4 A$1
A B C D
1 8 5 A1 B1
2 $A$1 $A$1
3 $A1 $A1
4 A$1 B$1
A B C D
1 8 5 8 5
2 8 8
3 8 8
4 8 5
Computational Tools 29
Copy and Paste a Row
A B C D
1 8
2 5
3 A1 $A$1 $A1 A$1
4
A B C D
1 8
2 5
3 A1 $A$1 $A1 A$1
4 A2 $A$1 $A2 A$1
A B C D
1 8
2 5
3 8 8 8 8
4 5 8 5 8
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. 4B. 8C. 16D. 32
A
3 4
4
5
6
A
3 4
4 8
5
6
A
3 4
4 8
5 12
6
A
3 4
4 8
5 12
6 16 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 + C4B. $B$6 + $C4 + C4C. $A$3 + $B6 + E5D. $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?
A. 67B. 55C. 93D. 77
The formula (2*C2)+7 in cell D3 employs the number in the cell one column to the left and one row up.
C2 53 104 155 206 257 30
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 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?
A B C D
1 2 $A$1
2 4 A2
3 0 A3+B2
4 5 A$3*B3
A B C D
1 2 $A$1 $A$1 $A$1
2 4 A2 B2 C2
3 0 A3+B2 B3+C2 C3+D2
4 5 A$3*B3 B$3*C3 C$3*D3
A B C D
1 2 2 2 2
2 4 4 4 4
3 0 4 8 12
4 5 0 32 96
A. 32B. 64C. 96D. 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?
A B C D
1 1 2 3
2 4 5 6
3 7 8 9
4
A. 15B. 12C. 14D. 18
A B C D
1 1 2 3 2
2 4 5 6
3 7 8 9
4
A B C D
1 1 2 3 2
2 4 5 6 5
3 7 8 9 8
4 15 A
top related