Содержание
- 2. C++ Programming Introduction Procedural, Structured, and Object-Oriented Programming Procedural or Structured A computer program can be
- 3. Introduction First, it is natural to think of your data (employee records, for example) and what
- 4. Introduction object-oriented programming (OOP)is to treat data and the procedures that act upon the data as
- 5. C++ and Object-Oriented Programming C++ fully supports object-oriented programming, including the four pillars of object-oriented development:
- 6. C++ and Object-Oriented Programming C++ supports the idea of reuse through inheritance. A new type, which
- 7. Creating an Executable File The steps to create an executable file are 1. Create a source
- 8. C++ Programming First program 1: #include 2: 3: int main() 4: { 5: cout 6: return
- 9. C++ Programming Question and answer Q. Can a program run even if has a warning? Q.
- 10. C++ Programming parts of a C++ program 1: #include 2: 3: int main() 4: { 5:
- 11. C++ Programming A Brief Look at cout 3: #include 4: int main() 5: { 6: cout
- 12. C++ Programming Comments----before function /**************************************************** Program: Hello World File: Hello.cpp Function: Main (complete program listing in
- 13. Variable How to declare and define variables and constants. The role of a variable in programm.
- 14. Enumerated Constants Enumerated constants enable you to create new types and then to define variables of
- 15. Enumerated Constants This statement performs two tasks: 1. It makes COLOR the name of an enumeration,
- 16. Enumerated Constants Any one of the constants can be initialized with a particular value, however, and
- 17. #include int main() { enum Days { Sunday, Monday, Tuesday, Wednesday, Thursday, Friday, Saturday }; Days
- 18. Results Output: What day would you like off (0-6)? 1 Okay, I'll put in the vacation
- 19. Expressions and Statements Statements In C++ a statement controls the sequence of execution, evaluates an expression,
- 20. Blocks and Compound Statements Any place you can put a single statement, you can put a
- 21. Expressions Expression is a legal set of operators and operands. Anything that can result to a
- 22. Operators Assignment Operator = Mathematical Operators There are five mathematical operators: addition (+), subtraction (-), multiplication
- 23. Precedence x = 5 + 3 + 72 + 24 TotalSeconds = NumMinutesToThink + NumMinutesToType *
- 24. C++ Programming Relational Operators A condition is represented by a logical (Boolean) expression that can be
- 25. C++ Programming Relational Operators (continued)
- 26. C++ Programming Relational Operators and Simple Data Types You can use the relational operators with all
- 27. C++ Programming Comparing Characters
- 28. Logical Operators C++ Programming Operator Symbol Example AND && expression1 && expression2 OR || expression1 ||
- 29. Increment and Decrement increment operator (++) and the decrement operator(--) Prefix and Postfix The prefix operator
- 30. The Nature of Truth In C++, zero is considered false, and all other values (not zero)are
- 31. C++ Programming Order of Precedence Relational and logical operators are evaluated from left to right The
- 32. C++ Programming Order of Precedence (continued)
- 33. C++ Programming Order of Precedence (continued)
- 34. C++ Programming Order of Precedence (continued)
- 35. C++ Programming Order of Precedence (continued)
- 36. C++ Programming Short-Circuit Evaluation Short-circuit evaluation: evaluation of a logical expression stops as soon as the
- 37. Conditional (Ternary) Operator Syntax for using the conditional operator: (expression1) ? (expression2) : (expression3) If expression1
- 38. C++ Programming int Data Type and Logical (Boolean) Expressions Earlier versions of C++ did not provide
- 39. C++ Programming The bool Data Type and Logical (Boolean) Expressions The data type bool has logical
- 40. C++ Programming Logical (Boolean) Expressions Logical expressions can be unpredictable The following expression appears to represent
- 41. Type Conversion in Expressions When constants and variables of different types are mixed in an expression,
- 42. IF an operand is a long double THEN the second is converted to long double ELSE
- 43. C++ Programming
- 44. The Comma Operator The comma operator strings together several expressions. The left side of the comma
- 45. Bitwise Operators Bitwise operation refers to testing, setting, or shifting the actual bits in a byte
- 46. C++ Programming
- 47. char get_char_from_modem(void) { char ch; ch = read_modem(); /* get a character from the modem port
- 48. The bitwise OR, as the reverse of AND, can be used to set a bit. An
- 49. C++ Programming
- 50. The one's complement operator, ~, reverses the state of each bit in its operand. That is,
- 51. C++ Programming Selection: if and if...else One-Way Selection Two-Way Selection Compound (Block of) Statements Multiple Selections:
- 52. C++ Programming Selection: if and if...else (continued) Using Pseudocode to Develop, Test, and Debug a Program
- 53. C++ Programming One-Way Selection The syntax of one-way selection is: The statement is executed if the
- 54. C++ Programming One-Way Selection (continued)
- 55. C++ Programming One-Way Selection (continued)
- 57. C++ Programming One-Way Selection (continued)
- 58. C++ Programming Two-Way Selection Two-way selection takes the form: If expression is true, statement1 is executed;
- 59. C++ Programming Two-Way Selection (continued)
- 60. C++ Programming Two-Way Selection (continued)
- 61. C++ Programming Two-Way Selection (continued)
- 62. C++ Programming Compound (Block of) Statement Compound statement (block of statements): A compound statement is a
- 63. C++ Programming Compound (Block of) Statement (continued) if (age > 18) { cout cout } else
- 64. C++ Programming Multiple Selections: Nested if Nesting: one control statement in another An else is associated
- 66. C++ Programming Multiple Selections: Nested if (continued)
- 67. C++ Programming: Comparing if…else Statements with a Series of if Statements
- 68. C++ Programming Using Pseudocode to Develop, Test, and Debug a Program Pseudocode (pseudo): provides a useful
- 69. C++ Programming Input Failure and the if Statement If input stream enters a fail state All
- 70. C++ Programming Confusion Between == and = C++ allows you to use any expression that can
- 71. C++ Programming switch Structures switch structure: alternate to if-else switch (integral) expression is evaluated first Value
- 73. C++ Programming switch Structures (continued) One or more statements may follow a case label Braces are
- 75. C++ Programming Terminating a Program with the assert Function Certain types of errors that are very
- 76. C++ Programming The assert Function (continued) Syntax: expression is any logical expression If expression evaluates to
- 77. C++ Programming The assert Function (continued) assert is useful for enforcing programming constraints during program development
- 78. C++ Programming Programming Example: Cable Company Billing This programming example calculates a customer’s bill for a
- 79. C++ Programming Programming Example: Rates For residential customer: Bill processing fee: $4.50 Basic service fee: $20.50
- 80. C++ Programming: From Problem Analysis to Program Design, Fourth Edition Programming Example: Requirements Ask user for
- 81. C++ Programming Programming Example: Input and Output Input: Customer account number Customer code Number of premium
- 82. C++ Programming Programming Example: Program Analysis Purpose: calculate and print billing amount Calculating billing amount requires:
- 83. C++ Programming Programming Example: Program Analysis (continued) Data needed to calculate the bill, such as bill
- 84. C++ Programming Programming Example: Algorithm Design Set precision to two decimal places Prompt user for account
- 85. C++ Programming Programming Example: Variables and Named Constants
- 86. C++ Programming Programming Example: Formulas Billing for residential customers: amountDue = RES_BILL_PROC_FEES + RES_BASIC_SERV_COST + numOfPremChannels
- 87. C++ Programming Programming Example: Formulas (continued) Billing for business customers: if (numOfBasicServConn amountDue = BUS_BILL_PROC_FEES +
- 88. C++ Programming Programming Example: Main Algorithm Output floating-point numbers in fixed decimal with decimal point and
- 89. C++ Programming Programming Example: Main Algorithm (continued) If the customer code is r or R, Prompt
- 90. C++ Programming Programming Example: Main Algorithm (continued) If customer code is b or B, Prompt user
- 91. C++ Programming Programming Example: Main Algorithm (continued) If customer code is other than r, R, b,
- 92. Looping The while Statement The syntax for the while statement is as follows: while ( condition
- 93. The do...while Statement The syntax for the do...while statement is as follows: do statement while (condition);
- 94. for Loops The syntax for the for statement is as follows: for (initialization; test; action )
- 95. example for (int i = 0; i { cout cout } for (int i=0, j=0; i
- 96. Empty for Loops 1: //Listing 7.13 2: //Demonstrates null statement 3: // as body of for
- 97. continue and break The continue statement jumps back to the top of the loop. break; causes
- 98. example:continue int values[10]; ... // Print the nonzero elements of the array. for (int i =
- 99. Example: break example: // Read integers from standard input until an // error or end-of-file is
- 100. Example: goto int i = 0; loop: // label for goto statement do { if (i
- 101. C++ Programming Summary Control structures alter normal control flow Most common control structures are selection and
- 102. C++ Programming Summary (continued) Two selection structures: one-way selection and two-way selection The expression in an
- 104. Скачать презентацию