If you did not do assignment 1, you are likely to be instructor dropped from the class...
If you haven't already, sign up for the class mailing list. I have already given instructions for account setup and information about project 1, in addition to having answered questions. And only list members can view the archives.
CS151 -- Administration Notice
You should have read Chapter 1 and most of chapter 2 by today!We are doing more of Chapter 2 today...
Remember, according to syllabus Quiz #1 is Thursday....
Project 1 is posted, and due next Friday, by midnight:
http://www.cs.unm.edu/~storm/C++/cs151_summer2001/Assignment1.html
CS151 -- Administration Notice
Skip Simple Loop Mechanisms in Chapter 2.4 for now...Syllabus has been updated...
http://www.cs.unm.edu/~storm/cs151_summer2001/syllabus.html
Flow of Control
Expressions, continued
- Operators on expressions
- Be aware of what each operator returns
- Combining operators
CS151 -- Shawn Stoffer
Flow of Control
Expressions, continued
- Operators on expressions
- Some operators appear to work on expressions
- Sometimes the compiler will warn, sometimes not
CS151 -- Shawn Stoffer
Flow of Control
Expressions, continued
- Be aware of what each operator returns
CS151 -- Shawn Stoffer
Flow of Control
Expressions, continued
- Combining operators
- 4 < x < 5?
- 4 < x && x < 5
vs.- 4 < x < 5
CS151 -- Shawn Stoffer
Flow of Control
Expressions, continued
- Combining operators
- Why is this wrong: 4 < x < 5?
- 4 < x returns boolean
so expansion gives us:
(true or false) < 5
CS151 -- Shawn Stoffer
Flow of Control
Expressions, continued
- Combining operators
- How does true or false relate to 5?
- true == 1
- false == 0
- therefore 4 < x < 5 is always true, because true or false are not greater than 5...
CS151 -- Shawn Stoffer
Flow of Control
- Combining Operators
- Operator Precedence:
- Special Operators
- Arithmetic operators
- Comparative operators
- Logical operators
- Assignment operator
- Ternary Conditional Operator
CS151 -- Shawn Stoffer
Flow of Control
- Combining Operators
- Operator Precedence:
- Special Operators
- ++,--,!
CS151 -- Shawn Stoffer
Flow of Control
- Combining Operators
- Operator Precedence:
- Arithmetic operators
- +,-
- *, /, %
CS151 -- Shawn Stoffer
Flow of Control
- Combining Operators
- Operator Precedence:
- Comparative operators
- <, >, <=, >=, ==, !=
CS151 -- Shawn Stoffer
Flow of Control
- Combining Operators
- Operator Precedence:
- Logical operators
- &&, ||
- careful here...the bitwise operators (&, |, ^) have greater precedence, so if you make a mistake and put these here, you will have more problems
CS151 -- Shawn Stoffer
Flow of Control
- Combining Operators
- Operator Precedence:
- Assignment operators
- =, +=, -=, *=, /=, %=, ...
CS151 -- Shawn Stoffer
Flow of Control
- Combining Operators
- Operator Precedence:
- Ternary Conditional Operator
- condition ? (if true):(if false)
CS151 -- Shawn Stoffer
Programming Style
- Braces
- Comments
- Indenting
- Reasons
CS151 -- Shawn Stoffer
Programming Style
- Braces
- if (condition) {
something;
}
CS151 -- Shawn Stoffer
Programming Style
- Braces
- if (condition)
{
something;
}
CS151 -- Shawn Stoffer
Programming Style
- Braces
- if (condition) { something; }
CS151 -- Shawn Stoffer
Programming Style
- Comments
- //
- /* comment */
- /*
* This is a
* long comment
*/
CS151 -- Shawn Stoffer
Programming Style
- Comments
- Informative, not merely explanatory
- x = 4; /* set x equal to 4 */ // <--- bad!!!
- x *= .25; /* convert x from gallons to quarts. */ // good!!
CS151 -- Shawn Stoffer
Programming Style
- Indenting
- Readability
- if (condition) {
something;
something else;
}
CS151 -- Shawn Stoffer
Programming Style
- Reasons
- Remember, art or science?
- Readability
- Others reading your program
- i.e. make my life difficult, I will make yours so as well...
- maintenance
CS151 -- Shawn Stoffer