tailieunhanh - Chapter 1 C++ Basics
Chapter Objectives.♦ Introduction to C++.♦ Origins, Object-Oriented Programming, Terms♦ Variables, Expressions, andAssignment Statements.♦ Console Input/Output ♦ Program Style ♦ Libraries and | Chapter 1 C++ Basics Learning Objectives Introduction to C++ Origins, Object-Oriented Programming, Terms Variables, Expressions, and Assignment Statements Console Input/Output Program Style Libraries and Namespaces Introduction to C++ C++ Origins Low-level languages Machine, assembly High-level languages C, C++, ADA, COBOL, FORTRAN Object-Oriented-Programming in C++ C++ Terminology Programs and functions Basic Input/Output (I/O) with cin and cout Display A Sample C++ Program (1 of 2) Display A Sample C++ Program (2 of 2) C++ Variables C++ Identifiers Keywords/reserved words vs. Identifiers Case-sensitivity and validity of identifiers Meaningful names! Variables A memory location to store data for a program Must declare all data before use in program Data Types: Display Simple Types (1 of 2) Data Types: Display Simple Types (2 of 2) Assigning Data Initializing data in declaration statement Results "undefined" if you don’t! int myValue = 0; Assigning data during . | Chapter 1 C++ Basics Learning Objectives Introduction to C++ Origins, Object-Oriented Programming, Terms Variables, Expressions, and Assignment Statements Console Input/Output Program Style Libraries and Namespaces Introduction to C++ C++ Origins Low-level languages Machine, assembly High-level languages C, C++, ADA, COBOL, FORTRAN Object-Oriented-Programming in C++ C++ Terminology Programs and functions Basic Input/Output (I/O) with cin and cout Display A Sample C++ Program (1 of 2) Display A Sample C++ Program (2 of 2) C++ Variables C++ Identifiers Keywords/reserved words vs. Identifiers Case-sensitivity and validity of identifiers Meaningful names! Variables A memory location to store data for a program Must declare all data before use in program Data Types: Display Simple Types (1 of 2) Data Types: Display Simple Types (2 of 2) Assigning Data Initializing data in declaration statement Results "undefined" if you don’t! int myValue = 0; Assigning data during execution Lvalues (left-side) & Rvalues (right-side) Lvalues must be variables Rvalues can be any expression Example: distance = rate * time; Lvalue: "distance" Rvalue: "rate * time" Assigning Data: Shorthand Notations Display, page 14 Data Assignment Rules Compatibility of Data Assignments Type mismatches General Rule: Cannot place value of one type into variable of another type intVar = ; // 2 is assigned to intVar! Only integer part "fits", so that’s all that goes Called "implicit" or "automatic type conversion" Literals 2, , "Z", "Hello World" Considered "constants": can’t change in program Literal Data Literals Examples: 2 // Literal constant int // Literal constant double "Z" // Literal constant char "Hello World" // Literal constant string Cannot change values during execution Called "literals" because you "literally typed" them in your program! Escape Sequences "Extend" character set Backslash, \ preceding a character Instructs compiler: a special "escape character" .
đang nạp các trang xem trước