CISC/CMPE320 - Prof. McLeod

Slides:



Advertisements
Similar presentations
Control Structures Any mechanism that departs from straight-line execution: –Selection: if-statements –Multiway-selection: case statements –Unbounded iteration:
Advertisements

IntroductionIntroduction  Computer program: an ordered sequence of statements whose objective is to accomplish a task.  Programming: process of planning.
True or false A variable of type char can hold the value 301. ( F )
Bellevue University CIS 205: Introduction to Programming Using C++ Lecture 3: Primitive Data Types.
Selection Statements choice of one among several blocks of code Java supports 3 kinds of selection statements: if statement – selects one block or leaves.
Logical Operators Java provides two binary logical operators (&& and ||) that are used to combine boolean expressions. Java also provides one unary (!)
Logical Operators and Conditional statements
Tutorial 4 Decision Making with Control Structures and Statements Section A - Decision Making JavaScript Tutorial 4 -Decision Making with Control.
Boolean Expressions and If Flow of Control / Conditional Statements The if Statement Logical Operators The else Clause Block statements Nested if statements.
1 Conditions Logical Expressions Selection Control Structures Chapter 5.
Programming in Java (COP 2250) Lecture 11 Chengyong Yang Fall, 2005.
CSCI 1100/1202 January 28, The switch Statement The switch statement provides another means to decide which statement to execute next The switch.
CPS120: Introduction to Computer Science Decision Making in Programs.
Week 3 - Wednesday.  What did we talk about last time?  Other C features  sizeof, const  ASCII table  printf() format strings  Bitwise operations.
Copyright Curt Hill The C/C++ switch Statement A multi-path decision statement.
Fall 2015CISC/CMPE320 - Prof. McLeod1 CISC/CMPE320 Meet with your team later today in ELL321 at 6:30pm. Teams are listed on the Project page of the course.
 In the java programming language, a keyword is one of 50 reserved words which have a predefined meaning in the language; because of this,
Fall 2015CISC/CMPE320 - Prof. McLeod1 CISC/CMPE320 Managers and “mentors” identified on projects page. All member accounts created and projects populated.
Fall 2015CISC/CMPE320 - Prof. McLeod1 CISC/CMPE320 How did your team meetings go? A list of three possible “adoptable” projects is linked near the bottom.
Decision Statements, Short- Circuit Evaluation, Errors.
Java Basics. Tokens: 1.Keywords int test12 = 10, i; int TEst12 = 20; Int keyword is used to declare integer variables All Key words are lower case java.
Fall 2015CISC/CMPE320 - Prof. McLeod1 CISC/CMPE320 Reminders: Have you filled out the questionnaire in Moodle? (3 left – as of last night). Office hours.
Week 3 - Friday.  What did we talk about last time?  Preprocessor directives  Other C features  sizeof, const  ASCII table  printf() format strings.
Announcements Assignment 2 Out Today Quiz today - so I need to shut up at 4:25 1.
CS113 Introduction to C Instructor: Ioannis A. Vetsikas Lecture 2 : August 28 webpage:
Today… Python Keywords. Iteration (or “Loops”!) Winter 2016CISC101 - Prof. McLeod1.
Today… Preparation for doing Assignment 1. Invoking methods overview. Conditionals and Loops. Winter 2016CMPE212 - Prof. McLeod1.
Winter 2016CISC101 - Prof. McLeod1 CISC101 Reminders Quiz 3 next week. See next slide. Both versions of assignment 3 are posted. Due today.
Quiz 3 Topics Functions – using and writing. Lists: –operators used with lists. –keywords used with lists. –BIF’s used with lists. –list methods. Loops.
OPERATORS IN C CHAPTER 3. Expressions can be built up from literals, variables and operators. The operators define how the variables and literals in the.
CMSC201 Computer Science I for Majors Lecture 05 – Comparison Operators and Boolean (Logical) Operators Prof. Katherine Gibson Prof. Jeremy.
Week 3 - Friday CS222.
Selection (also known as Branching) Jumail Bin Taliba by
2.0 FUNDAMENTALS OF JAVA PROGRAMMING LANGUAGE
Selections Java.
Lecture 3- Decision Structures
EGR 2261 Unit 4 Control Structures I: Selection
CISC/CMPE320 - Prof. McLeod
Boolean Expressions and If
CISC/CMPE320 - Prof. McLeod
CISC/CMPE320 - Prof. McLeod
CISC/CMPE320 - Prof. McLeod
CISC/CMPE320 - Prof. McLeod
Control Structures – Selection
Character Set The character set of C represents alphabet, digit or any symbol used to represent information. Types Character Set Uppercase Alphabets A,
CISC101 Reminders Quiz 1 grading underway Assn 1 due Today, 9pm.
CISC101 Reminders Assn 3 due tomorrow, 7pm.
CISC/CMPE320 - Prof. McLeod
CISC/CMPE320 - Prof. McLeod
CISC124 Labs start this week in JEFF 155.
CISC/CMPE320 - Prof. McLeod
CISC124 Labs start this week in JEFF 155. Fall 2018
CISC/CMPE320 - Prof. McLeod
CISC/CMPE320 - Prof. McLeod
CISC/CMPE320 - Prof. McLeod
CISC/CMPE320 - Prof. McLeod
SE1H421 Procedural Programming LECTURE 4 Operators & Conditionals (1)
CISC/CMPE320 - Prof. McLeod
CMPE212 – Reminders The other four assignments are now posted.
CISC101 Reminders All assignments are now posted.
CS 240 – Lecture 7 Boolean Operations, Increment and Decrement Operators, Constant Types, enum Types, Precedence.
Winter 2019 CISC101 4/16/2019 CISC101 Reminders
CISC101 Reminders Quiz 1 marking underway.
Winter 2019 CISC101 4/28/2019 CISC101 Reminders
CISC/CMPE320 - Prof. McLeod
CISC/CMPE320 - Prof. McLeod
CprE 185: Intro to Problem Solving (using C)
CISC101 Reminders Assignment 3 due today.
Presentation transcript:

