Departamento de Ingenieria General Recinto...

Post on 09-Mar-2018

217 views 4 download

transcript

Fundamentals of Engineering (FE) Review Exam

Computers Software

Departamento de Ingenieria General

Recinto Universitario de Mayagüez

Universidad de Puerto Rico

Dr. Marco A. Arocha

10th August 2013

Content, Topics

Subjects o Numeric Systems & Conversions

o FORTRAN

o Flowchart Symbols

o Low-level Languages

o High-level Languages

o Assembly Language

o Pseudocode

o Logic Operations

o Spreadsheets

Content, FE Review

Glossary: In a separate document there is a selected

list of frequent used computer terms

Problems: Also a collection of FE like problems

Website: Some topics, problems, solutions, strategies,

and more. Under Construction

Numeric Systems Conversions

Binary Binary

Base-5 Base-5

Base-7 Base-7

Octal Octal

Decimal X X X Decimal

Hexadecimal X X Hexadecimal

Binary & Decimal • Decimal:

15610

• Binary:

100111002

• The binary system is the

internal language of

computers

• Computer programmers should understand how to

convert from decimal to

binary.

Binary Decimal

Bases Equivalent

0 0

1 1

2

3

4

5

6

7

8

9

Binary to Decimal 101110002 decimal

0 0X20

= 0

0 0X21

= 0

0 0X22= 0

1 1X23= 8

1 1X24

= 16

1 1X25

= 32

0 1X26

= 0

1 1X27128

sum 184

= 18410101110002

Hexadecimal & Decimal

Uses letters for the numbers from 10 to 15

Hexadecimal to Decimal 3B21AC16 decimal

C 12X160 = 12

A 10X161= 160

1 1X162= 256

2 2X163

= 8192

B 11X164

= 720896

3 3X165

= 3145728

sum = 3875244

= 3875244103B21AC16

High Level Languages Computer programs are written in specific languages:

“High-Level” and “Low-Level” Languages.

High-level programming language: o It is easy to use, resembles English

o Hide memory management

o Developing programs is simpler and more understandable relative to a

lower-level languages.

o The amount of abstraction provided defines how "high-level" a

programming language is.

o Examples of high-level programming languages include FORTRAN, C,

C++, VBA, FOCUS, Lisp, Perl, and Python.

FORTRAN In the past FE exam used FORTRAN as the high-level language of its choice. Still

sometimes you may found FORTRAN problems. The operators in FORTRAN:

Priority

FORTRAN sample question

What is the approximate value of variable S in the

FORTRAN statement shown?

S=(5.4)**(3.2)+5.4/2.5*1.5

(A)136

(B) 175

(C)224

(D)233

FORTRAN Hints 1. Square of 5: 5**2

2. Square root of 5: 5**0.5

3. - 3**2 = -(3**2) = -9, exponential operator has

higher priority than unary opertor “-”

4. A**B**C is equal to A**(B**C) rather than (A**B)**C

Low-Level Languages

Low-Level Languages: o MACHINE LANGUAGE

o ASSEMBLY LANGUAGE

Machine Language • instructions understood by

CPU

• made up of binary strings

of 0s and 1s

• instructions has two parts:

operation and operands

addresses

• instructions are a series of

bits

Assembly Language

• symbolic language

• Mnemonic codes for

operations

• Variables names

rather than addresses

• Uses macros (blocks of

codes than can be

repeated) referred by

names

• More sophisticated than machine

language

Assembly Language

For assembly language:

1. Assembly language code is translate into machine

language by an assembler

2. Functions libraries are combined by the linker

3. Program is placed into the computer memory by a

loader

Assembly Example Some times FE exam contains problems on basic

assembly

Data Movement Instruction

mov — The mov instruction copies the data item

referred to by its second operand into the location

referred to by its first operand

• Example:

mov eax, ebx — copy the value in ebx into eax

Assembly Example Arithmetic and Logic Instructions

• add — Integer Addition. The add instruction adds

together its two operands, storing the result in its first

operand.

• Example

add eax, 10 — means: EAX ← EAX + 10

Assembly Example Arithmetic and Logic Instructions

• sub — Integer Subtraction. The sub instruction stores

in the value of its first operand the result of

subtracting the value of its second operand from

the value of its first operand.

• Examples

sub al, ah — means: AL ← AL - AH

Assembly Example Arithmetic and Logic Instructions

• inc, dec — Increment, Decrement.

The inc instruction increments the contents of its

operand by one. The dec instruction decrements

the contents of its operand by one.

• Examples

dec eax — subtracts one from the contents of EAX.

inc eax— adds one from the contents of EAX.

Pseudocode • An informal language that helps programmers develop

algorithms

• A text-based detail algorithmic design tool.

• Each individual designer may have its own personal style of

pseudocode

• It has not a rigorous notation. There is no universal "standard."

• It is recommended that all statements showing "dependency" are to be indented. These include while, do, for, if, switch.

