chapter 2: basic elements of C++

Ace your homework & exams now with Quizwiz!

new line character '\n'

- tells the next command to output in a new line

'string' data type

- user-defined type - must always be included in double quotation '' '' - blank space count as a character

floating point data types

- uses scientific notation to represent real numbers

'endl'

causes insertion point to move to the beginning of next line

STD namespace

- 'cin' and 'cout' are declared in the header file 'iostream' but within 'std' namespace

C++ input

- 'cin' is used with '>>', stream extraction operator, to gather input

semicolon

- ALL statements must end with a semicolon - also called a statement terminator

variable

- a memory location whose contents can be changed

programming language

- a set of rules, symbols, and special words

order of precedence

- all operations in () are calculated first - same as basic math orders

how to assign data into variables - 1st way

- assignment statements

reserved words

- cannot be redefined within program - cannot be used for anything other than their intended use

'int' data type

- cannot use a comma within an integer

C++ program

- collection of functions, one of which is always called 'main' - use 'cin' and stream extraction operator '>>' to input - use 'cout' and the stream insertion operation '<<' to output - pre-processor commands are processed before the program goes through the compiler - gives files the extension '.cpp'

function ( or subprogram)

- collection of statements - when executed, accomplishes something - maybe predefined or standars

comments

- comments are for the reader and are not executed by the compiler - 2 types

semantics rules

- determine the meaning of the instructions

whitespaces

- every C++ program contains whitespaces - include blanks, tabs, and newline characters - used to separate special symbols, reserved words, and identifiers - can be used to make program more readable

prompt lines

- executable statements that inform the user what to type to input into a variable

data type conversion

- implicit type coercion: when value of one type of data is automatically changed to another type - cast operator: provides explicit type conversion

named constant

- memory location whose content can't change during execution

preprocessor commands

- processed before the program goes through the compiler - begin with '#' - no semicolon at the end - many functions and symbols needed to rum a C++ code are provided in its libraries - every library has a name and is referred to by a header file such as 'iostream'

'double' data type

- represents any real number - maximum of 15 significant digits - double values are called double precision

'float' data type

- represents any real number - maximum of 6 or 7 significant digits - float values are called single precision

syntax rules

- rules that specify which statements are legal or valid

data types

- set of values together with a set of operations - 3 C++ data types 1. simple data type 2. structured data type 3. pointers

creating a C++ program

- the first line of the function 'main' is called the heading of the function - the statements enclosed between the curly braces { } from the body of the function - has 2 parts, preprocessor directives and the actual program - both constitute and make up the C++ source code (.cpp) - executable code is produced and saved in a file with the extension .exe

identifiers

- the name of something that appears in a program - consists of letters, digits, and underscore '_' - must begin with a letter or underscore - is case sensitive ('A' is not the same as 'a') - two predefined identifiers: 'cout' and 'cin' - predefined identifiers may be redefined, but it's not a good idea

special symbols: token

- the smallest individual unit of a program written in any language - C++ tokens include special symbols, word symbols, and identifiers

'char' data type

- the smallest integral data type - used for SINGLE characters: letters, digits, and special symbols - each character is enclosed in single quotes - a blank space IS a character

how to declare a variable

- to create a variable, follow the syntax "datatype" "identifier";

how to assign data into variables - 2st way

- use input statements

C++ output

- use stream insertion operator '<<'

commas

- used to separate items in a list

blanks

- used to separate numbers when inputting data - also used to separate reserved words and identifier - must NEVER appear within a reserved word

C++ output examples

- what's put into "" "" are shown as what it is - what's not put into double quotations are calculated/ processed

if you use the string type

- you need to access its definition from the header file string - must include the following preprocessor directive

data types: simple data types

3 categories of simple data 1. integral: integers (numbers without a decimal) 2. floating-point: decimal numbers 3. enumeration type: user-defined data type

expressions

for mixed expressions, integers are changed to floating-point and result is floating point

programming

process of planning and creating a program

computer program

sequence of statements whose objective is to accomplish a task


Related study sets

Chapter 18: The heart and cardiovascular function

View Set

Ch. 40 F & E, Acid‐Base Balance

View Set

Relaxation Therapy Nclex Questions

View Set

MISY 5320 Info Assurance and Security 17 & 19

View Set

Intro to Physical Fitness Wellness Online Exam

View Set