🗊Презентация C++ Programming

Нажмите для полного просмотра!
C++ Programming, слайд №1C++ Programming, слайд №2C++ Programming, слайд №3C++ Programming, слайд №4C++ Programming, слайд №5C++ Programming, слайд №6C++ Programming, слайд №7C++ Programming, слайд №8C++ Programming, слайд №9C++ Programming, слайд №10C++ Programming, слайд №11C++ Programming, слайд №12C++ Programming, слайд №13C++ Programming, слайд №14C++ Programming, слайд №15C++ Programming, слайд №16C++ Programming, слайд №17C++ Programming, слайд №18C++ Programming, слайд №19C++ Programming, слайд №20C++ Programming, слайд №21C++ Programming, слайд №22C++ Programming, слайд №23C++ Programming, слайд №24C++ Programming, слайд №25C++ Programming, слайд №26C++ Programming, слайд №27C++ Programming, слайд №28C++ Programming, слайд №29C++ Programming, слайд №30C++ Programming, слайд №31C++ Programming, слайд №32C++ Programming, слайд №33C++ Programming, слайд №34C++ Programming, слайд №35C++ Programming, слайд №36C++ Programming, слайд №37C++ Programming, слайд №38C++ Programming, слайд №39C++ Programming, слайд №40C++ Programming, слайд №41C++ Programming, слайд №42C++ Programming, слайд №43C++ Programming, слайд №44C++ Programming, слайд №45C++ Programming, слайд №46C++ Programming, слайд №47C++ Programming, слайд №48C++ Programming, слайд №49C++ Programming, слайд №50C++ Programming, слайд №51C++ Programming, слайд №52C++ Programming, слайд №53C++ Programming, слайд №54C++ Programming, слайд №55C++ Programming, слайд №56C++ Programming, слайд №57C++ Programming, слайд №58C++ Programming, слайд №59C++ Programming, слайд №60C++ Programming, слайд №61C++ Programming, слайд №62C++ Programming, слайд №63C++ Programming, слайд №64C++ Programming, слайд №65C++ Programming, слайд №66C++ Programming, слайд №67C++ Programming, слайд №68C++ Programming, слайд №69C++ Programming, слайд №70C++ Programming, слайд №71C++ Programming, слайд №72C++ Programming, слайд №73C++ Programming, слайд №74C++ Programming, слайд №75C++ Programming, слайд №76C++ Programming, слайд №77C++ Programming, слайд №78C++ Programming, слайд №79C++ Programming, слайд №80C++ Programming, слайд №81C++ Programming, слайд №82C++ Programming, слайд №83C++ Programming, слайд №84C++ Programming, слайд №85C++ Programming, слайд №86C++ Programming, слайд №87C++ Programming, слайд №88C++ Programming, слайд №89C++ Programming, слайд №90C++ Programming, слайд №91C++ Programming, слайд №92C++ Programming, слайд №93C++ Programming, слайд №94C++ Programming, слайд №95C++ Programming, слайд №96C++ Programming, слайд №97C++ Programming, слайд №98C++ Programming, слайд №99C++ Programming, слайд №100C++ Programming, слайд №101C++ Programming, слайд №102C++ Programming, слайд №103

Содержание

Вы можете ознакомиться и скачать презентацию на тему C++ Programming. Доклад-сообщение содержит 103 слайдов. Презентации для любого класса можно скачать бесплатно. Если материал и наш сайт презентаций Mypresentation Вам понравились – поделитесь им с друзьями с помощью социальных кнопок и добавьте в закладки в своем браузере.

Слайды и текст этой презентации


Слайд 1





C++ Programming
Jingping Li
(Simon)	
xxtjingping@buu.edu.cn
Описание слайда:
C++ Programming Jingping Li (Simon) xxtjingping@buu.edu.cn

Слайд 2





Introduction	
Procedural, Structured, and Object-Oriented Programming
Procedural or Structured
A computer program can be thought of as consisting of a set of tasks.
Structured programming remains an enormously successful approach for dealing with complex problems.
Описание слайда:
Introduction Procedural, Structured, and Object-Oriented Programming Procedural or Structured A computer program can be thought of as consisting of a set of tasks. Structured programming remains an enormously successful approach for dealing with complex problems.

Слайд 3





Introduction
First, it is natural to think of your data (employee records, for example) and what you can do with your data (sort, edit, and so on) as related ideas.
Second, programmers found themselves constantly reinventing new solutions to old problems.
Event-driven
means that an event happens--the user presses a button or chooses from a menu--and the program must respond.
Описание слайда:
Introduction First, it is natural to think of your data (employee records, for example) and what you can do with your data (sort, edit, and so on) as related ideas. Second, programmers found themselves constantly reinventing new solutions to old problems. Event-driven means that an event happens--the user presses a button or chooses from a menu--and the program must respond.

Слайд 4





Introduction
object-oriented programming (OOP)is to treat data and the procedures that act upon the data as a single "object"--a self-contained entity with an identity and certain characteristics of its own.
"data controlling access to code”
Описание слайда:
Introduction object-oriented programming (OOP)is to treat data and the procedures that act upon the data as a single "object"--a self-contained entity with an identity and certain characteristics of its own. "data controlling access to code”

Слайд 5





