Section 3 Review Mr. Crone.

Slides:



Advertisements
Similar presentations
Operator Overloading Fundamentals
Advertisements

Basic Control Structures Control order of execution of statements sequential selection iteration - Repeat some action while a certain condition is true.
If Statements & Relational Operators Programming.
1 Powers of Two: Trace Ex. Print powers of 2 that are  2 N. Increment i from 0 to N. Double v each time. int i = 0; int v = 1; while (i
Lecture 071 CS 192 Lecture 7 Winter 2003 December 15-16, 2003 Dr. Shafay Shamail.
Slide 1 Summary Two basic concepts: variables and assignments Some C++ practical issues: division rule, operator precedence  Sequential structure of a.
Friday, December 08, 2006 “Experience is something you don't get until just after you need it.” - Olivier.
1 9/29/06CS150 Introduction to Computer Science 1 Loops Section Page 255.
1 9/24/07CS150 Introduction to Computer Science 1 Relational Operators and the If Statement.
1 9/26/08CS150 Introduction to Computer Science 1 Logical Operators and if/else statement.
Computer Science 1620 Accumulators. Recall the solution to our financial program: #include using namespace std; int main() { double balance = ;
CS150 Introduction to Computer Science 1
1 CS150 Introduction to Computer Science 1 Arithmetic Operators.
1 9/25/06CS150 Introduction to Computer Science 1 Nested Ifs, Logical Operators, exit() Page 194.
Compound Operators 03/07/11. More Operators, First Section 4.4.
1 CS150 Introduction to Computer Science 1 Relational Operators and the If Statement 9/22/08.
Thursday, December 14, 2006 “Would you tell me, please, which way I ought to go from here?” “That depends a good deal on where you want to get to,” said.
1 9/28/07CS150 Introduction to Computer Science 1 Logical Operators and if/else statement.
Quiz 1 Exam 1 Next Week. Nested if Statements if (myGrade >= 80) if (myGrade >= 90) cout
C++ Operators CS242 COMPUTER PROGRAMMING T.Banan Al-Hadlaq.
M. Taimoor Khan #include void main() { //This is my first C++ Program /* This program will display a string message on.
CS31: Introduction to Computer Science I Discussion 1A 4/9/2010 Sungwon Yang
Windows Programming, C.-S. Shieh, KUAS EC, Chapter 3 Operators and Expressions.
Chapter 4 Loops Write code that prints out the numbers Very often, we want to repeat a (group of) statement(s). In C++, we have 3 major ways of.
Chapter 3. Outline Relational Operators Loops Decisions Logical Operators Precedence Summary.
1 Compound Assignment C++ has a large set of operators for applying an operation to an object and then storing the result back into the object Examples.
Liang, Introduction to C++ Programming, (c) 2007 Pearson Education, Inc. All rights reserved X1 Chapter 3 Control Statements.
1 09/15/04CS150 Introduction to Computer Science 1 Life is Full of Alternatives Part 2.
Programming 1 DCT 1033 Control Structures I (Selection) if selection statement If..else double selection statement Switch multiple selection statement.
1 © 2002 John Urrutia. All rights reserved. Qbasic Chapter 4 IF Statements and READ & DATA.
CHAPTER 1.3 THE OPERATORS Dr. Shady Yehia Elmashad.
Data Types Declarations Expressions Data storage C++ Basics.
Overview Go over parts of quiz? Another iteration structure for loop.
Selection Control Structures (L08) * Selection Criteria * if Statements * The if-else Statement Selection Control Structure Dr. Ming Zhang.
1 For Loops l From Chapter 9 l A shorthand way of coding count loops.
A: A: double “4” A: “34” 4.
Fundamental Programming Fundamental Programming More Expressions and Data Types.
What are Operators? Some useful operators to get you started.
STRUCTURED PROGRAMMING C++ Operators. Content 2  C++ operators  Assignment operators  Arithmetic operators  Increment and decrement operators  Decision.
Literals A literal (sometimes called a constant) is a symbol which evaluates to itself, i.e., it is what it appears to be. Examples: 5 int literal
Operators A binary operator combines two values to get one result: x OP y where OP is any binary operators such as +, -, *, /, ==, !=, >, &&, or even =.
LECTURE # 6 : STRUCTURED PROGRAMMING C++ OPERATORS By Mr. Ali Edan.
 By the end of this section you should be able to: ◦ Differentiate between sequence, selection, and repetition structure. ◦ Differentiae between single,
 2006 Pearson Education, Inc. All rights reserved if…else Double-Selection Statement if – Performs action if condition true if…else – Performs.
Rational Expressions relational operators logical operators order of precedence.
T/F  The following code will compile without error. int x = 3, y = 4, z = 5; double k = 3.4; cout
Branching statements.
Chapter 3 Selection Statements
Chapter 3 Control Statements
Data Types and Expressions
Chapter 7: Expressions and Assignment Statements
Rational Expressions. relational operators. logical operators
A mechanism for deciding whether an action should be taken
Chapter 2 Assignment and Interactive Input
Chapter 7: Expressions and Assignment Statements
Bools & Ifs.
Operators and Expressions
Expression Review what is the result and type of these expressions?
البرمجة بلغة الفيجول بيسك ستوديو
אבני היסוד של תוכנית ב- C++
Bools & Ifs.
Summary Two basic concepts: variables and assignments Basic types:
Operator Overloading.
If Statements.
Engineering Problem Solving with C++ An Object Based Approach
Engineering Problem Solving with C++ An Object Based Approach
Fundamental Programming
CS 101 First Exam Review.
Operator and Expression
HNDIT11034 More Operators.
Presentation transcript:

Section 3 Review Mr. Crone

True or false? bool x = true; int y = 5, z = 6; (y > z && x )

True or false? bool x = true; int y = 5, z = 6; (y > z && x ) // F

True or false? bool x = true; int y = 5, z = 6; (y > z || !x )

True or false? bool x = true; int y = 5, z = 6; (y > z || !x ) // False!

True or false? bool x = true, y = false, z = false (x && !y && !z)

True or false? bool x = true, y = false, z = false (x && !y && !z) True!

What does the code print? int x = 4, y = 2, z = 1; if(y ==2) if( z ==1) x += 6; else x =4; x += 8; cout << x << endl;

What does the code print? int x = 4, y = 2, z = 1; if(y ==2) // True if( z ==1) // True x += 6; // x = 10 else x =4; x += 8; cout << x << endl;

What does the code print? int x = 54; if(x>= 5 && x <= 100) x = 4; else x = 5; cout << x << endl;

What does the code print? int x = 54; if(x>= 5 && x <= 100) // True x = 4; // x = 4 else x = 5; cout << x << endl; // 4

What does the code print? bool var = true; bool var2 = false; if( !(!var && var2)) cout << “1”; else cout << “2”;

What does the code print? bool var = true; bool var2 = false; if( !(!var && var2)) // True cout << “1”; // Prints 1 else cout << “2”;

What does the code print? int x = 14; if(x < 10) cout << “1”; if (x > 10) cout << “2”; if ( x >10 && x < 20) cout << “3”; if(x ==10 || x ==14) cout << “4”;

What does the code print? int x = 14; if(x < 10) // false cout << “1”; if (x > 10) // true cout << “2”; if ( x >10 && x < 20) // true cout << “3”; if(x ==10 || x ==14) // true cout << “4”; Prints: 234

int x = 4; bool var = true; if( var) cout << “1” ; else if(x==4) cout << “2” ; else if (x ==4 && var) cout << “3”; else cout << “4”;

What does the code print? int x = 4; bool var = true; if( var)// true cout << “1” ; // Prints 1 else if(x==4) cout << “2” ; else if (x ==4 && var) cout << “3”; else cout << “4”;

True or False? bool var = false; bool var2 = true; cout << (24/4%4>1 || !var && var2) << endl;

True or False? Prints: 1 bool var = false; bool var2 = true; 24/4%4>1 || !var && var2 6 % 4 > 1 || T 2 > 1 || T True || T True Prints: 1

const int RADIUS = 3. 14; double num = 5. 5; bool x = false; if( const int RADIUS = 3.14; double num = 5.5; bool x = false; if(!x) RADIUS += 4; else num= 17; cout << num << endl;

const int RADIUS = 3. 14; // ERROR. double num = 5 const int RADIUS = 3.14; // ERROR! double num = 5.5; bool x = false; if(!x) RADIUS += 4; // ERROR! else num= 17; cout << num << endl;

int x = 4, y = 5; bool isWorking = false; if(x> 0&& y > 0) isWorking = true; if(isWorking) x = 5; cout << x << y << endl;

int x = 4, y = 5; bool isWorking = false; if(x> 0&& y > 0) // True isWorking = true; if(isWorking) // True x = 5; cout << x << y << endl; // 55

int x = 4, y = 5; bool isWorking = false; if(x<y) if(isWorking) isWorking = false; else isWorking = true; y = 20; cout << isWorking << endl;

int x = 4, y = 5; bool isWorking = false; if(x<y) if(isWorking) isWorking = false; else isWorking = true; y = 20; cout << isWorking << endl; // Prints 1

int x = 4; double y = 2. 5; int yx = 3; cout << ((2 int x = 4; double y = 2.5; int yx = 3; cout << ((2*x)/3 < yx && 2 == int(y));

int x = 4; double y = 2. 5; int yx = 3; cout << ((2 int x = 4; double y = 2.5; int yx = 3; cout << ((2*x)/3 < yx && 2 == int(y)); // 8/3 < 3 && 2 == 2 // 2 < 3 && 2 ==2 // TRUE

List the logical operators in order of precedence with the operator with the highest precedence being listed first.

List the logical operators in order of precedence with the operator with the highest precedence being listed first. !, &&, ||

Provide two examples of unary operators.

Provide two examples of unary operators. ++, --, !

What is the decimal equivalent of the following binary number? 110100

What is the decimal equivalent of the following binary number? 110100 52

Operator Review Relational Operators: <, >, <=, >=, ==, != Logical Operators: !, &&, || Assignment Operator: = Shortcut Assignment Operators: +=, -=, /=, *=, %= Increment Operator: ++ Decrement Operator: -- Arithmetic Operators: +, -, *, /, % Unary Operators (operator on one item): -, !, ++, -- ** Know when to use == vs. =