+ All Categories
Home > Documents > Exam 1: Review 1.History of computers 2.Fundamentals of computer architecture 3.Developing...

Exam 1: Review 1.History of computers 2.Fundamentals of computer architecture 3.Developing...

Date post: 26-Dec-2015
Category:
Upload: deirdre-cornelia-whitehead
View: 215 times
Download: 1 times
Share this document with a friend
Popular Tags:
40
Exam 1: Review 1. History of computers 2. Fundamentals of computer architecture 3. Developing algorithms and programs 4. Variables and data types 5. User I/O 6. Operators 7. Library Functions 1
Transcript
Page 1: Exam 1: Review 1.History of computers 2.Fundamentals of computer architecture 3.Developing algorithms and programs 4.Variables and data types 5.User I/O.

1

Exam 1: Review

1. History of computers2. Fundamentals of computer architecture3. Developing algorithms and programs4. Variables and data types5. User I/O6. Operators7. Library Functions

Page 2: Exam 1: Review 1.History of computers 2.Fundamentals of computer architecture 3.Developing algorithms and programs 4.Variables and data types 5.User I/O.

2

Finally, the von Neumann Architecture…

• The Von Neumann computer architecture is mostly what we use today. The architecture separates a computer in 3 major parts:– The Central Processing Unit (CPU)– The computer memory– The Input/Output (I/O) devices

CPU + memoryScreen=output

Speakers=output Mouse=input

Keyboard=input

?

Page 3: Exam 1: Review 1.History of computers 2.Fundamentals of computer architecture 3.Developing algorithms and programs 4.Variables and data types 5.User I/O.

3

Categories of software

• Software contains the instructions the CPU uses to run programs. There are several categories, including:

– Operating systems (OS) – manager of the computer system as a whole

– Software applications – commercial programs that have been written to solve specific problems

– Compilers / Interpreters - to ‘translate’ programs written by people into something understandable by the machine

Page 4: Exam 1: Review 1.History of computers 2.Fundamentals of computer architecture 3.Developing algorithms and programs 4.Variables and data types 5.User I/O.

4

Generations of Languages used to write software

1) Machine language – also called binary language. Sequenceof 0’s and 1’s.

2) Assembly language – each line of code produces a single machine instruction (add, subtract…), see bottom of page 11.

3) High-level language – slightly closer to spoken languages.

add b,cadd a,b

a= a + b + c;

This line does the same as the two above.

Page 5: Exam 1: Review 1.History of computers 2.Fundamentals of computer architecture 3.Developing algorithms and programs 4.Variables and data types 5.User I/O.

5

MATLAB…

• Is an interpreted language – does not require compilation, but instead has an interpreter running behind the scenes– MATLAB executes one line at a time, (stops if one line crashes, or code

ends)– Compiled languages read the entire code before executing line1!

• Has an interactive environment –– “In the MATLAB environment, you can develop and execute programs

that contain MATLAB commands. You can execute a MATLAB command, observe the results, and then execute another MATLAB command that interacts with the information in memory, observe its results and so on.”

Page 6: Exam 1: Review 1.History of computers 2.Fundamentals of computer architecture 3.Developing algorithms and programs 4.Variables and data types 5.User I/O.

6

Problem Solving Process

1. Problem Statementa. Diagramb. Assumptions

2. Solution Steps (manual solution)a. Theory / limitationsb. Itemize specific steps (in order) as you solve the problemc. Identify results & verify accuracy

3. Computerize the solutiona. Express the algorithm as steps general to any instance of the problemb. Translate the algorithm to lines of codec. Test and verify results

Page 7: Exam 1: Review 1.History of computers 2.Fundamentals of computer architecture 3.Developing algorithms and programs 4.Variables and data types 5.User I/O.

7

Frame #1“The Command Window”

Frame #2“Current

Directory”

Frame #3“Workspace”

Frame #4“Command History”

“Your Calculator Screen”

You can do exactly as on your calculator: add, subtract, divide, multiple, use parentheses to override the order of operations…

Later on, you will realize you can do a LOT more in this frame.

This frame shows the files (excel, text, Matlab files) that can immediately be used.

It will show the variables that have been created.

It will show all the commands executed previously.