C++ and Object-Oriented Programming
C++ fully supports object-oriented programming, including the four pillars of object-oriented development: encapsulation, data hiding, inheritance, and polymorphism.
With encapsulation, we can accomplish data hiding. Data hiding is the highly valued characteristic that an object can be used without the user knowing or caring how it works internally.
Описание слайда:
C++ and Object-Oriented Programming C++ fully supports object-oriented programming, including the four pillars of object-oriented development: encapsulation, data hiding, inheritance, and polymorphism. With encapsulation, we can accomplish data hiding. Data hiding is the highly valued characteristic that an object can be used without the user knowing or caring how it works internally.

Слайд 6





C++ and Object-Oriented Programming
C++ supports the idea of reuse through inheritance.
A new type, which is an extension of an existing type, can be declared. This new subclass is said to derive from the existing type and is sometimes called a derived type.
different objects do "the right thing" through what is called function polymorphism and class polymorphism.
Описание слайда:
C++ and Object-Oriented Programming C++ supports the idea of reuse through inheritance. A new type, which is an extension of an existing type, can be declared. This new subclass is said to derive from the existing type and is sometimes called a derived type. different objects do "the right thing" through what is called function polymorphism and class polymorphism.

Слайд 7





Creating an Executable File
The steps to create an executable file are
1. Create a source code file, with a .CPP extension(txt file).
2. Compile the source code into a file with the .OBJ extension(binary file).
3. Link your OBJ file with any needed libraries to produce an executable program.
Описание слайда:
Creating an Executable File The steps to create an executable file are 1. Create a source code file, with a .CPP extension(txt file). 2. Compile the source code into a file with the .OBJ extension(binary file). 3. Link your OBJ file with any needed libraries to produce an executable program.

Слайд 8





First program
1: #include <iostream.h>
2:
3: int main()
4: {
5: cout << "Hello World!\n";
6: return 0;
7: }
Note: COMPILE---LINK---RUN
Описание слайда:
First program 1: #include <iostream.h> 2: 3: int main() 4: { 5: cout << "Hello World!\n"; 6: return 0; 7: } Note: COMPILE---LINK---RUN

Слайд 9





Question and answer
Описание слайда:
Question and answer

Слайд 10





parts of a C++ program
1: #include <iostream.h>
2:
3: int main()
4: {
5: cout << "Hello World!\n";
6: return 0;
7: }
Описание слайда:
parts of a C++ program 1: #include <iostream.h> 2: 3: int main() 4: { 5: cout << "Hello World!\n"; 6: return 0; 7: }

Слайд 11





A Brief Look at cout
Описание слайда:
A Brief Look at cout

Слайд 12





Comments----before function
/****************************************************
Program: Hello World
File: Hello.cpp
Function: Main (complete program listing in this file)
Description: Prints the words "Hello world" to the screen
Author: Jesse Liberty (jl)
Environment: Turbo C++ version 4, 486/66 32mb RAM, Windows 3.1
DOS 6.0. EasyWin module.
*******************************************************/
Описание слайда:
Comments----before function /**************************************************** Program: Hello World File: Hello.cpp Function: Main (complete program listing in this file) Description: Prints the words "Hello world" to the screen Author: Jesse Liberty (jl) Environment: Turbo C++ version 4, 486/66 32mb RAM, Windows 3.1 DOS 6.0. EasyWin module. *******************************************************/

Слайд 13





Variable
How to declare and define variables and constants.
The role of a variable in programm.
How to assign values to variables and manipulate those values.--- variable's name
How to write the value of a variable to the screen.
Описание слайда:
Variable How to declare and define variables and constants. The role of a variable in programm. How to assign values to variables and manipulate those values.--- variable's name How to write the value of a variable to the screen.

Слайд 14





Enumerated Constants
Enumerated constants enable you to create new types and then to define variables of those types whose values are restricted to a set of possible values.
enum COLOR { RED, BLUE, GREEN, WHITE, BLACK };
Описание слайда:
Enumerated Constants Enumerated constants enable you to create new types and then to define variables of those types whose values are restricted to a set of possible values. enum COLOR { RED, BLUE, GREEN, WHITE, BLACK };

Слайд 15





Enumerated Constants
This statement performs two tasks:
1. It makes COLOR the name of an enumeration, that is, a new type.
2. It makes RED a symbolic constant with the value 0, BLUE a symbolic constant with the
value 1, GREEN a symbolic constant with the value 2, and so forth.
Every enumerated constant has an integer value.
Описание слайда:
Enumerated Constants This statement performs two tasks: 1. It makes COLOR the name of an enumeration, that is, a new type. 2. It makes RED a symbolic constant with the value 0, BLUE a symbolic constant with the value 1, GREEN a symbolic constant with the value 2, and so forth. Every enumerated constant has an integer value.

Слайд 16





Enumerated Constants
Any one of the constants can be initialized with a particular value, however, and those that are not initialized will count upward from the ones before them.
enum Color { RED=100, BLUE, GREEN=500, WHITE, BLACK=700 };
then RED will have the value 100; BLUE, the value 101; GREEN, the value 500; WHITE, the value 501; and BLACK, the value 700.
Описание слайда:
Enumerated Constants Any one of the constants can be initialized with a particular value, however, and those that are not initialized will count upward from the ones before them. enum Color { RED=100, BLUE, GREEN=500, WHITE, BLACK=700 }; then RED will have the value 100; BLUE, the value 101; GREEN, the value 500; WHITE, the value 501; and BLACK, the value 700.

