WPU CS 2300 - Data Types Declarations and Displays

Unformatted text preview:

Slide 1ObjectivesData TypesData Types (continued)Slide 5Slide 6Slide 7Integer Data TypesThe int Data TypeThe int Data Type (continued)The char Data TypeThe char Data Type (continued)Slide 13The Escape CharacterThe Escape Character (continued)Slide 16Slide 17The bool Data TypeDetermining Storage SizeSigned and Unsigned Data TypesSigned and Unsigned Data Types (continued)Floating-Point TypesFloating-Point Types (continued)Exponential NotationArithmetic OperatorsArithmetic Operators (continued)Integer DivisionNegationOperator Precedence and AssociativityOperator Precedence and Associativity (continued)Numerical Output Using coutFormatted OutputFormatted Output (continued)Slide 34Variables and DeclarationsDeclaration StatementsDeclaration Statements (continued)Multiple DeclarationsReference VariablesSpecifying Storage AllocationSpecifying Storage Allocation (continued)Common Programming ErrorsCommon Programming Errors (continued)SummarySummary (continued)Slide 46A First Book of C++: From Here To There, Third Edition 2ObjectivesYou should be able to describe:•Data Types•Arithmetic Operators•Numerical Output Using cout •Variables and Declarations•Common Programming ErrorsA First Book of C++: From Here To There, Third Edition 3Data Types•The objective of all programs is to process data•It is necessary to classify data into specific types–Numerical–Alphabetical–Audio–Video•C++ allows only certain operations to be performed on certain types of data–Prevents inappropriate programming operationsA First Book of C++: From Here To There, Third Edition 4Data Types (continued)•Data Type: A set of values and operations that can be applied to these values•Example of Data Type: Integers–The Values: Set of all Integer (whole) numbers–The Operations: Familiar mathematical and comparison operatorsA First Book of C++: From Here To There, Third Edition 5Data Types (continued)•Class: –Programmer-created data type–Set of acceptable values and operations defined by a programmer using C++ code•Built-In: Provided as an integral part of C++–Also known as a primitive type–Requires no external code–Consists of basic numerical types–Majority of operations are symbols (e.g. +,-,*,…)A First Book of C++: From Here To There, Third Edition 6Data Types (continued)A First Book of C++: From Here To There, Third Edition 7Data Types (continued)•Literal: Acceptable value for a data type–Value explicitly identifies itself•The numbers 2, 3.6 and –8.2 are literals–Values are literally displayed•The text “Hello World!” is a literal •Text itself is displayed•Literals also known as literal values and constantsA First Book of C++: From Here To There, Third Edition 8Integer Data Types•C++ provides nine built-in integer data types•Three most important–int–char–bool•Reason for remaining types is historical–Originally provided for special situations–Difference among types based on storage requirementsA First Book of C++: From Here To There, Third Edition 9The int Data Type•Set of values supported are whole numbers–Whole numbers mathematically known as integers•Explicit signs allowed•Commas, decimal points, and special signs not allowed•Examples of int:–Valid: 0 5 -10 +25 1000 253 -26351 +36–Invalid: $255.62 2,523 3. 6,243,982 1,492.89A First Book of C++: From Here To There, Third Edition 10The int Data Type (continued)•Different compilers have different internal limits on the largest and smallest values that can be stored in each data type–Most common allocation for int is four bytes•Atomic Data Value: a complete entity that cannot be decomposed into a smaller data type–All built-in data types are atomicA First Book of C++: From Here To There, Third Edition 11The char Data Type•Used to store individual characters–Letters of the alphabet (upper and lower case)–Digits 0 through 9–Special symbols such as + $ . , - !•Single Character Value: letter, digit or special character enclosed in single quotes –Examples ‘A’ ‘$’ ‘b’ ‘7’ ‘y’ ‘!’ ‘M’ ‘q’A First Book of C++: From Here To There, Third Edition 12The char Data Type (continued)•Character values stored in ASCII or Unicode codes•ASCII: American Standard Code for Information Exchange–Provides English-language based character set plus codes for printer and display control–Each character code contained in one byte–256 distinct codesA First Book of C++: From Here To There, Third Edition 13The char Data Type (continued)•Unicode: Provides other language character sets–Each character contained in two bytes–Can represent 65,536 characters•First 256 Unicode codes have same numerical value as the 256 ASCII codesA First Book of C++: From Here To There, Third Edition 14The Escape Character•Backslash ( \ ): the escape character–Special meaning in C++–Placed before a select group of characters, it tells the compiler to escape from normal interpretation of these characters•Escape Sequence: combination of a backslash and specific characters–Example: newline escape sequence, \nA First Book of C++: From Here To There, Third Edition 15The Escape Character (continued)A First Book of C++: From Here To There, Third Edition 16The Escape Character (continued)A First Book of C++: From Here To There, Third Edition 17The Escape Character (continued)•Both ‘\n’ and “\n” contain the newline character–‘\n’ is a character literal–“\n” is a string literal•Both cause the same thing to happen–A new line is forced on the output display•Good programming practice is to end the final output display with a newline escape sequenceA First Book of C++: From Here To There, Third Edition 18The bool Data Type•Represents boolean (logical) data•Restricted to true or false values•Often used when a program must examine a specific condition–If condition is true, the program takes one action, if false, it takes another action•Boolean data type uses an integer storage codeA First Book of C++: From Here To There, Third Edition 19Determining Storage Size•C++ makes it possible to see how values are stored•sizeof(): provides the number of bytes required to store a value for any data type–Built-in operator that does not use an arithmetic symbolA First Book of C++: From Here To There, Third Edition 20Signed and Unsigned Data Types•Signed Data Type: stores negative, positive and zero


View Full Document

WPU CS 2300 - Data Types Declarations and Displays

Download Data Types Declarations and Displays
Our administrator received your request to download this document. We will send you the file to your email shortly.
Loading Unlocking...
Login

Join to view Data Types Declarations and Displays and access 3M+ class-specific study document.

or
We will never post anything without your permission.
Don't have an account?
Sign Up

Join to view Data Types Declarations and Displays 2 2 and access 3M+ class-specific study document.

or

By creating an account you agree to our Privacy Policy and Terms Of Use

Already a member?