Page 8: Exam 1: Review 1.History of computers 2.Fundamentals of computer architecture 3.Developing algorithms and programs 4.Variables and data types 5.User I/O.

8

Basic Data Manipulation

• A variable is a name given for a memory location• “Assigning a value to a variable” means to place a value in the

memory location associated with the variable name

• MATLAB usually shows what the variables are - in the Command Window, but also in the Workspace.

Page 9: Exam 1: Review 1.History of computers 2.Fundamentals of computer architecture 3.Developing algorithms and programs 4.Variables and data types 5.User I/O.

9

The keyword ans

Page 10: Exam 1: Review 1.History of computers 2.Fundamentals of computer architecture 3.Developing algorithms and programs 4.Variables and data types 5.User I/O.

10

Inputs

• What data type is the user asked for?

– num_apples = input('How many WHOLE apples? ');

The user is asked to provide a number .

– name = input('Enter your name: ', 's');The user is asked to provide a sequence of characters – i.e. a string.

These are the only forms of the input() function.

Page 11: Exam 1: Review 1.History of computers 2.Fundamentals of computer architecture 3.Developing algorithms and programs 4.Variables and data types 5.User I/O.

11

Form #1. input()

• In the first form, only 1 prompt is inside the parentheses:

num_apples = input('How many WHOLE apples? ');

There is only one argument to the function. Arguments are inputs to the function – information being sent into the function so it can do its job.

The one argument is the prompt string:'How many WHOLE apples:'

Page 12: Exam 1: Review 1.History of computers 2.Fundamentals of computer architecture 3.Developing algorithms and programs 4.Variables and data types 5.User I/O.

12

Form #2. input(…,‘s’)

• In the second form of the input() function, there are TWO arguments: the prompt string, and another string: ‘s’

name = input('Enter your name: ', 's');

• If this argument is present, it must be the letter 's' and no other letter!

1st argument 2nd argument

Page 13: Exam 1: Review 1.History of computers 2.Fundamentals of computer architecture 3.Developing algorithms and programs 4.Variables and data types 5.User I/O.

13

Display with a specific format

• There are multiple ways to display the value of a variable1. Use the semicolon appropriately2. use the disp() built-in function3. use the fprintf() built-in function

• Each is used for specific reasons1. Debugging – finding problems with the code2. Simple programs, simple results (the programmer’s use)3. Formatted (“pretty”) output

Page 14: Exam 1: Review 1.History of computers 2.Fundamentals of computer architecture 3.Developing algorithms and programs 4.Variables and data types 5.User I/O.

14

Using fprintf()

1. fprintf(...) % is the built-in function

2. fprintf('format String InSeRtEd hErE!') % The format string allows you to put words and specify a format (UPPER CASE vs. Lower case, and punctuation only)

3. fprintf('format string with placeholders', list of vars comma-separated, one for each placeholder)

% Placeholders allow a specific format to be set (aligned right, and 2 decimal places for example)

Page 15: Exam 1: Review 1.History of computers 2.Fundamentals of computer architecture 3.Developing algorithms and programs 4.Variables and data types 5.User I/O.

15

Using fprintf()

Example:

fprintf('His name is %s, he makes %f dollars/year and his age is %d.\n', his_name, his_income, his_age);

Provides:His name is Fred, he makes 1234.560000 dollars/year and his age is 45.

>>>

Page 16: Exam 1: Review 1.History of computers 2.Fundamentals of computer architecture 3.Developing algorithms and programs 4.Variables and data types 5.User I/O.

16

Vocabulary

fprintf('The value in result is %f meters.', result);

“function call” ‘format string’ “placeholder”(part of format string)

variable to be printed

Page 17: Exam 1: Review 1.History of computers 2.Fundamentals of computer architecture 3.Developing algorithms and programs 4.Variables and data types 5.User I/O.

17

Most common placeholders

• Each data-type has a placeholder– Integer %d– Floats %f– Strings %s– A single letter %c

Page 18: Exam 1: Review 1.History of computers 2.Fundamentals of computer architecture 3.Developing algorithms and programs 4.Variables and data types 5.User I/O.

18

%d does NOT mean decimals!

Example:

fprintf('His name is %s, he makes %d dollars/year and his age is %d.\n', his_name, his_income, his_age);

