Presentation is loading. Please wait.

Presentation is loading. Please wait.

Announcements Quiz 1 Next Week. int : Integer Range of Typically -32,768 to 32,767 (machine and compiler dependent) float : Real Number (i.e., integer.

Similar presentations


Presentation on theme: "Announcements Quiz 1 Next Week. int : Integer Range of Typically -32,768 to 32,767 (machine and compiler dependent) float : Real Number (i.e., integer."— Presentation transcript:

1 Announcements Quiz 1 Next Week

2 int : Integer Range of Typically -32,768 to 32,767 (machine and compiler dependent) float : Real Number (i.e., integer part, decimal part, and exponent part) Range of Typically 10e-38 to 10e38 double : Larger Real Number (10e-308 to 10e308) char : Character Built-In (or Primitive) Data Types for Variables

3 Can Use Letters: Remember That C++ is Case Sensitive (e.g., NumWidgets Is Not the Same as numwidgets ) Can Use Digits 0-9, and Underscore Cannot Start with a Digit Cannot Contain Spaces or Other Characters Typically Maximum of 32 Characters Cannot Use C++ Keywords Naming Variables in C++: Identifiers

4 Should Use a Meaningful, Descriptive Name so that Variable’s Use Is Easily Understood: Examples: counter, second, minute, length, width Be Consistent with Case; Usually Lower Case with Upper Case for Second Part of Variable Name Examples: averageRainfall, totalStudentGrades, maxBuildingHeight, minPackageWeight; Naming Variables (Cont)

5 Constant: An Identifier that Is Initialized to a Value that Cannot Change Usually Declared at Top of Program using Keyword const Standard Naming of Constants Is to Use All Upper Case Letter with or without Underscore between Words All Constants Must Be Initialized Syntax: const int MAXHT = 100; Named Constants

6 Easier to Understand Easier to Modify Example: Compare using Number 5000 in Program versus Constant MAXHT Advantages of Constants

7 const int MAXHT = 100; main() {... currentHeight > MAXHT... bridgeHeight == MAXHT... bridgeHeight + newAddition >= MAXHT... // used MAXHT 223 times in this program } Named Constants

8 Constants Whose values Are Already Known: Characters (Specified Inside Single Quotes): ‘A’, ‘a’, ’5’, ’ ‘, ’\n’ (newline), ’\0’ (NULL Character) Integers: 10, 1345, -34 Float or Double: 2.3, -45.18, 10.6e6 String (Specified Inside Double Quotes): “HELLO”, “What a great deal.”, “5” Literal Constants (Values)

9 Also Known as I/O Output Stream: cout << variable; Input Stream: cin >> variable; New Line: endl All C++ Statements End in Semicolon ( ; ) Input and Output

10 #include using namespace std; int main() { int numEntered; cout << “Please enter an integer:”; cin >> numEntered; cout << “Thanks, you entered: “ << numEntered << “.” << endl; } Input and Output Example

11 Standard Template Library (STL): Library of C++ Functions Used Worldwide String Type NOT Built-in in C++ String Type Defined in STL To Use STL Strings: #include using namespace std; string lastName; Characters and Strings

12 Declaration: string yourName; Assigning a Value to a String: yourName = “A. Goose”; String Constants (Values) Must Be Enclosed in Double Quotes STL Strings

13 #include using namespace std; int main() { string lastName; cout << “Enter your last name: “; cin >> lastName; cout << “Your last name is: “ << lastName << endl; return(0); } Input String Example

14 Expressions Expression: A Sequence of One or More Identifiers and Operators that Evaluates to a Value Operator: A Symbol Expressing a Way to Modify a Value or Values (e.g., + for Addition) Operand: A Value Being Modified by an Operator Example Expressions: 5 currentHeight currentHeight + 10

15 Arithmetic Expressions Standard Arithmetic Operations Can Be Performed: Addition, Subtraction, Multiplication, Division Standard Arithmetic Operators Can Be Used for These Operations: +, -, *, / Others: % - “Modulo (Mod)” – Remainder after Integer Division -- Decrement (Subtract 1) ++ Increment (Add 1)

16 Order of Operations Precedence: Level of Importance of Operations Multiplicative Operators Have Higher Precedence than Additive Operators: *, /, % Higher +, - Lower Associativity: Order of Operation for Equal Level Precedence Most Operators Have Left-to-Right Associativity Use Parentheses to Force Differing Precedence of Operations

17 Know for the Quiz All Terms (Underlined Items) Variable Declaration, Initialization, and Assignment Constant Declaration Expressions Operators Input (cin) and Output (cout) Everything in Labs through Lab 2


Download ppt "Announcements Quiz 1 Next Week. int : Integer Range of Typically -32,768 to 32,767 (machine and compiler dependent) float : Real Number (i.e., integer."

Similar presentations


Ads by Google