Instructor: Scott Kristjanson CMPT 135 SFU Surrey, Spring 2016

Slides:



Advertisements
Similar presentations
Making Choices in C if/else statement logical operators break and continue statements switch statement the conditional operator.
Advertisements

If Statements & Relational Operators Programming.
Slide 1 Summary Two basic concepts: variables and assignments Some C++ practical issues: division rule, operator precedence  Sequential structure of a.
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.
If Statements Sections 1.25, Control Structures o All code thus far executes every line of code sequentially o We want to be able to repeat,
If Statements. COMP104 If / Slide 2 Three Program Structures * Sequence - executable statements which the computer processes in the given order * Choice.
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.
The If/Else Statement, Boolean Flags, and Menus Page 180
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.
C++ Programming: Program Design Including Data Structures, Fourth Edition Chapter 13: Pointers, Classes, Virtual Functions, and Abstract Classes.
C++ Programming: From Problem Analysis to Program Design, Fourth Edition Chapter 14: Pointers, Classes, Virtual Functions, and Abstract Classes.
Review Chapters 1 to 4 Instructor: Scott Kristjanson CMPT 125/125 SFU Burnaby, Fall 2013.
More on Input Output Input Stream : A sequence of characters from an input device (like the keyboard) to the computer (the program running). Output Stream.
Liang, Introduction to Programming with C++, Second Edition, (c) 2010 Pearson Education, Inc. All rights reserved Chapter 3 Selections.
Dr. Yang, QingXiong (with slides borrowed from Dr. Yuen, Joe) LT3: Conditional Statements CS2311 Computer Programming.
Programming in Java (COP 2250) Lecture 11 Chengyong Yang Fall, 2005.
Computer Science 210 Computer Organization Introduction to Boolean Algebra.
Quiz Answers 1. Show the output from the following code fragment: int a = 5, b = 2, c = 3; cout
CPS120: Introduction to Computer Science Operations Lecture 9.
Chapter 5 Control Structure (Repetition). Objectives In this chapter, you will: Learn about repetition (looping) control structures Explore how to construct.
ECE122 Feb. 22, Any question on Vehicle sample code?
Programming Fundamental Slides1 Data Types, Identifiers, and Expressions Topics to cover here: Data types Variables and Identifiers Arithmetic and Logical.
Review the following: if-else One branch if Conditional operators Logical operators Switch statement Conditional expression operator Nested ifs if –else.
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.
1 09/15/04CS150 Introduction to Computer Science 1 Life is Full of Alternatives Part 2.
COMP102 – Programming Fundamentals I LA2B (Mon 5-7pm) LA2E (Fri 3-5pm) LA2F (Fri 5-7pm) TA: Jackie Lo.
Lecture 2 Conditional Statement. chcslonline.org Conditional Statements in PHP Conditional Statements are used for decision making. Different actions.
Today’s Topics Graded HW1 in Moodle (Testbeds used for grading are linked to class home page) HW2 due (but can still use 5 late days) at 11:55pm tonight.
Reviewing for the Midterm Covers chapters 1 to 5, 7 to 9 Instructor: Scott Kristjanson CMPT 125/125 SFU Burnaby, Fall 2013.
72 4/11/98 CSE 143 Abstract Data Types [Sections , ]
1 Review for Midterm 2 Aaron Bloomfield CS 101-E.
1 st Semester Module2 Basic C# Concept อภิรักษ์ จันทร์สร้าง Aphirak Jansang Computer Engineering.
CSE202: Lecture 5The Ohio State University1 Selection Structures.
Instructor: Scott Kristjanson CMPT 125/125 SFU Burnaby, Fall 2013
CSII Final Review. How many bits are in a byte? 8.
Selection (if-then-else) Programming Has 3 Types of Control: Sequential (normal): Control of Execution Proceeds One after the Other Selection (if-then-else):
 Type Called bool  Bool has only two possible values: True and False.