Provides:His name is Fred, he makes 1.234560e+003 dollars/year and his age is 45.

>>

Page 19: Exam 1: Review 1.History of computers 2.Fundamentals of computer architecture 3.Developing algorithms and programs 4.Variables and data types 5.User I/O.

19

Special Characters

• Escape sequences can also be used within the format string:\n - this will create a new line when printing the string\t - tab (tabs the text to the right)

Special characters:'' - this will place one apostrophe in the final sentence

• Example of all three:>> fprintf('%s''s age:\t\t%d years old\n\n', name, age);Fred's age: 47 years old

>>

Page 20: Exam 1: Review 1.History of computers 2.Fundamentals of computer architecture 3.Developing algorithms and programs 4.Variables and data types 5.User I/O.

20

Format Modifiers

• Once the base placeholder is ready, modifiers further change how the values are displayed.

• Complete Format Modifier form:

_ _ _ _ _ _ _ 7 6 5 4 3 2 1

%-7.2f

Left-justify the value

TOTAL width to occupy

Nb. of decimal places

2 3 . 5 5 _ _7 6 5 4 3 2 1

- 3 4 . 3 0 _7 6 5 4 3 2 1

- 6 6 9 7 . 4 47 6 5 4 3 2 1

Page 21: Exam 1: Review 1.History of computers 2.Fundamentals of computer architecture 3.Developing algorithms and programs 4.Variables and data types 5.User I/O.

21

Operators & Operands

• Operators work on operands. There are 2 types of operands:1. Numerical 1, 3.5, -472. Logical true, false

• Arithmetic operators (+, -, /, *, ^) and relational operators (<, <=, >, >=, ==, ~=) require numerical operands

• Boolean operators (&&,||,~) require logical operands

Page 22: Exam 1: Review 1.History of computers 2.Fundamentals of computer architecture 3.Developing algorithms and programs 4.Variables and data types 5.User I/O.

22

Boolean Operators

• These operators take logical values and perform some operation on them to yield a logical value

• Two Boolean operators allow to combine logical expressions– && Logical AND– || Logical OR

• One Boolean operator allows to negate the result– ~ Logical NOT– “Negate”: turns true values into false, and false values into true

Page 23: Exam 1: Review 1.History of computers 2.Fundamentals of computer architecture 3.Developing algorithms and programs 4.Variables and data types 5.User I/O.

23

Operators: unary vs. binary

• Operators can be unary – taking only one operand:y = -x;

opposite = ~result;

• Or binary operators – taking two operands:z = x * y;z = x + y;z = x – y; %both unary and binary!z = x / y;z = x ^ y;x >= 7(x<3) && (3>y)

Page 24: Exam 1: Review 1.History of computers 2.Fundamentals of computer architecture 3.Developing algorithms and programs 4.Variables and data types 5.User I/O.

24

Operators: Output values

Type Input values Output values

Arithmetic: Numbers Numberse.g. 5 * 3 15

Relational: Numbers Logicale.g. 5 < 3 false

Boolean: Logical Logicale.g. ~true false

Page 25: Exam 1: Review 1.History of computers 2.Fundamentals of computer architecture 3.Developing algorithms and programs 4.Variables and data types 5.User I/O.

25

What is a function?

• A function is like a box with holes in it.

Input Output

The _________ function

Magic

sinsqrtfloorrandbazingawhy

Page 26: Exam 1: Review 1.History of computers 2.Fundamentals of computer architecture 3.Developing algorithms and programs 4.Variables and data types 5.User I/O.

26

Exam 1:Review Questions

Page 27: Exam 1: Review 1.History of computers 2.Fundamentals of computer architecture 3.Developing algorithms and programs 4.Variables and data types 5.User I/O.

27

Review Questions

Software & Hardware:

Provide a simple definition for software.

Is a DVD hardware or software?

Page 28: Exam 1: Review 1.History of computers 2.Fundamentals of computer architecture 3.Developing algorithms and programs 4.Variables and data types 5.User I/O.

28

Review Questions

Language generations:

Sort the following languages in order of generation, low to high:

• MATLAB

• Machine

• Assembly

Why do we say that computers work in "binary"?

Page 29: Exam 1: Review 1.History of computers 2.Fundamentals of computer architecture 3.Developing algorithms and programs 4.Variables and data types 5.User I/O.