Слайд 17





 #include <iostream.h>
 #include <iostream.h>
 int main()
 {
	 enum Days { Sunday, Monday, Tuesday, Wednesday, 	Thursday, Friday, Saturday };
	Days DayOff;
	int x;
	cout << "What day would you like off (0-6)? ";
	cin >> x;
	DayOff = Days(x);
	if (DayOff == Sunday || DayOff == Saturday)
		cout << "\nYou're already off on weekends!\n";
	else
		cout << "\nOkay, I'll put in the vacation day.\n";
	return 0;
}
Описание слайда:
#include <iostream.h> #include <iostream.h> int main() { enum Days { Sunday, Monday, Tuesday, Wednesday, Thursday, Friday, Saturday }; Days DayOff; int x; cout << "What day would you like off (0-6)? "; cin >> x; DayOff = Days(x); if (DayOff == Sunday || DayOff == Saturday) cout << "\nYou're already off on weekends!\n"; else cout << "\nOkay, I'll put in the vacation day.\n"; return 0; }

Слайд 18





Results
Output: 
What day would you like off (0-6)? 1
Okay, I'll put in the vacation day.
What day would you like off (0-6)? 0
You're already off on weekends!
What day would you like off (0-6)? 3
?
What day would you like off (0-6)?6
Описание слайда:
Results Output: What day would you like off (0-6)? 1 Okay, I'll put in the vacation day. What day would you like off (0-6)? 0 You're already off on weekends! What day would you like off (0-6)? 3 ? What day would you like off (0-6)?6

Слайд 19





Expressions and Statements
Statements
In C++ a statement controls the sequence of execution, evaluates an expression, or does nothing (the null statement). 
All C++ statements end with a semicolon, even the null statement, which is just the semicolon and nothing else.
x = a + b;
Описание слайда:
Expressions and Statements Statements In C++ a statement controls the sequence of execution, evaluates an expression, or does nothing (the null statement). All C++ statements end with a semicolon, even the null statement, which is just the semicolon and nothing else. x = a + b;

Слайд 20





Blocks and Compound Statements
Any place you can put a single statement, you can put a compound statement, also called a block. 
A block begins with an opening brace ({) and ends with a closing brace (}). 
Although every statement in the block must end with a semicolon, the block itself does not end with a semicolon.
A block of code acts as one statement
Описание слайда:
Blocks and Compound Statements Any place you can put a single statement, you can put a compound statement, also called a block. A block begins with an opening brace ({) and ends with a closing brace (}). Although every statement in the block must end with a semicolon, the block itself does not end with a semicolon. A block of code acts as one statement

Слайд 21





Expressions
Expression is a legal set of operators and operands.
Anything that can result to a value is an expression.
In other word any expression has a value.
3.14
x = a + b
y = x = a + b
Описание слайда:
Expressions Expression is a legal set of operators and operands. Anything that can result to a value is an expression. In other word any expression has a value. 3.14 x = a + b y = x = a + b

Слайд 22





Operators	
Assignment Operator    =
Mathematical Operators
There are five mathematical operators: addition (+), subtraction (-), multiplication (*), division (/), and modulus (%).
Combining the Assignment and Mathematical Operators
There are self-assigned subtraction (-=), division (/=), multiplication (*=), and modulus (%=) operators as well.
Описание слайда:
Operators Assignment Operator = Mathematical Operators There are five mathematical operators: addition (+), subtraction (-), multiplication (*), division (/), and modulus (%). Combining the Assignment and Mathematical Operators There are self-assigned subtraction (-=), division (/=), multiplication (*=), and modulus (%=) operators as well.

Слайд 23





Precedence
x = 5 + 3 + 72 + 24
TotalSeconds = NumMinutesToThink + NumMinutesToType * 60
Nesting Parentheses
complicated expression is read from the inside out
Описание слайда:
Precedence x = 5 + 3 + 72 + 24 TotalSeconds = NumMinutesToThink + NumMinutesToType * 60 Nesting Parentheses complicated expression is read from the inside out

Слайд 24





Relational Operators
A condition is represented by a logical (Boolean) expression that can be true or false
Relational operators: 
Allow comparisons
Require two operands (binary)
Evaluate to true or false
Описание слайда:
Relational Operators A condition is represented by a logical (Boolean) expression that can be true or false Relational operators: Allow comparisons Require two operands (binary) Evaluate to true or false

Слайд 25





Relational Operators (continued)
Описание слайда:
Relational Operators (continued)

Слайд 26





Relational Operators and Simple Data Types
You can use the relational operators with all three simple data types:
8 < 15 evaluates to true
6 != 6 evaluates to false
2.5 > 5.8 evaluates to false
5.9 <= 7.5 evaluates to true
Описание слайда:
Relational Operators and Simple Data Types You can use the relational operators with all three simple data types: 8 < 15 evaluates to true 6 != 6 evaluates to false 2.5 > 5.8 evaluates to false 5.9 <= 7.5 evaluates to true

Слайд 27





Comparing Characters
Описание слайда:
Comparing Characters

Слайд 28





Logical Operators
Описание слайда:
Logical Operators

Слайд 29





Increment and Decrement

increment operator (++) and the decrement operator(--)
Prefix and Postfix
The prefix operator is evaluated before the assignment, the postfix is evaluated after.
a = ++x
b = x++
Описание слайда:
Increment and Decrement increment operator (++) and the decrement operator(--) Prefix and Postfix The prefix operator is evaluated before the assignment, the postfix is evaluated after. a = ++x b = x++

Слайд 30