CISC/CMPE320 - Prof. McLeod Winter 2013 CISC/CMPE320 2/4/2019 CISC/CMPE320 Teams are assembled. They are listed on the project page. Make sure you are listed! Let me know if you are with someone that you cannot get along with (bloodshed might result…). Also, let me know of any spelling errors. And, if you are going to drop the course, do it soon, svp… Jira account creation is in progress. You will get an email that expires in 24 hours to login. Fall 2018 CISC/CMPE320 - Prof. McLeod Prof. Alan McLeod

CISC/CMPE320 - Prof. McLeod Today First team meeting today. Deliverables. C++: Finish Operator Precedence Bitwise Operations Boolean Expressions Conditionals and Loops string and vector classes from the STL: demos Fall 2018 CISC/CMPE320 - Prof. McLeod

Review - First Team Meeting Introduce each other -  Exchange contact info? Present your background/experience.  Which hardware/OS do you like to use for C++ development? Has each member read over and understood the projects page?  Do you know what the deliverables are and when they are due? Pick a notetaker for this meeting. Notetaker takes attendance and records any momentous decisions – is anyone missing?  Use Confluence to record notes and link them to an issue in Jira. Or, keep separate notes on paper or on a laptop and copy them into Confluence later. Fall 2018 CISC/CMPE320 - Prof. McLeod

First Team Meeting, Cont. Discuss project ideas – negotiate? Other meeting time(s) than just the tutorial time? If you do settle on a project idea, discuss it with your TA (your mentor) to see if it is too hard/too easy and just what might be involved with implementation. Write an “executive summary” to be sent to the CEO. Start thinking about two major roles that must be filled soon: Team Manager (or “Lead”) and Primary Software Architect. Start putting in your story line so you can build your first sprint! Fall 2018 CISC/CMPE320 - Prof. McLeod

Immediate Deliverables This week or next week, at the latest: Report a membership “deficiency” to your mentor or to the CEO. Choose a project topic. Choose a manager (or team lead). Optional: Choose an chief architect. Email the CEO with the name of the manager. Provide the CEO with an “executive summary” of your project concept by email. Add meeting notes (including attendance) to your team’s Confluence space. Fall 2018 CISC/CMPE320 - Prof. McLeod

CISC/CMPE320 - Prof. McLeod Notes on Precedence Prefix operators (~, !, -, &, *, pre-increment and pre-decrement) and assignment operators are right associative (right to left) – all others are left-associative (left to right). So: int a = b + c + d; Means int a = (b + c) + d; But, int x = y = z; Means int x = (y = z); (Yes, the assignment operator returns something!) Fall 2018 CISC/CMPE320 - Prof. McLeod

CISC/CMPE320 - Prof. McLeod Precedence Notes, Cont. Use ( ) to control precedence. When in doubt, control precedence! If an expression gets too long, use intermediate variables to make it more readable. Fall 2018 CISC/CMPE320 - Prof. McLeod