• In the FE exam this last advice is not follow.

• Examples below will illustrate this notion.

H = 1

J = 2

K = 3

L = 4

ANSWER = C

IF (H>J) OR (K<L) THEN ANSWER = A

IF (H<J) OR (K>L) THEN ANSWER = B

IF (H>J) OR (K>L) THEN H = 5

IF (H<J) AND (K<L) THEN ANSWER = D

Chose one:

A

B

C

D

Based on the following pseudocode, what is the

ANSWER?

Follow the value of the variables ANSWER and H after each IF:

IF (TRUE) ANSWER=A

IF (TRUE) ANSWER=B

IF (TRUE) H=5

IF (TRUE) ANSWER=D

Select (D) as the solution of the problem

Pseudocode Example

• How many times will the second line be executed?

M=42

LOOPSTART M=M-1

P=INTEGER PART OF (M/2)

IF P>15, THEN GO TO LOOPSTART

OTHERWISE GO TO END

END PRINT “DONE”

iteration M P P>15 GO TO

1 41 20 T LOOPSTART

2 40 20 T LOOPSTART

3 39 19 T LOOPSTART

4 38 19 T LOOPSTART

5 37 18 T LOOPSTART

6 36 18 T LOOPSTART

7 35 17 T LOOPSTART

8 34 17 T LOOPSTART

9 33 16 T LOOPSTART

10 32 16 T LOOPSTART

11 31 15 F END

Becareful: Most people will answer 10, however the 2nd

instuction M=M-1 will execute one more time to reach

the false condition 15>15 and then GO TO END

Pseudocode Example, Solution

Pseudocode Example

INPUT X

Y=0

Z=X+1

FOR K=1 TO Z

Y=Y+Z

NEXT K

Y=Y-(2*Z-1)

INPUT X

Y=0

Z=X+1

FOR K=1 TO Z

Y=Y+Z

NEXT K

Y=Y-(2*Z-1)

A program contains the following pseudocode

segment:

What is the final value of Y in terms of X?

(A) x2-1

(B) x2

(C) x2+1

(D) x2+2x+1

Pseudocode Example Solution

Alternative-1:

Within the loop Y is initialized to zero and then has Z

added to it Z times:

𝑌 =0+Z+Z+Z+Z+Z+Z+Z+..Z

Y=Z2 z added z times

After the loop

Y=Z2-2Z+1=(Z-1)2

Y=(X+1-1)2=X2

Pseudocode, Example Solution Alternative-2

Follow the pattern of the X and Y variable

X Z K Y, loop Y, final

0 1 1 1 0

1 2 1 2

2 0 1

2 3 1 3 Y=X2

2 6

3 9 4

3 4 1 4

2 8

3 12

4 16 9

Pseudocode Example

INPUT N, X

S=1

T=1

FOR K=1 TO N

T=(-1)*T*X^2/(2*K*(2*K-1))

S=S+T

NEXT K

What sum is calculated by the following

pseudocode program segment:

(A) 𝑆 = 1 −𝑥2

2 −

𝑥2

12 −

𝑥2

30 − ⋯ −

𝑥2

2𝑛(2𝑛−1)

(B) 𝑆 = 1 −𝑥2

2 −

𝑥4

12 −

𝑥6

30 − ⋯ −

𝑥2𝑛

2𝑛(2𝑛−1)

(C) 𝑆 = 1 −𝑥2

2! −

𝑥4

4! −

𝑥6

6! − ⋯ − (−1)𝑛 𝑥2𝑛

2𝑛 !

(D) 𝑆 = 1 −𝑥3

2! −

𝑥4

4! −

𝑥5

6! − ⋯ − (−1)𝑛𝑥𝑛+2

2𝑛 !

Pseudocode Example

Make a list for the values of S through the first few loops until

the pattern is evident

N=0 S=1

N= 1 𝑆 = 1 −𝑥2

2

N=2 𝑆 = 1 −𝑥2

2 −

𝑥4

24

N=3 𝑆 = 1 −𝑥2

2 −

𝑥4

24 −

𝑥6

720

N=n 𝑆 = 1 −𝑥2

2! −

𝑥4

4! −

𝑥6

6! − ⋯ − (−1)𝑛 𝑥2𝑛

2𝑛 !

ANSWER IS (C)

A flowchart is a step-by-step

drawing representing a specific

procedure or algorithm

www. allbusiness.com

Flowcharts

Flow Chart Symbols

Starts/Stops Decision [ decision must be made]

Input/Output [keyboard, printer, memory, permanent data storge]

Connector [point where several flow lines merge]

Processing [calculation]

Off-page [fc continues next page]

Predefined Process (library functions)

Annotation [comments]

Flowcharts

The terminal symbol starts or stops a process. The FE

problems typically involve a program fragment, so this

symbol might be used to distinguish a complete

program from a fragment