The Nature of Truth
In C++, zero is considered false, and all other values (not zero)are considered true, although true is usually represented by 1.
Especially some of the results of an expression
Описание слайда:
The Nature of Truth In C++, zero is considered false, and all other values (not zero)are considered true, although true is usually represented by 1. Especially some of the results of an expression

Слайд 31





Order of Precedence
Relational and logical operators are evaluated from left to right
The associativity is left to right
Parentheses can override precedence
Описание слайда:
Order of Precedence Relational and logical operators are evaluated from left to right The associativity is left to right Parentheses can override precedence

Слайд 32





Order of Precedence (continued)
Описание слайда:
Order of Precedence (continued)

Слайд 33





Order of Precedence (continued)
Описание слайда:
Order of Precedence (continued)

Слайд 34





Order of Precedence (continued)
Описание слайда:
Order of Precedence (continued)

Слайд 35





Order of Precedence (continued)
Описание слайда:
Order of Precedence (continued)

Слайд 36





Short-Circuit Evaluation
Short-circuit evaluation: evaluation of a logical expression stops as soon as the value of the expression is known
Example:
	(age >= 21) || ( x == 5)	//Line 1
	(grade == 'A') && (x >= 7)	//Line 2
Описание слайда:
Short-Circuit Evaluation Short-circuit evaluation: evaluation of a logical expression stops as soon as the value of the expression is known Example: (age >= 21) || ( x == 5) //Line 1 (grade == 'A') && (x >= 7) //Line 2

Слайд 37





Conditional (Ternary) Operator
Syntax for using the conditional operator:
(expression1) ? (expression2) : (expression3)
If expression1 is true, the result of the conditional expression is expression2
Otherwise, the result is expression3
This line is read as "If expression1 is true, return the value of expression2; otherwise, return the value of expression3." Typically, this value would be assigned to a variable.
Описание слайда:
Conditional (Ternary) Operator Syntax for using the conditional operator: (expression1) ? (expression2) : (expression3) If expression1 is true, the result of the conditional expression is expression2 Otherwise, the result is expression3 This line is read as "If expression1 is true, return the value of expression2; otherwise, return the value of expression3." Typically, this value would be assigned to a variable.

Слайд 38





int Data Type and Logical (Boolean) Expressions
Earlier versions of C++ did not provide built-in data types that had Boolean values
Logical expressions evaluate to either 1 or 0
The value of a logical expression was stored in a variable of the data type int
You can use the int data type to manipulate logical (Boolean) expressions
Описание слайда:
int Data Type and Logical (Boolean) Expressions Earlier versions of C++ did not provide built-in data types that had Boolean values Logical expressions evaluate to either 1 or 0 The value of a logical expression was stored in a variable of the data type int You can use the int data type to manipulate logical (Boolean) expressions

Слайд 39





The bool Data Type and Logical (Boolean) Expressions
The data type bool has logical (Boolean) values true and false
bool, true, and false are reserved words
The identifier true has the value 1 
The identifier false has the value 0
Описание слайда:
The bool Data Type and Logical (Boolean) Expressions The data type bool has logical (Boolean) values true and false bool, true, and false are reserved words The identifier true has the value 1 The identifier false has the value 0

Слайд 40





Logical (Boolean) Expressions
Logical expressions can be unpredictable
The following expression appears to represent a comparison of 0, num, and 10:
		0 <= num <= 10
It always evaluates to true because 0 <= num evaluates to either 0 or 1, and 0 <= 10 is true and 1 <= 10 is true 
A correct way to write this expression is:
		0 <= num && num <= 10
Описание слайда:
Logical (Boolean) Expressions Logical expressions can be unpredictable The following expression appears to represent a comparison of 0, num, and 10: 0 <= num <= 10 It always evaluates to true because 0 <= num evaluates to either 0 or 1, and 0 <= 10 is true and 1 <= 10 is true A correct way to write this expression is: 0 <= num && num <= 10

Слайд 41





Type Conversion in Expressions
When constants and variables of different types are mixed in an expression, they are all converted to the same type. The compiler converts all operands up to the type of the largest operand, which is called type promotion.
Описание слайда:
Type Conversion in Expressions When constants and variables of different types are mixed in an expression, they are all converted to the same type. The compiler converts all operands up to the type of the largest operand, which is called type promotion.

Слайд 42





IF an operand is a long double
IF an operand is a long double
THEN the second is converted to long double
ELSE IF an operand is a double
THEN the second is converted to double
ELSE IF an operand is a float
THEN the second is converted to float
ELSE IF an operand is an unsigned long
THEN the second is converted to unsigned long
ELSE IF an operand is long
THEN the second is converted to long
ELSE IF an operand is unsigned int
THEN the second is converted to unsigned int
Описание слайда:
IF an operand is a long double IF an operand is a long double THEN the second is converted to long double ELSE IF an operand is a double THEN the second is converted to double ELSE IF an operand is a float THEN the second is converted to float ELSE IF an operand is an unsigned long THEN the second is converted to unsigned long ELSE IF an operand is long THEN the second is converted to long ELSE IF an operand is unsigned int THEN the second is converted to unsigned int

Слайд 43


C++ Programming, слайд №43
Описание слайда:

Слайд 44





The Comma Operator
The comma operator strings together several expressions. The left side of the comma operator is always evaluated as void. This means that the expression on the right side becomes the value of the total comma-separated expression.
x = (y=3, y+1);
What is the value of x?
Описание слайда:
The Comma Operator The comma operator strings together several expressions. The left side of the comma operator is always evaluated as void. This means that the expression on the right side becomes the value of the total comma-separated expression. x = (y=3, y+1); What is the value of x?