Bit and Shift Operations These operate on all integer types and enums. Complement, ~, carries out a bitwise negation of each bit (1 becomes 0, 0 becomes 1). Binary &, | and ^: A B A&B A|B A^B 1 Fall 2018 CISC/CMPE320 - Prof. McLeod

Bit and Shift Operations, Cont. The left shift operator, <<, moves all bits in val to the left by n positions: val << n. Zeros are added to the least significant bits. This is the same as multiplying a number by 2n. Right shift, >>, moves all bits to the right. For unsigned integers zeros are added to the most significant bits – same as dividing by 2n. For signed integers, the result is not predicable as the sign bit may be duplicated. Fall 2018 CISC/CMPE320 - Prof. McLeod

Bitwise Operations, Examples Set the nth bit in a number and the rest are zeros: 1 << n To set the nth bit of any number, x, and not change the rest: x = x | 1 << n To check to see if the nth bit is set: if ((x & 1 << n) != 0)… Fall 2018 CISC/CMPE320 - Prof. McLeod

CISC/CMPE320 - Prof. McLeod Boolean Expressions We have seen the boolean operators already. Here are a few notes: Something like a < b < c will compile and run, but may not produce the desired result. Better to use: a < b && b < c Remember that & and | are bitwise operators, not logical ones. Fall 2018 CISC/CMPE320 - Prof. McLeod

Boolean Expressions, Cont. The && and || logical operators use “short circuit evaluation”: For && if the LHS is false then the RHS is not evaluated. For || if the LHS is true then the RHS is not evaluated. (Same as in Java.) Fall 2018 CISC/CMPE320 - Prof. McLeod

Boolean Expressions, Cont. Non zero integers are treated as being true, and zero is treated as being false. (Ouch!) So, you can use logical operators, && || and !, with integers. For example, the code: int x = 10; if (x) is the same as: if (x != 0) Fall 2018 CISC/CMPE320 - Prof. McLeod

Boolean Expressions, Cont. Also, this is legal syntax: if (x = 10) The assignment operator returns the value being assigned, which in this case is a true! But suppose x is 12 and you really meant to type ==… Ouch, again! Fall 2018 CISC/CMPE320 - Prof. McLeod

Boolean Expressions, Cont. See TestStuff.cpp. Applying ! to a non-zero integer returns false or zero. An if statement will treat a pointer by itself as an integer – it will be true unless it is nullptr. You can also test assignment statements since the assignment operator returns the value being assigned. Fall 2018 CISC/CMPE320 - Prof. McLeod

Conditional Expressions C++ has if, if/else and switch. Syntax of if/else: if (boolean_expression) true_part else false_part Use { } to enclose more than one statement. Fall 2018 CISC/CMPE320 - Prof. McLeod

CISC/CMPE320 - Prof. McLeod switch Statement Same syntax as in Java: switch (expression) { case val1: // statements if expression produces val1 break; case val2: // statements if expression produces val2 case val3: … default: // statements if none of the above is true } // end switch Fall 2018 CISC/CMPE320 - Prof. McLeod

CISC/CMPE320 - Prof. McLeod switch Statement, Cont. expression must be an integer. The break statements are needed to prevent the next case statement from taking place if the one above it is true. The default is only executed if none of the other case blocks have executed. Fall 2018 CISC/CMPE320 - Prof. McLeod

The Conditional Operator int max = (n1 > n2) ? n1 : n2; Is the same as: int max; if (n1 > n2) max = n1 else max = n2 Which is easier to read? Fall 2018 CISC/CMPE320 - Prof. McLeod

CISC/CMPE320 - Prof. McLeod Loops Three types: while (condition) statement_or_block do while(condition); for(init; condition; expr) Fall 2018 CISC/CMPE320 - Prof. McLeod

CISC/CMPE320 - Prof. McLeod Goto C++ also has the infamous “goto” statement: goto identifier : …. identifier : statement Don’t use it! (Maybe use it to kick you completely out of a nested loop. break only kicks you out one level…) Fall 2018 CISC/CMPE320 - Prof. McLeod

CISC/CMPE320 - Prof. McLeod break and continue Work as they do in Java: break; spits you right out of the loop. continue; sends you back to the loop condition. Fall 2018 CISC/CMPE320 - Prof. McLeod

CISC/CMPE320 - Prof. McLeod As Promised Demos of the string and vector classes: StringDemo.cpp VectorDemo.cpp Much better than C-strings and arrays! Fall 2018 CISC/CMPE320 - Prof. McLeod