The Ohio State University
Chapter 3 Selection Statements
Computer Science 210 Computer Organization
University of Central Florida COP 3330 Object Oriented Programming
Chapter 13: Pointers, Classes, Virtual Functions, and Abstract Classes
Selection (also known as Branching) Jumail Bin Taliba by
Bill Tucker Austin Community College COSC 1315
A mechanism for deciding whether an action should be taken
University of Central Florida COP 3330 Object Oriented Programming
Data Types, Identifiers, and Expressions
Engineering Problem Solving with C++, Etter/Ingber
Computing with C# and the .NET Framework
Control Structures Combine individual statements into a single logical unit with one entry point and one exit point. Used to regulate the flow of execution.
Control Structures Combine individual statements into a single logical unit with one entry point and one exit point. Used to regulate the flow of execution.
Data Types, Identifiers, and Expressions
Boolean Logic Damian Gordon.
If statement.
Computers & Programming Languages
Summary Two basic concepts: variables and assignments Basic types:
If Statements.
SE1H421 Procedural Programming LECTURE 4 Operators & Conditionals (1)
Chapter 2 Programming Basics.
Understanding Conditions
Life is Full of Alternatives
Life is Full of Alternatives
EECE.2160 ECE Application Programming
Comparing Data & the ‘switch’ Statement
Comparing Data & the ‘switch’ Statement
CSE 206 Course Review.
Presentation transcript:

Instructor: Scott Kristjanson CMPT 135 SFU Surrey, Spring 2016 Midterm Solutions Instructor: Scott Kristjanson CMPT 135 SFU Surrey, Spring 2016

Question 1 x x x IF is a statement, not an expression. √ x x √ IF is a statement, not an expression. (x || y) is a valid boolean expression: x or y ++ operator only works on variables, not expressions like (a+b) WHILE is a statement too, not an expression. Conditional expressions with ?: are valid expressions

(A&&!B&&!C) || (!A&&B&&!C) || (!A&&!B&&C) Question 2 (A&&!B&&!C) || (!A&&B&&!C) || (!A&&!B&&C) A&&!B&&!C || !A&&B&&!C || !A&&!B&&C) Work out the logic one step at a time: True if A is true and B and C false => A==true && B==false && C==false => A && !B && !C also True if B is true and A and C false => B==true && A==false && C==false => B && !A && !C and True if C is true and A and B false => C==true && A==false && B==false => C && !A && !B No other cases Put the three cases together using OR Check precedence! && is higher precedence than || So no Need to add parenthesis But they add clarity Validate using a Truth Table: A B C A&&!B&&!C !A&&B&&!C !A&&!B&&C expr F T

Question 3 A Class is a blue print for an object. It defines a set of variables, methods, and interfaces but has no state and reserves no memory space for those variables. An Object is an instantiation of a Class and is assigned a new copy of any instance data associated with that class. It has both state and methods that operate on that state.

Question 4 A struct is an aggregation of data but defines no methods associated with that data. A Class defines both data and methods associated with managing that data. Class members are private by default. Struct members are public by default.

Question 5 F A E D C B

Question 6 (Write the output from executing the program here) a = 0 b = 201 c = 5 6 301 0 0

Nortel Corporate Presentation Question 7 int findMax(int arr[], int arrLen) { (Write the function implementation here) int max = 0; for(int i=0; i<arrLen; i++) if (arr[i] > max) max = arr[i]; return max; } © 2004 Nortel

Question 8 Coin(); bool flip(); bool heads; Coin::Coin() { srand(time(0)); // Seed rand() heads = ((rand()%2)==0); } bool Coin::flip() { heads = ((rand()%2)==0); return heads; }

Question 9 void BarGraph(ostream& outStream, int Production[], int prodLen) { (Write the code to implement BarGraph here) for(int i=0; i<prodLen; i++) { outStream << i << ": "; // NumStars equals Production/10 rounded to nearest 10 int numStars = (production[i]+5)/10; for(int j=0; j<numStars; j++) outStream << "*"; outStream << endl; }

Midterm Grade Distribution