Слайд 45





Bitwise Operators
Bitwise operation refers to testing, setting, or shifting the actual bits in a byte or word, which correspond to the char and int data types and variants.
The operations are applied to the individual bits of the operands.
the bitwise operations can be used to mask off certain bits, such as parity.
Описание слайда:
Bitwise Operators Bitwise operation refers to testing, setting, or shifting the actual bits in a byte or word, which correspond to the char and int data types and variants. The operations are applied to the individual bits of the operands. the bitwise operations can be used to mask off certain bits, such as parity.

Слайд 46


C++ Programming, слайд №46
Описание слайда:

Слайд 47





char get_char_from_modem(void)
char get_char_from_modem(void)
{
char ch;
ch = read_modem(); /* get a character from the
modem port */
return(ch & 127);
}
Описание слайда:
char get_char_from_modem(void) char get_char_from_modem(void) { char ch; ch = read_modem(); /* get a character from the modem port */ return(ch & 127); }

Слайд 48






The bitwise OR, as the reverse of AND, can be used to set a bit.
An exclusive OR, usually abbreviated XOR, will set a bit on if and only if the bits being compared are different.
The bit-shift operators, >> and <<, move all bits in a value to the right or left as specified.
Описание слайда:
The bitwise OR, as the reverse of AND, can be used to set a bit. An exclusive OR, usually abbreviated XOR, will set a bit on if and only if the bits being compared are different. The bit-shift operators, >> and <<, move all bits in a value to the right or left as specified.

Слайд 49


C++ Programming, слайд №49
Описание слайда:

Слайд 50






The one's complement operator, ~, reverses the state of each bit in its operand. That is, all 1's are set to 0, and all 0's are set to 1.
Описание слайда:
The one's complement operator, ~, reverses the state of each bit in its operand. That is, all 1's are set to 0, and all 0's are set to 1.

Слайд 51





Selection: if and if...else
One-Way Selection
Two-Way Selection
Compound (Block of) Statements
Multiple Selections: Nested if
Comparing if...else Statements with a Series of if Statements
Описание слайда:
Selection: if and if...else One-Way Selection Two-Way Selection Compound (Block of) Statements Multiple Selections: Nested if Comparing if...else Statements with a Series of if Statements

Слайд 52





Selection: if and if...else (continued)
Using Pseudocode to Develop, Test, and Debug a Program
Input Failure and the if Statement
Confusion Between the Equality Operator (==) and the Assignment Operator (=)
Conditional Operator (?:)
Описание слайда:
Selection: if and if...else (continued) Using Pseudocode to Develop, Test, and Debug a Program Input Failure and the if Statement Confusion Between the Equality Operator (==) and the Assignment Operator (=) Conditional Operator (?:)

Слайд 53





One-Way Selection
The syntax of one-way selection is:
  
The statement is executed if the value of the expression is true
The statement is bypassed if the value is false; program goes to the next statement
if is a reserved word
Описание слайда:
One-Way Selection The syntax of one-way selection is: The statement is executed if the value of the expression is true The statement is bypassed if the value is false; program goes to the next statement if is a reserved word

Слайд 54





One-Way Selection (continued)
Описание слайда:
One-Way Selection (continued)

Слайд 55





One-Way Selection (continued)
Описание слайда:
One-Way Selection (continued)

Слайд 56


C++ Programming, слайд №56
Описание слайда:

Слайд 57





One-Way Selection (continued)
Описание слайда:
One-Way Selection (continued)

Слайд 58





Two-Way Selection
Two-way selection takes the form:
	 
	 
 	
If expression is true, statement1 is executed; otherwise, statement2 is executed
statement1 and statement2 are any C++ statements
else is a reserved word
Описание слайда:
Two-Way Selection Two-way selection takes the form: If expression is true, statement1 is executed; otherwise, statement2 is executed statement1 and statement2 are any C++ statements else is a reserved word

Слайд 59





Two-Way Selection (continued)
Описание слайда:
Two-Way Selection (continued)

Слайд 60





Two-Way Selection (continued)
Описание слайда:
Two-Way Selection (continued)

Слайд 61





Two-Way Selection (continued)
Описание слайда:
Two-Way Selection (continued)

Слайд 62





Compound (Block of) Statement
Compound statement (block of statements):
	
A compound statement is a single statement
Описание слайда:
Compound (Block of) Statement Compound statement (block of statements): A compound statement is a single statement

Слайд 63





Compound (Block of) Statement (continued)
if (age > 18)
{
	cout << "Eligible to vote." << endl;
	cout << "No longer a minor." << endl;
} 
else
{
	cout << "Not eligible to vote." << endl;
	cout << "Still a minor." << endl;
}
Описание слайда:
Compound (Block of) Statement (continued) if (age > 18) { cout << "Eligible to vote." << endl; cout << "No longer a minor." << endl; } else { cout << "Not eligible to vote." << endl; cout << "Still a minor." << endl; }

Слайд 64





Multiple Selections: Nested if
Nesting: one control statement in another
An else is associated with the most recent if that has not been paired with an else
Описание слайда:
Multiple Selections: Nested if Nesting: one control statement in another An else is associated with the most recent if that has not been paired with an else

Слайд 65


C++ Programming, слайд №65
Описание слайда:

Слайд 66





Multiple Selections: Nested if (continued)
Описание слайда:
Multiple Selections: Nested if (continued)