The decision symbol is a branch point in a flowchart. It

can only have one of two results, “true” or “false.” The decision symbol equate to an IF-ELSE statement, the

start of a WHILE loop, or the start of FOR loop.

The input/output symbol may be used in a program to

receive data from the user or to output data to the user or data storage.

Flowcharts

The processing symbol is where

mathematical (numerical or string)

operations take place

The connector symbol indicates where

several flow lines merge.

The off page symbol indicates that the

flowchart continues on the following page

Comments are placed on the annotation

symbol.

Which of the following flowcharts does not represent a complete program?

Flowcharts

The flowchart shown

represents the summer

training schedule for a

college athlete. What is the

regularly scheduled workout

on Wednesday morning?

(A) bike

(B) rest

(C) run

(D) weights

Flowcharts questions?

38

Logic Operations

Operators

AND

OR

NOT

39

‘AND’ True Table

Cond1 Operator Cond2 Result

T AND T T

T AND F

F AND T

F AND F

Expressions containing ‘AND’ are true only if both

conditions are true

40

‘OR’ True Table

Cond1 Operator Cond2 Result

F OR F F

T OR F

F OR T

T OR T

Statements containing ‘OR’ are false when both conditions

are false.

41

‘NOT’ True Table

NOT Cond Result

NOT T F

NOT F

‘NOT’ switches to false the expression if it is true and

viceverse.

42

Example • Let

A=5; B=3; C=6; D=8;

• Find the value of (A>B) AND (C>D)

(5>3 ) AND (6>8 )

T F

F

evaluate the terms

within the

parentheses first evaluate

43

Example • Let

A=5; B=3; C=6; D=8;

• Find the value of (A>B) OR (C>D)

(5>3) OR (6>8)

T F

T

evaluate

44

Example • Let

A=5; B=3; C=6; D=8;

• Find the value of ~( (A>B) AND (C>D))

~( (5>3) AND (6>8) )

T F

F

T

evaluate

FE Sample Problem • Given A= true, B= true, and C= false, what is the

value of the following expression?

• (A.AND.B).AND.(NOT.(C.OR.A))

(A)true

(B) false

(C)either true or false

(D)neither true nor false

FE Sample Problem Evaluate the terms within the parenthesis first, from the

inner to the outer parenthesis:

(A AND B) AND (NOT (C OR A))

(T AND T) AND (NOT (F OR T))

(T AND T) (NOT ( T )

(T AND F)

F

order

Spreadsheets A spreadsheet is a collection of items arranged in a tabular

format and organizaed in rows and columns. Typically, rows are

assigned numbers: 1, 2, 3, ... and columns are assigned letters: A,

B, C, ...

Cells

A cell is a unique element identified by an address consisting of

the column letter and the row number. For example, the address of the shaded cell above is D3. A cell may contain a number,

formula, or name.

Formulas Spreadsheets allow the construction of formulas in a

cell that may reference the content in other cells,

example:

The formula in the cell D3:

D3=C4+E5

Formulas When a cell containing a formula is copied to another cell, the

column and row references will automatically be changed by

others in the same relative position (this is called relative addressing)

Cell References

If D3=C4+E5 is copied to

C7=B8+D9

G6=F7+H8

Cell References If a row or column is referenced using absolute addressing (indicated

with a $ symbol) the row or the column reference will not changed

when a cell containing a formula is copied to another cell.

If C3 is copied to Result is

D3 D3=$B4+E$5+$A$1

C4 C4=$B5+D$5+$A$1

B4 B4=$B5+C$5+$A$1

E5 E5=$B6+F$5+$A$1

C3=$B4+D$5+$A$1

Spreadsheets

Computer programs consisting of tables of cells

containing values or formulas: • Cells are arranged in rows (labeled by numbers) and columns

(labeled by letters)

• Cells could be related to other cells

Example. The content of the cells in a spreadsheet are shown

What is the value of ‘T’ in the following program:

y=-3

z=y*3+10

T=D2-5*z

answer: T=-17

• How many cells are in the range C5...Z30

(A)575

(B) 598

(C)600

(D)624

Solution:

C5

Z35

From row 5 up to 30 there are 26 rows: 30-5+1=26

From column C up to Z there are 24 cols: 26-3+1=24

Total cells: 26x24=624, ANSWER IS (D)

Spreadsheets, sample problem

The cells in a spreadsheet are initialized as shown. The

formula B1+$A$1*A2 is entered into cell B2 and then

copied into B3 and B4. What value is displayed in B4?

• (A) 123

• (B) 147

• (C) 156

• (D) 173

The cells in a spreadsheet are initialized as shown. The

formula B1+$A$1*A2 is entered into cell B2 and then

copied into B3 and B4. What value is displayed in B4?

• (A) 123

• (B) 147

• (C) 156

• (D) 173 Need to compute each formula in

the order B2, B3, B4

Spreadsheets, sample problem

Good Luck !!!