Exam 1 Review - 10/3/10 Review: C+ Fundamentals ENGR 101: 4...

Info iconThis preview shows pages 1–7. Sign up to view the full content.

View Full Document Right Arrow Icon
10/3/10 1 Review: C++ Fundamentals ENGR 101: 4 Oct 10 Where We’ve Been Algorithms (what it’s all about) A high-level programming language: C++ Data types and declaration Expression statements Operators: Arithmetic, Assignment, Input/Output, Relational, Logical Functions and procedures Stream and file input/output Iteration Selection
Background image of page 1

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
10/3/10 2 What is an Algorithm? A precise specification of a computational process . what computers do involves calculation operates over time result: solve a problem perform a task unambiguous can be executed mechanically structured set of instructions Caller Algorithm A Data Exchange Data is exchanged between the algorithm and its caller. Recall definition: An algorithm transforms input to output. Every algorithm specification includes provisions to accept input and provide output to the caller. Data Data Data input output
Background image of page 2
10/3/10 3 Algorithm Control Constructs Sequence Selection Iteration Greatest Common Factor 1: Request a value for a 2: Request a value for b 3: if a b then assign b to c 4: if a < b then assign a to c 5: while (remainder( a , c ) 0 OR remainder( b , c ) 0) 6: subtract one from c 7: return c 8: end Creating and Compiling a C++ Program 1. Invoke the text editor via the OS 2. Create a text file containing the program: project1.cpp 3. Run the compiler with project1.cpp as input; output is executable project1 4. Invoke project1 (via the OS) programmer Text Editor Compiler OS (Linux) project1.cpp project1
Background image of page 3

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
10/3/10 4 Statements The computations in a program are organized into statements . The heart of our example program includes a declaration statement and three expression statements . Every C++ statement ends in a semicolon. #include <iostream> using namespace std; int main ( ) { double x, y; cin >> x; y = x * 7; cout << y; return 0; } ; C++ Declaration Simple declarations are of the form: simple_type identifiers ; simple_type is a symbol specifying a type identifiers is a comma-separated list of identifiers In our example, we introduce the identifiers x and y, and declare that they are of type double . The type double is one of several numeric data types supported by C++. double x, y;
Background image of page 4
10/3/10 5 We can create compound expressions by applying operators to (atomic) expressions. For example, 5+x is a compound expression with operator + and operands 5 and x . Unary operator: has one operand Binary operator: has two operands New compound expression Compound Expressions operator exp1 exp2 Arithmetic Operators Operator Meaning Arity Placement Precedence sign change unary prefix 15 * multiplication binary infix 13 / real division binary infix 13 / integer division binary infix 13 % remainder binary infix 13 + addition binary infix 12 subtraction binary infix 12 Holloway Table 2.1
Background image of page 5

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
10/3/10 6 More Operators Operators are not just for arithmetic
Background image of page 6
Image of page 7
This is the end of the preview. Sign up to access the rest of the document.

This note was uploaded on 05/25/2011 for the course ENGR 101 taught by Professor Ringenberg during the Fall '07 term at University of Michigan.

Page1 / 24

Exam 1 Review - 10/3/10 Review: C+ Fundamentals ENGR 101: 4...

This preview shows document pages 1 - 7. Sign up to view the full document.

View Full Document Right Arrow Icon
Ask a homework question - tutors are online