Слайд 67





Comparing if…else Statements with a Series of if Statements
Описание слайда:
Comparing if…else Statements with a Series of if Statements

Слайд 68





Using Pseudocode to Develop, Test, and Debug a Program
Pseudocode (pseudo): provides a useful means to outline and refine a program before putting it into formal C++ code
You must first develop a program using paper and pencil
On paper, it is easier to spot errors and improve the program
Especially with large programs
Описание слайда:
Using Pseudocode to Develop, Test, and Debug a Program Pseudocode (pseudo): provides a useful means to outline and refine a program before putting it into formal C++ code You must first develop a program using paper and pencil On paper, it is easier to spot errors and improve the program Especially with large programs

Слайд 69





Input Failure and the if Statement
If input stream enters a fail state
All subsequent input statements associated with that stream are ignored
Program continues to execute
May produce erroneous results
Can use if statements to check status of input stream
If stream enters the fail state, include  instructions that stop program execution
Описание слайда:
Input Failure and the if Statement If input stream enters a fail state All subsequent input statements associated with that stream are ignored Program continues to execute May produce erroneous results Can use if statements to check status of input stream If stream enters the fail state, include instructions that stop program execution

Слайд 70





Confusion Between == and =
C++ allows you to use any expression that can be evaluated to either true or false as an expression in the if statement:
if (x = 5)
    cout << "The value is five." << endl;
The appearance of = in place of == resembles a silent killer
It is not a syntax error
It is a logical error
Описание слайда:
Confusion Between == and = C++ allows you to use any expression that can be evaluated to either true or false as an expression in the if statement: if (x = 5) cout << "The value is five." << endl; The appearance of = in place of == resembles a silent killer It is not a syntax error It is a logical error

Слайд 71





switch Structures
switch structure: alternate to if-else
switch (integral) expression is evaluated first
Value of the expression determines which corresponding action is taken
Expression is sometimes called the selector
Описание слайда:
switch Structures switch structure: alternate to if-else switch (integral) expression is evaluated first Value of the expression determines which corresponding action is taken Expression is sometimes called the selector

Слайд 72


C++ Programming, слайд №72
Описание слайда:

Слайд 73





switch Structures (continued)
One or more statements may follow a case label
Braces are not needed to turn multiple statements into a single compound statement
The break statement may or may not appear after each statement
switch, case, break, and default are reserved words
Описание слайда:
switch Structures (continued) One or more statements may follow a case label Braces are not needed to turn multiple statements into a single compound statement The break statement may or may not appear after each statement switch, case, break, and default are reserved words

Слайд 74


C++ Programming, слайд №74
Описание слайда:

Слайд 75





Terminating a Program with the assert Function
Certain types of errors that are very difficult to catch can occur in a program 
Example: division by zero can be difficult to catch using any of the programming techniques examined so far 
The predefined function, assert, is useful in stopping program execution when certain elusive errors occur
Описание слайда:
Terminating a Program with the assert Function Certain types of errors that are very difficult to catch can occur in a program Example: division by zero can be difficult to catch using any of the programming techniques examined so far The predefined function, assert, is useful in stopping program execution when certain elusive errors occur

Слайд 76





The assert Function (continued)
Syntax:
	expression is any logical expression
If expression evaluates to true, the next statement executes
If expression evaluates to false, the program terminates and indicates where in the program the error occurred
To use assert, include cassert header file
Описание слайда:
The assert Function (continued) Syntax: expression is any logical expression If expression evaluates to true, the next statement executes If expression evaluates to false, the program terminates and indicates where in the program the error occurred To use assert, include cassert header file

Слайд 77





The assert Function (continued)
assert is useful for enforcing programming constraints during program development
After developing and testing a program, remove or disable assert statements
The preprocessor directive #define NDEBUG must be placed before the directive #include <cassert> to disable the assert statement
Описание слайда:
The assert Function (continued) assert is useful for enforcing programming constraints during program development After developing and testing a program, remove or disable assert statements The preprocessor directive #define NDEBUG must be placed before the directive #include <cassert> to disable the assert statement

Слайд 78





Programming Example: Cable Company Billing
This programming example calculates a customer’s bill for a local cable company 
There are two types of customers: 
Residential
Business
Two rates for calculating a cable bill: 
One for residential customers
One for business customers
Описание слайда:
Programming Example: Cable Company Billing This programming example calculates a customer’s bill for a local cable company There are two types of customers: Residential Business Two rates for calculating a cable bill: One for residential customers One for business customers

Слайд 79





Programming Example: Rates
For residential customer:
Bill processing fee: $4.50
Basic service fee: $20.50
Premium channel: $7.50 per channel
For business customer:
Bill processing fee: $15.00
Basic service fee: $75.00 for first 10 connections and $5.00 for each additional connection
Premium channel cost: $50.00 per channel for any number of connections
Описание слайда:
Programming Example: Rates For residential customer: Bill processing fee: $4.50 Basic service fee: $20.50 Premium channel: $7.50 per channel For business customer: Bill processing fee: $15.00 Basic service fee: $75.00 for first 10 connections and $5.00 for each additional connection Premium channel cost: $50.00 per channel for any number of connections

Слайд 80





Programming Example: Requirements
Ask user for account number and customer code
Assume R or r stands for residential customer and B or b stands for business customer
Описание слайда:
Programming Example: Requirements Ask user for account number and customer code Assume R or r stands for residential customer and B or b stands for business customer

