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.

Slides:



Advertisements
Similar presentations
CS0007: Introduction to Computer Programming Console Output, Variables, Literals, and Introduction to Type.
Advertisements

Introduction to C Programming
 2005 Pearson Education, Inc. All rights reserved Introduction.
1 Chapter 2 Introduction to Java Applications Introduction Java application programming Display ____________________ Obtain information from the.
Introduction to C Programming
COSC 120 Computer Programming
 2008 Pearson Education, Inc. All rights reserved JavaScript: Introduction to Scripting.
Copyright © 2012 Pearson Education, Inc. Chapter 1: Introduction to Computers and Programming.
 2007 Pearson Education, Inc. All rights reserved Introduction to C Programming.
Data types and variables
Introduction to C Programming
Chapter 3: Introduction to C Programming Language C development environment A simple program example Characters and tokens Structure of a C program –comment.
Basic Elements of C++ Chapter 2.
1 Chapter Two Using Data. 2 Objectives Learn about variable types and how to declare variables Learn how to display variable values Learn about the integral.
Computer Science 101 Introduction to Programming.
Copyright © 2012 Pearson Education, Inc. Chapter 1: Introduction to Computers and Programming.
Chapter Introduction to Computers and Programming 1.
Lecture 2 - Variables, program execution, calculations, print() COMPSCI 101 Principles of Programming.
Objectives You should be able to describe: Data Types
Introduction to Python
Lecture 4 Input/Output Conditional Statements 1. Data Types 2. Input/Outputs 3. Operators 4. Conditionals 1.
Chapter 1: Introduction to Computers and Programming.
Copyright © 2009 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Chapter 1: Introduction to Computers and Programming.
Lecture 4 MATLAB Windows Arithmetic Operators Maintenance Functions
REVIEW 2 Exam History of Computers 1. CPU stands for _______________________. a. Counter productive units b. Central processing unit c. Copper.
IPC144 Introduction to Programming Using C Week 1 – Lesson 2
DEPARTMENT OF COMPUTER SCIENCE & TECHNOLOGY FACULTY OF SCIENCE & TECHNOLOGY UNIVERSITY OF UWA WELLASSA 1 CST 221 OBJECT ORIENTED PROGRAMMING(OOP) ( 2 CREDITS.
Presenting results to the USER in a professional manner 1. semicolon, disp(), fprintf() 2. Placeholders 3. Special characters 4. Format-modifiers Output.
Introduction to Java Applications Part II. In this chapter you will learn:  Different data types( Primitive data types).  How to declare variables?
Copyright © 2009 Pearson Education, Inc. Publishing as Pearson Addison-Wesley STARTING OUT WITH Python Python First Edition by Tony Gaddis Chapter 2 Input,
CH2 – Using Data. Constant Something which cannot be changed Data Type Format and size of a data item Intrinsic Data Types Pg. 47 – Table 2-1 Basic ones.
Input, Output, and Processing
Introduction to Computers and Programming 1. History of computers (4 slides) 2. What is a computer system? 3. What is a software? 4. What is programming?
Chapter 3 Syntax, Errors, and Debugging Fundamentals of Java.
Computer Science 101 Introduction to Programming.
© Copyright 1992–2004 by Deitel & Associates, Inc. and Pearson Education Inc. All Rights Reserved. Chapter 2 Chapter 2 - Introduction to C Programming.
Getting Started with MATLAB 1. Fundamentals of MATLAB 2. Different Windows of MATLAB 1.
1. Exam Topics Difference between computers and calculators John creates a new device. It will compute the orbit of all the planets in the solar system.
Introduction to C Programming Angela Chih-Wei Tang ( 唐 之 瑋 ) Department of Communication Engineering National Central University JhongLi, Taiwan 2010 Fall.
Constants Numeric Constants Integer Constants Floating Point Constants Character Constants Expressions Arithmetic Operators Assignment Operators Relational.
 Pearson Education, Inc. All rights reserved Introduction to Java Applications.
Ch1 Introduction to Computers and Programming 1. History of computers (4 slides) 2. What is a computer system? 3. What is a software? 4. What is programming?
Copyright © 2012 Pearson Education, Inc. Publishing as Pearson Addison-Wesley C H A P T E R 2 Input, Processing, and Output.
1 Chapter 3 Syntax, Errors, and Debugging Fundamentals of Java: AP Computer Science Essentials, 4th Edition Lambert / Osborne.
Getting Started with MATLAB (part2) 1. Basic Data manipulation 2. Basic Data Understanding 1. The Binary System 2. The ASCII Table 3. Creating Good Variables.
Asking the USER for values to use in a software 1 Input.
Chapter 3 Syntax, Errors, and Debugging Fundamentals of Java.
Lecture 5 1.What is a variable 2.What types of information are stored in a variable 3.Getting user input from the keyboard 1.
Asking the USER for values to use in a software 1 Input.
 2008 Pearson Education, Inc. All rights reserved JavaScript: Introduction to Scripting.
Introduction to Python Dr. José M. Reyes Álamo. 2 Three Rules of Programming Rule 1: Think before you program Rule 2: A program is a human-readable set.
Programming Fundamentals. Overview of Previous Lecture Phases of C++ Environment Program statement Vs Preprocessor directive Whitespaces Comments.
COIT29222 Structured Programming 1 COIT29222-Structured Programming Lecture Week 02  Reading: Textbook(4 th Ed.), Chapter 2 Textbook (6 th Ed.), Chapters.
Topic Review for Exam 1 0.Infrastructure: You must be able to use MATLAB, Blackboard Exams, and Blackboard submissions 1. Computer Developing algorithms.
Lecture 6: Output 1.Presenting results in a professional manner 2.semicolon, disp(), fprintf() 3.Placeholders 4.Special characters 5.Format-modifiers 1.
Part:2.  Keywords are words with special meaning in JavaScript  Keyword var ◦ Used to declare the names of variables ◦ A variable is a location in the.
© Copyright 1992–2004 by Deitel & Associates, Inc. and Pearson Education Inc. All Rights Reserved. 1 Chapter 2 - Introduction to C Programming Outline.
Introduction to Java Applications Part II. In this chapter you will learn:  Different data types( Primitive data types).  How to declare variables?
Gator Engineering Copyright © 2008 W. W. Norton & Company. All rights reserved. 1 Chapter 3 Formatted Input/Output.
1. COMPUTERS AND PROGRAMS Rocky K. C. Chang September 6, 2015 (Adapted from John Zelle’s slides)
1 Types of Programming Language (1) Three types of programming languages 1.Machine languages Strings of numbers giving machine specific instructions Example:
Review A program is… a set of instructions that tell a computer what to do. Programs can also be called… software. Hardware refers to… the physical components.
Unit 1 Review By: Mr. Jacobs.
CS0007: Introduction to Computer Programming Primitive Data Types and Arithmetic Operations.
1 Lecture 2 - Introduction to C Programming Outline 2.1Introduction 2.2A Simple C Program: Printing a Line of Text 2.3Another Simple C Program: Adding.
Chapter Topics The Basics of a C++ Program Data Types
Chapter 3 Syntax, Errors, and Debugging
Basic Elements of C++.
Basic Elements of C++ Chapter 2.
Introduction to C Programming
Presentation transcript:

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

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 + memory Screen=output Speakers=output Mouse=input Keyboard=input ? 2

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 3

Generations of Languages used to write software 1) Machine language – also called binary language. Sequence of 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. addb,c adda,b a= a + b + c; This line does the same as the two above. 4

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.” 5

