General Computer Science for Engineers CISC 106 Lecture 33 Dr. John Cavazos Computer and Information Sciences 05/11/2009.

Slides:



Advertisements
Similar presentations
Lecture Computer Science I - Martin Hardwick The Programming Process rUse an editor to create a program file (source file). l contains the text of.
Advertisements

Control Structures.
PHYS707: Special Topics C++ Lectures Lecture 2. Summary of Today’s lecture: 1.More data types 2.Flow control (if-else, while, do-while, for) 3.Brief introduction.
3. S/E with Control Structures 3.1 Relational Operators and Expressions 3.2 If and if-else Statements 3.3 The Type Double 3.4 Program Design with the While.
1 G54PRG Programming Lecture 1 Amadeo Ascó Adam Moore 6 Decision Making, Control Structures & Error Handling.
IntroductionIntroduction  Computer program: an ordered sequence of statements whose objective is to accomplish a task.  Programming: process of planning.
General Computer Science for Engineers CISC 106 Lecture 21 Dr. John Cavazos Computer and Information Sciences 04/10/2009.
General Computer Science for Engineers CISC 106 Lecture 28 Dr. John Cavazos Computer and Information Sciences 04/29/2009.
General Computer Science for Engineers CISC 106 Lecture 19 Dr. John Cavazos Computer and Information Sciences 04/06/2009.
C Programming Basics Lecture 5 Engineering H192 Winter 2005 Lecture 05
1 9/24/07CS150 Introduction to Computer Science 1 Relational Operators and the If Statement.
General Computer Science for Engineers CISC 106 Lecture 20 Dr. John Cavazos Computer and Information Sciences 04/08/2009.
1 CS 105 Lecture 4 Selection Statements Wed, Jan 26, 2011, 6:05 pm.
If Statements. COMP104 If / Slide 2 Three Program Structures * Sequence - executable statements which the computer processes in the given order * Choice.
General Computer Science for Engineers CISC 106 Lecture 34 Dr. John Cavazos Computer and Information Sciences 05/13/2009.
1 CS150 Introduction to Computer Science 1 Relational Operators and the If Statement 9/22/08.
CS 1400 Jan 2007 Chapter 4, sections Relational operators Less than< Greater than> Less than or equal= Equal== Not equal!=
General Computer Science for Engineers CISC 106 Lecture 05 Dr. John Cavazos Computer and Information Sciences 2/20/2009.
General Computer Science for Engineers CISC 106 Lecture 26 Dr. John Cavazos Computer and Information Sciences 04/24/2009.
The If/Else Statement, Boolean Flags, and Menus Page 180
Administrative MUST GO TO CORRECT LAB SECTION! Homework due 11:59pm on Tuesday. 25 points off if late (up to 24 hours) Cannot submit after 11:59pm on Wednesday.
Quiz 1 Exam 1 Next Week. Nested if Statements if (myGrade >= 80) if (myGrade >= 90) cout
CS 192 Lecture 3 Winter 2003 December 5, 2003 Dr. Shafay Shamail.
COMPUTER PROGRAMMING. Data Types “Hello world” program Does it do a useful work? Writing several lines of code. Compiling the program. Executing the program.
1 Conditions Logical Expressions Selection Control Structures Chapter 5.
Decision II. CSCE 1062 Outline  Boolean expressions  switch statement (section 4.8)
Semester Review. As we have discussed, Friday we will have in class time for you to work on a program, this program will come with instructions and you.
CPS120: Introduction to Computer Science Operations Lecture 9.
Chapter 5 Logic; Got Any?. Flow of Control The order in which the computer executes statements in a program Control Structure A statement used to alter.
COMPUTER PROGRAMMING. variable What is variable? a portion of memory to store a determined value. Each variable needs an identifier that distinguishes.
Switch Statements Comparing Exact Values. The Switch Statement: Syntax The switch statement provides another way to decide which statement to execute.
Computer Science 1620 boolean. Types so far: Integer char, short, int, long Floating Point float, double, long double String sequence of chars.
Chapter 7 Selection Dept of Computer Engineering Khon Kaen University.
Programming 1 DCT 1033 Control Structures I (Selection) if selection statement If..else double selection statement Switch multiple selection statement.
Variables and Data Types.  Variable: Portion of memory for storing a determined value.  Could be numerical, could be character or sequence of characters.
Copyright © 2002, Department of Systems and Computer Engineering, Carleton University CONTROL STRUCTURES Simple If: if (boolean exp) { statements.
Engineering H192 - Computer Programming Gateway Engineering Education Coalition Lect 5P. 1Winter Quarter C Programming Basics Lecture 5.
Lecture 7: Making Decisions Professor: Dr. Miguel Alonso Jr. Fall 2008 CGS2423/COP1220.
Computing and Statistical Data Analysis Lecture 2 Glen Cowan RHUL Physics Computing and Statistical Data Analysis Variables, types: int, float, double,
Glenn Stevenson CSIS 113A MSJC CSIS 113A Lecture 2.
School of Computer Science & Information Technology G6DICP - Lecture 4 Variables, data types & decision making.
Programming Fundamentals1 Chapter 4 SELECTION STRUCTURES.
CSC 107 – Programming For Science. Today’s Goal  Know how to write selections besides if-else  When each of the options makes sense  When each selection.
General Computer Science for Engineers CISC 106 Lecture 12 James Atlas Computer and Information Sciences 08/03/2009.
CPS120: Introduction to Computer Science Decision Making in Programs.
CPS120: Introduction to Computer Science Decision Making in Programs.
Lecture 6 – Selection FTMK, UTeM – Sem /2014.
CSE202: Lecture 5The Ohio State University1 Selection Structures.
C++ Programming: From Problem Analysis to Program Design, Fifth Edition Chapter 2: Control Structures (Selection & Repetition)
LECTURE # 7 : STRUCTURED PROGRAMMING Selection Statements Tr.Hadeel.
General Computer Science for Engineers CISC 106 Lecture 27 Dr. John Cavazos Computer and Information Sciences 04/27/2009.
Selection (if-then-else) Programming Has 3 Types of Control: Sequential (normal): Control of Execution Proceeds One after the Other Selection (if-then-else):
C++ Lesson 1.
Asst.Prof.Dr. Tayfun ÖZGÜR
CIS3931 – Intro to JAVA Lecture Note Set 2 17-May-05.
Introduction to C++ Programming Language
Programming Fundamentals
Reserved Words.
Introduction to Programming in Java
null, true, and false are also reserved.
Flow Control Statements
Summary Two basic concepts: variables and assignments Basic types:
If Statements.
By Hector M Lugo-Cordero September 3, 2008
Java Programming Review 1
Understanding Conditions
Decisions, decisions, decisions
Repetition Statements (Loops) - 2
Computer Programming Basics
General Computer Science for Engineers CISC 106 Lecture 15
Presentation transcript:

General Computer Science for Engineers CISC 106 Lecture 33 Dr. John Cavazos Computer and Information Sciences 05/11/2009

Lecture Overview More C++ Reserved words Function calling Relational/Logical Operators If statements Loops

C++ reserved words (keywords) Boolean: bool, true, false Types: char, float, int, unsigned, double, long Control flow: if, else, for, while, case, break Object Oriented: class, public, private, protected, new, delete, this Exceptions: try, catch, throw

Program with three functions

Relational Operators < (less than) <= (less than or equal to) > (greater than) >= (greater than or equal to) == (equal to) != (not equal to)

Logical Operators ! (Not) && (And) || (Or)

If Statements if (expression) statement1; else statement2; Note: Else part is optional!

Simple if statements if (age >= 18) cout << “Can vote.” << endl; if (songSize != 5) cout “Song is not equal to 5 megs” << endl;

Simple if statements if (songSize > 2 && songSize < 5) cout “Song is greater than 2 megs and less than 5 megs” << endl; if (!(songSize > 2 && songSize < 5)) cout “Song is less than or equal to 2 megs or greater than or equal to 5 megs” << endl;

Short Circuit example

Another short circuit example Protects from having a divide by zero error! If Number != 0 then number is not zero and we can divide 1 by number.

Beware of dangling else problem The else matches this if statement!

While Loops

For Loops