Слайд 81





Programming Example: Input and Output
Input: 
Customer account number
Customer code
Number of premium channels
For business customers, number of basic service connections
Output: 
Customer’s account number
Billing amount
Описание слайда:
Programming Example: Input and Output Input: Customer account number Customer code Number of premium channels For business customers, number of basic service connections Output: Customer’s account number Billing amount

Слайд 82





Programming Example: Program Analysis
Purpose: calculate and print billing amount
Calculating billing amount requires:
Customer for whom the billing amount is calculated (residential or business)
Number of premium channels to which the customer subscribes
For a business customer, you need: 
Number of basic service connections
Number of premium channels
Описание слайда:
Programming Example: Program Analysis Purpose: calculate and print billing amount Calculating billing amount requires: Customer for whom the billing amount is calculated (residential or business) Number of premium channels to which the customer subscribes For a business customer, you need: Number of basic service connections Number of premium channels

Слайд 83





Programming Example: Program Analysis (continued)
Data needed to calculate the bill, such as bill processing fees and the cost of a premium channel, are known quantities
The program should print the billing amount to two decimal places
Описание слайда:
Programming Example: Program Analysis (continued) Data needed to calculate the bill, such as bill processing fees and the cost of a premium channel, are known quantities The program should print the billing amount to two decimal places

Слайд 84





Programming Example: Algorithm Design
Set precision to two decimal places
Prompt user for account number and customer type
If customer type is R or r
Prompt user for number of premium channels
Compute and print the bill
If customer type is B or b
Prompt user for number of basic service connections and number of premium channels
Compute and print the bill
Описание слайда:
Programming Example: Algorithm Design Set precision to two decimal places Prompt user for account number and customer type If customer type is R or r Prompt user for number of premium channels Compute and print the bill If customer type is B or b Prompt user for number of basic service connections and number of premium channels Compute and print the bill

Слайд 85





Programming Example: Variables and Named Constants
Описание слайда:
Programming Example: Variables and Named Constants

Слайд 86





Programming Example: Formulas
Billing for residential customers:
amountDue = RES_BILL_PROC_FEES + 
            RES_BASIC_SERV_COST 
            + numOfPremChannels * 
            RES_COST_PREM_CHANNEL;
Описание слайда:
Programming Example: Formulas Billing for residential customers: amountDue = RES_BILL_PROC_FEES + RES_BASIC_SERV_COST + numOfPremChannels * RES_COST_PREM_CHANNEL;

Слайд 87





Programming Example: Formulas (continued)
Billing for business customers:
if (numOfBasicServConn <= 10)  
    amountDue = BUS_BILL_PROC_FEES + 
                BUS_BASIC_SERV_COST 
                + numOfPremChannels *
                  BUS_COST_PREM_CHANNEL;
else
    amountDue = BUS_BILL_PROC_FEES + 
                BUS_BASIC_SERV_COST 
                + (numOfBasicServConn - 10) 
                 * BUS_BASIC_CONN_COST
               + numOfPremChannels *
                 BUS_COST_PREM_CHANNEL;
Описание слайда:
Programming Example: Formulas (continued) Billing for business customers: if (numOfBasicServConn <= 10) amountDue = BUS_BILL_PROC_FEES + BUS_BASIC_SERV_COST + numOfPremChannels * BUS_COST_PREM_CHANNEL; else amountDue = BUS_BILL_PROC_FEES + BUS_BASIC_SERV_COST + (numOfBasicServConn - 10) * BUS_BASIC_CONN_COST + numOfPremChannels * BUS_COST_PREM_CHANNEL;

Слайд 88





Programming Example: Main Algorithm
Output floating-point numbers in fixed decimal with decimal point and trailing zeros
Output floating-point numbers with two decimal places and set the precision to two decimal places
Prompt user to enter account number
Get customer account number
Prompt user to enter customer code
Get customer code
Описание слайда:
Programming Example: Main Algorithm Output floating-point numbers in fixed decimal with decimal point and trailing zeros Output floating-point numbers with two decimal places and set the precision to two decimal places Prompt user to enter account number Get customer account number Prompt user to enter customer code Get customer code

Слайд 89





Programming Example: Main Algorithm (continued)
If the customer code is r or R,
Prompt user to enter number of premium channels
Get the number of premium channels
Calculate the billing amount
Print account number and billing amount
Описание слайда:
Programming Example: Main Algorithm (continued) If the customer code is r or R, Prompt user to enter number of premium channels Get the number of premium channels Calculate the billing amount Print account number and billing amount

Слайд 90





Programming Example: Main Algorithm (continued)
If customer code is b or B,
Prompt user to enter number of basic service connections
Get number of basic service connections
Prompt user to enter number of premium channels
Get number of premium channels
Calculate billing amount
Print account number and billing amount
Описание слайда:
Programming Example: Main Algorithm (continued) If customer code is b or B, Prompt user to enter number of basic service connections Get number of basic service connections Prompt user to enter number of premium channels Get number of premium channels Calculate billing amount Print account number and billing amount

Слайд 91





Programming Example: Main Algorithm (continued)
If customer code is other than r, R, b, or B, output an error message
Описание слайда:
Programming Example: Main Algorithm (continued) If customer code is other than r, R, b, or B, output an error message

Слайд 92





Looping
The while Statement
The syntax for the while statement is as follows:
while ( condition )
	statement;