Problem Solving Process 6 1.Problem Statement a.Diagram b.Assumptions 2.Solution Steps (manual solution) a.Theory / limitations b.Itemize specific steps (in order) as you solve the problem c.Identify results & verify accuracy 3.Computerize the solution a.Express the algorithm as steps general to any instance of the problem b.Translate the algorithm to lines of code c.Test and verify results

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.

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. 8

The keyword ans 9

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. 10

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:' 11

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! 1 st argument 2nd argument 12

Display with a specific format There are multiple ways to display the value of a variable 1.Use the semicolon appropriately 2.use the disp() built-in function 3.use the fprintf() built-in function Each is used for specific reasons 1.Debugging – finding problems with the code 2.Simple programs, simple results (the programmer’s use) 3.Formatted (“pretty”) output 13

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) 14

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 dollars/year and his age is 45. >>> 15

Vocabulary fprintf('The value in result is %f meters.', result); “function call” ‘format string’ “placeholder” (part of format string) variable to be printed 16

Most common placeholders Each data-type has a placeholder – Integer %d – Floats %f – Strings %s – A single letter %c 17

%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 e+003 dollars/year and his age is 45. >> 18

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 >> 19

Format Modifiers Once the base placeholder is ready, modifiers further change how the values are displayed. Complete Format Modifier form: _ _ _ _ _ _ _ %-7.2f Left-justify the value TOTAL width to occupy Nb. of decimal places _ _ _

Operators & Operands Operators work on operands. There are 2 types of operands: 1.Numerical 1, 3.5, Logical true, false Arithmetic operators ( +, -, /, *, ^ ) and relational operators (, >=, ==, ~= ) require numerical operands Boolean operators ( &&, ||, ~ ) require logical operands 21

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 22

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 y) 23

Operators: Output values TypeInput valuesOutput values Arithmetic: Numbers Numbers e.g. 5 * 315 Relational:NumbersLogical e.g. 5 < 3false Boolean:LogicalLogical e.g. ~truefalse 24

What is a function? A function is like a box with holes in it. 25 Input Output The _________ function Magic sinsqrtfloorrandbazingawhy

Exam 1: Review Questions 26

Review Questions Software & Hardware:  Provide a simple definition for software.  Is a DVD hardware or software? 27

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"? 28

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 29

Review Questions Developing Solutions: 30

Review Questions MATLAB Defaults:  What is ans ?  What does clear do?  What about clc ?  How do you suppress default output? 31

Data types:  Describe the following types of data: – Integers whole numbers – Floats numbers with fractional portion – Strings sequences of characters Review Questions 32

Review Questions MATLAB Layout:  What is the command window useful for? a)Performing quick commands to see results b)Everyday calculator operations c)Getting the help file of a specific built-in function d)Writing full scripts (Select all that apply) 33

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? 34

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? 35

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 If paycheck holds the value , what will be printed for the second placeholder? 2. If name holds the value 'Fred Flintstone', what will be printed for the first placeholder?

Review Questions Operators: Given the following operators: &, &&, |, ||, +, -, *, /, ~, <, =, ==  Identify the Boolean operators.  Identify the Relational operators  What about the other ones? 37

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–1 –0–0 – Logical expressions are not stored in the workspace 38

Review Questions Identify the parts – provide the name for the item or action: 39 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:

RUN home STUDY hard SLEEP well SHOW UP for the exam. Good Luck! How to prepare for Test 1 40