Slide1SummaryTwo basicconcepts:variablesand assignmentsBasictypes:int, double, char (string),...Some C++ practicalissues:division rule,operator precedence
Slide 1 Summary Two basic concepts: variables and assignments Basic types: int, double, char (string), . Some C++ practical issues: division rule, operator precedence
Slide2Expression and statementAnexpressionhasavaluewhichistheresultofsomeoperation(s)ontheassociatedoperands.x-y, 2-a-(b*c)Astatementisasentencethatactsasacommanditdoesnothaveavalueit always ends in a‘;"cin>>x;X=5;intx;
Slide 2 Expression and statement An expression has a value which is the result of some operation(s) on the associated operands. 4, x-y, 2-a-(b*c) A statement is a sentence that acts as a command it does not have a value it always ends in a ‘;’ cin >> x; x = 5; int x;
Boolean type and expressions
Boolean type and expressions
Slide4Boolean type: boolC++ contains a type (new!) named bool whichcanhave one of twovaluestrue (corresponding to non-zero value)false(correspondingtozerovalue)Boolean operatorsbool P = true;Logical and: &&bool Q = false;Logical or: IIbool R = true;boolS=P&&Q;Logical not: !boolT=(!Q)1IR;boolU=!(R&&!Q);Examples
Slide 4 Boolean type: bool C++ contains a type (new!) named bool which can have one of two values true (corresponding to non-zero value) false (corresponding to zero value) Boolean operators Logical and: && Logical or: || Logical not: ! Examples bool P = true; bool Q = false; bool R = true; bool S = P && Q; bool T = (!Q) || R; bool U = !(R && !Q);
Slide5Boolean expressionsArithmeticexpression:usearithmeticoperators+,*,l,toproduceanumberasthefinalresultA Booleanexpressionhasoneofthetwovalues:trueorfalseuserelationaloperators<,>,==,andbooleanoperatorsAND(&&),OR(l),NOT()
Slide 5 Boolean expressions Arithmetic expression: use arithmetic operators +,- ,*,/, to produce a number as the final result A Boolean expression has one of the two values: true or false use relational operators <,>, ==, . and boolean operators AND (&&), OR (||), NOT (!)