condition is any C++ expression, and statement is any valid C++ statement or block of statements.
Описание слайда:
Looping The while Statement The syntax for the while statement is as follows: while ( condition ) statement; condition is any C++ expression, and statement is any valid C++ statement or block of statements.

Слайд 93





The do...while Statement
The syntax for the do...while statement is as follows:
do
statement
while (condition);
// count to 10
int x = 0;
do
cout << "X: " << x++;
while (x < 10)
Описание слайда:
The do...while Statement The syntax for the do...while statement is as follows: do statement while (condition); // count to 10 int x = 0; do cout << "X: " << x++; while (x < 10)

Слайд 94





for Loops
The syntax for the for statement is as follows:
for (initialization; test; action ) statement;
for (counter = 0; counter < 5; counter++)
A for loop works in the following sequence:
1. Performs the operations in the initialization.
2. Evaluates the condition.
3. If the condition is TRUE, executes the action statement and the loop.
Описание слайда:
for Loops The syntax for the for statement is as follows: for (initialization; test; action ) statement; for (counter = 0; counter < 5; counter++) A for loop works in the following sequence: 1. Performs the operations in the initialization. 2. Evaluates the condition. 3. If the condition is TRUE, executes the action statement and the loop.

Слайд 95






example
for (int i = 0; i < 10; i++)
{
	cout << "Hello!" << endl;
	cout << "the value of i is: " << i << endl;
}
for (int i=0, j=0; i<3; i++, j++)
for( ; counter < 5; )
for (;;)
Описание слайда:
example for (int i = 0; i < 10; i++) { cout << "Hello!" << endl; cout << "the value of i is: " << i << endl; } for (int i=0, j=0; i<3; i++, j++) for( ; counter < 5; ) for (;;)

Слайд 96





Empty for Loops
1: //Listing 7.13
2: //Demonstrates null statement
3: // as body of for loop
4:
5: #include <iostream.h>
6: int main()
7: {
8: for (int i = 0; i<5; cout << "i: " << i++ << endl)
9: ;
10: return 0;
11: }
Описание слайда:
Empty for Loops 1: //Listing 7.13 2: //Demonstrates null statement 3: // as body of for loop 4: 5: #include <iostream.h> 6: int main() 7: { 8: for (int i = 0; i<5; cout << "i: " << i++ << endl) 9: ; 10: return 0; 11: }

Слайд 97





continue and break
The continue statement jumps back to the top of the loop.
break; causes the immediate end of a while or for loop.
Описание слайда:
continue and break The continue statement jumps back to the top of the loop. break; causes the immediate end of a while or for loop.

Слайд 98





example:continue
int values[10];
...
// Print the nonzero elements of the array.
for (int i = 0; i < 10; ++i) {
	if (values[i] == 0) {
// Skip over zero elements.
		continue;
	}
// Print the (nonzero) element.
	std::cout << values[i] << ’\n’;
}
Описание слайда:
example:continue int values[10]; ... // Print the nonzero elements of the array. for (int i = 0; i < 10; ++i) { if (values[i] == 0) { // Skip over zero elements. continue; } // Print the (nonzero) element. std::cout << values[i] << ’\n’; }

Слайд 99





Example: break
example:
// Read integers from standard input until an
// error or end-of-file is encountered or a
// negative integer is read.
int x;
while (std::cin >> x) {
	if (x < 0) {
		break;
	}
	std::cout << x << ’\n’;
}
Описание слайда:
Example: break example: // Read integers from standard input until an // error or end-of-file is encountered or a // negative integer is read. int x; while (std::cin >> x) { if (x < 0) { break; } std::cout << x << ’\n’; }

Слайд 100





Example: goto 
int i = 0;
loop: // label for goto statement
do {
	if (i == 3) {
		++i;
		goto loop;
	}
	std::cout << i << ’\n’;
	++i;
} while (i < 10);
Описание слайда:
Example: goto int i = 0; loop: // label for goto statement do { if (i == 3) { ++i; goto loop; } std::cout << i << ’\n’; ++i; } while (i < 10);

Слайд 101





Summary
Control structures alter normal control flow
Most common control structures are selection and repetition
Relational operators: ==, <, <=, >, >=, !=
Logical expressions evaluate to 1 (true) or 0 (false)
Logical operators: ! (not), && (and), || (or)
Описание слайда:
Summary Control structures alter normal control flow Most common control structures are selection and repetition Relational operators: ==, <, <=, >, >=, != Logical expressions evaluate to 1 (true) or 0 (false) Logical operators: ! (not), && (and), || (or)

Слайд 102





Summary (continued)
Two selection structures: one-way selection and two-way selection
The expression in an if or if...else structure is usually a logical expression
No stand-alone else statement in C++
Every else has a related if
A sequence of statements enclosed between braces, { and }, is called a compound statement or block of statements
Описание слайда:
Summary (continued) Two selection structures: one-way selection and two-way selection The expression in an if or if...else structure is usually a logical expression No stand-alone else statement in C++ Every else has a related if A sequence of statements enclosed between braces, { and }, is called a compound statement or block of statements

Слайд 103





Summary (continued)
Using assignment in place of the equality operator creates a semantic error
switch structure handles multiway selection
break statement ends switch statement
Use assert to terminate a program if certain conditions are not met
Описание слайда:
Summary (continued) Using assignment in place of the equality operator creates a semantic error switch structure handles multiway selection break statement ends switch statement Use assert to terminate a program if certain conditions are not met



Теги C++ Programming
Похожие презентации
Mypresentation.ru
Загрузить презентацию