29

Problem Solving Process:

When solving the following problem, what is the first step?

Write a computer program that will compute the volume of any right regular prism with 10 sides or less.

Review Questions

Page 30: Exam 1: Review 1.History of computers 2.Fundamentals of computer architecture 3.Developing algorithms and programs 4.Variables and data types 5.User I/O.

30

Review Questions

Developing Solutions:

Page 31: Exam 1: Review 1.History of computers 2.Fundamentals of computer architecture 3.Developing algorithms and programs 4.Variables and data types 5.User I/O.

31

Review Questions

MATLAB Defaults:

What is ans?

What does clear do?

What about clc?

How do you suppress default output?

Page 32: Exam 1: Review 1.History of computers 2.Fundamentals of computer architecture 3.Developing algorithms and programs 4.Variables and data types 5.User I/O.

32

Data types:

Describe the following types of data:

– Integerswhole numbers

– Floatsnumbers with fractional portion

– Stringssequences of characters

Review Questions

Page 33: Exam 1: Review 1.History of computers 2.Fundamentals of computer architecture 3.Developing algorithms and programs 4.Variables and data types 5.User I/O.

33

Review Questions

MATLAB Layout:

What is the command window useful for?a) Performing quick commands to see resultsb) Everyday calculator operationsc) Getting the help file of a specific built-in functiond) Writing full scripts

(Select all that apply)

Page 34: Exam 1: Review 1.History of computers 2.Fundamentals of computer architecture 3.Developing algorithms and programs 4.Variables and data types 5.User I/O.

34

Review Questions

Input and Output:

What is the purpose of the first argument in a call to input() ?

How many arguments are needed to collect a string from the user?

Page 35: Exam 1: Review 1.History of computers 2.Fundamentals of computer architecture 3.Developing algorithms and programs 4.Variables and data types 5.User I/O.

35

Review Questions

Output functions:

• Given the following place holder: %14.7f

How many decimal places will be displayed?

What is the total width occupied on the screen as a result of this format specifier?

Is the output left- or right-justified?

Page 36: Exam 1: Review 1.History of computers 2.Fundamentals of computer architecture 3.Developing algorithms and programs 4.Variables and data types 5.User I/O.

36

Review Questions

Output functions:

Given the following MATLAB statement:fprintf('%11s''s income:\t$%-7.2f/year\n', name, paycheck);

1. Identify the escape sequence(s) used.

3. If paycheck holds the value 123456.789, what will be printed for the second placeholder?

2. If name holds the value 'Fred Flintstone', what will be printed for the first placeholder?

Page 37: Exam 1: Review 1.History of computers 2.Fundamentals of computer architecture 3.Developing algorithms and programs 4.Variables and data types 5.User I/O.

37

Review Questions

Operators:

Given the following operators:&, &&, |, ||, +, -, *, /, ~, <, =, ==

Identify the Boolean operators.

Identify the Relational operators

What about the other ones?

Page 38: Exam 1: Review 1.History of computers 2.Fundamentals of computer architecture 3.Developing algorithms and programs 4.Variables and data types 5.User I/O.

38

Review Questions

Operators:

What is the result of a Boolean operator?– Numerical value– Logical value

What is the numerical value stored in the workspace for the logical “false”– 1– 0– Logical expressions are not stored in the workspace

Page 39: Exam 1: Review 1.History of computers 2.Fundamentals of computer architecture 3.Developing algorithms and programs 4.Variables and data types 5.User I/O.

39

Review Questions

Identify the parts – provide the name for the item or action:the_result = some_function( );val1, str2, int3

Name a MATLAB built-in function which could be used to determine divisibility.

While examining code from another engineer, you discover this line:

fix_val = fix(z, 2);

Did s/he use this command correctly? If so, what does it do? If not, what is wrong?

Is there a built-in MATLAB function that will find the cube root of a number?

Library Functions:

Page 40: Exam 1: Review 1.History of computers 2.Fundamentals of computer architecture 3.Developing algorithms and programs 4.Variables and data types 5.User I/O.

40

RUN home STUDY hard SLEEP well SHOW UP for the exam.

Good Luck!

How to prepare for Test 1


Recommended