《C++程序设计》(英文版) Chapter 5 Topics

Programming in c++ Conditions, Logical EXpressions and the Selection Control Structures Dale/eems/Headington
1 Conditions, Logical Expressions, and the Selection Control Structures

Programming in C++ Chapter 5 Topics Data Type bool % Using Relational and Logical Operators to Construct and Evaluate Logical Expressions oIfThen-Else Statements %If-Then Statements Nested If Statements for Multi-way Branching Testing the State of an I/O Stream Testing a C++ Program
2 Chapter 5 Topics ❖Data Type bool ❖Using Relational and Logical Operators to Construct and Evaluate Logical Expressions ❖If-Then-Else Statements ❖If-Then Statements ❖Nested If Statements for Multi-way Branching ❖Testing the State of an I/O Stream ❖Testing a C++ Program

Programming in C++ Flow of Control &the order in which program statements are executed WHAT ARE THE POSSIBILITIES
3 Flow of Control ❖the order in which program statements are executed WHAT ARE THE POSSIBILITIES. .

Programming in C++ Flow of Control is Sequential unless a control structure'is used to change that o there are 2 general types of control structures Selection(also called branching) Repetition (also called looping)
4 Flow of Control ❖is Sequential unless a “control structure” is used to change that ❖there are 2 general types of control structures: Selection (also called branching) Repetition (also called looping)

Programming in C++ C++ control structures Selection ff else switch Repetition for loop while loop do. while loop
5 C++ control structures ❖Selection if if . . . else switch ❖Repetition for loop while loop do . . . while loop

Programming in C++ Logic EXpression >Alogic expression(Boolean expression) is made up of logical values and operations )Every logical expression has one of two values: true or false. > Here are some examples i A Boolean variable or constant iAn expression followed by a relational operator followed by an expression ii. A logical expression followed by a logical operator followed by a logical expression
6 Logic Expression ➢A logic expression (Boolean expression) is made up of logical values and operations. ➢Every logical expression has one of two values: true or false. ➢Here are some examples: i. A Boolean variable or constant ii.An expression followed by a relational operator followed by an expression iii. A logical expression followed by a logical operator followed by a logical expression

Programming in C++ bool Data Type type bool is a built-in type consisting of just 2 values, the constants true and false True and false are reserved words in C++, not variable names or string owe can declare variables of type bool bool hasFever; // true if has high temperature bool isSenior; //true if age is at least 55
7 bool Data Type ❖type bool is a built-in type consisting of just 2 values, the constants true and false ❖True and false are reserved words in C++, not variable names or string ❖we can declare variables of type bool bool hasFever; // true if has high temperature bool isSenior; // true if age is at least 55

Programming in C++ The operators used in logical expressions )6 Relational Operators )3 Logical Operators &1
8 The operators used in logical expressions ➢6 Relational Operators >= == != ➢3 Logical Operators ! && ||

Programming in C++ 6 Relational Operators are used In expressions of form. ExpressionA Operator EXpression B For example: temperature humidity B*B-4.0*A*C>0.0 abs(number 35 initial Q
9 are used in expressions of form: ExpressionA Operator ExpressionB For example: temperature > humidity B * B - 4.0 * A * C > 0.0 abs (number ) == 35 initial != ‘Q’ 6 Relational Operators

Programming in C++ int x, y: X=4 y=6; EXPRESSION VALUE x=y true y==X false y==x+2 true y=x+3 7(true) aution: Don't confuse the assignment operator() and the relational operator (= 10
10 int x, y ; x = 4; y = 6; EXPRESSION VALUE x = y true y == x false y == x+2 true y = x + 3 7 (true) Caution: Don’t confuse the assignment operator (=) and the relational operator (==)
按次数下载不扣除下载券;
注册用户24小时内重复下载只扣除一次;
顺序:VIP每日次数-->可用次数-->下载券;
- 《C++程序设计》(英文版) Chapter 4 Topics.ppt
- 《C++程序设计》(英文版) Chapter 3 Topics.ppt
- 《C++程序设计》(英文版) Chapter 2 Topics.ppt
- 《C++程序设计》(英文版) Chapter 1 Topics.ppt
- 《网络互连技术教程》第9章 广播.ppt
- 《网络互连技术教程》第8章 用户数据报协议—UDP.ppt
- 《网络互连技术教程》第7章 CMP和网络状态.ppt
- 《网络互连技术教程》第6章 地址解析.ppt
- 《网络互连技术教程》第5章 子网与超网.ppt
- 《网络互连技术教程》第4章 网络互连协议——IP.ppt
- 《网络互连技术教程》第3章 网络接入技术.ppt
- 《网络互连技术教程》第2章 网络互连体系.ppt
- 《网络互连技术教程》第1章 网络的历史与发展.ppt
- 《网络互连技术教程》第12章 应用服务.ppt
- 《网络互连技术教程》第11章 域名服务系统—DNS.ppt
- 《网络互连技术教程》第10章 传输控制协议—7CP.ppt
- 高职高专课程:《数据库应用技术(SQL SERVER2000)》电子教案(PPT教学课件)第9章 存储过程与触发器.ppt
- 高职高专课程:《数据库应用技术(SQL SERVER2000)》电子教案(PPT教学课件)第8章 视图及其应用.ppt
- 高职高专课程:《数据库应用技术(SQL SERVER2000)》电子教案(PPT教学课件)第7章 索引及其应用.ppt
- 高职高专课程:《数据库应用技术(SQL SERVER2000)》电子教案(PPT教学课件)第6章 SQL Server 2000 数据完整性.ppt
- 《C++程序设计》(英文版) Chapter 6 Topics.ppt
- 《C++程序设计》(英文版) Chapter 7 Topics.ppt
- 《C++程序设计》(英文版) Chapter 8 Topics.ppt
- 《C++程序设计》(英文版) Chapter 9 Topics.ppt
- 《C++程序设计》(英文版) Chapter 10 Topics.ppt
- 《C++程序设计》(英文版) Chapter 11 Topics.ppt
- 《C++程序设计》(英文版) Chapter 12 Topic.ppt
- 《C++程序设计》(英文版) Chapter 13 Topics.ppt
- 《C++程序设计》(英文版) Chapter 14 Topics.ppt
- 《C++程序设计》(英文版) Chapter 15 Topics.ppt
- 《Java编程技术基础》第一章 面向对象原理与实现.ppt
- 《Java编程技术基础》第二章 Java的实现基础.ppt
- 《Java编程技术基础》第二章习题.doc
- 《Java编程技术基础》第三章 类与对象(一).ppt
- 《Java编程技术基础》第三章习题.doc
- 《Java编程技术基础》第四章 类与对象(二).ppt
- 《Java编程技术基础》第四章习题.doc
- 《Java编程技术基础》第五章 异常与垃圾收集.ppt
- 《Java编程技术基础》第五章习题.doc
- 《Java编程技术基础》第十一章 Java集合框架.ppt