Upload
diana-jane-terez-lazaro
View
218
Download
0
Embed Size (px)
Citation preview
7/29/2019 CS10 10/15/12
1/4
Introduction
Computer Program
- Sequence of statements whose objectives is to accomplish a task
Programming
- Process of planning
The Basics of a C++ Program
Function: Collection of statements; when executed, accomplish something.
- May be predefined or standard
Syntax: rules that specify which statements are legal
Programming language: a set of rules, symbols, and special words
Semantic rule: meaning of instruction
Comments
- Comments are for the reader, not the compiler
- Two types
Single line (//)
Multiple line (/*)
Special Symbols
+ - * / . ; ? , < = ! = == > =
Reserved Words (Keywords)
- Reserved words, keywords or word symbols
Identifiers
- Consists of letters, digits, and the underscore character
- Must begin with a letter or underscore
- C++ is case sensitive
- Two predefined identifiers are cout and cin
- Unlike reserved words, predefined identifiers may be redefined, but it is not a
good idea
7/29/2019 CS10 10/15/12
2/4
Legal Identifiers in C++:
- first
- conversion
- payRate
- there can be no space
- no symbols
- cannot begin w/ a number
Whitespaces
- every C++ Program contains whitespaces
include blanks, tabs, and newline characters
- used to separate symbols, reserved words, and identifiers
- proper utilization of whitespaces is important
can be used to make the program readable
Data Types
Data type: set of values together with a set of operations
Simple Data Type
- integral: integers
- floating-point: decimal
- enumeration type: user defined
Integral Data types:
- char, short, int, long, bool
- unsigned char, unsigned short, unsigned int, unsigned long
bool true and false
- different compiler s may allow different ranges of values
Floating-Point Data Tyes
- uses scientific notations to represent real numbers
7/29/2019 CS10 10/15/12
3/4
- float: represents any real number (4bytes) 7SF
- double: (8byes) 15SF
Arithmetic Operators and Operator Precedence
- + -/*%
- Can be unary or binary
- All operations inside the () are evaluated first
- *,/, % same level
- +, - same level
- Left to Right (associativity)
Expressions
- If all operands are integers (integral expression)
- If all operands are floating point (floating-point expression)
- Mixed expressions (combination)
Evaluation Rules:
- If same types the result would be the same
- When different int is changed to double
- Evaluated according to precedence
Type Conversion (Casting)
- Cast operator - static_cast ( )
- implicit type coercion - automatic
string Type
- programmer-defined type supplied in ANSI/ISO Standard C++ library
- sequence of zero or more characters
- enclosed in double quotation marks
- null: a string w/ no characters
- each character has a relative position in string
7/29/2019 CS10 10/15/12
4/4
- length of a string is the number of characters in it