Introduction to C How C Evolved B C

Introduction to C++ How C++ Evolved B C (Richie) C++ (Stroustrup) C++ is a superset of C Should I learn C first? ***

Introduction To C++ Program Design Trivial problems Complex problems On time Within budget *

Start yes Compile Link Errors no Edit Source Code Run Time Errors Link Errors Compile yes no Done ***

Source to Executable source code compiler h-files used object code linked to libraries exe. file **

A First Program 1. #include <iostream. h> 2. void main() 3. { 4. 5. } cout <<"Hello Worldn";

A Simple Program Parts of a simple program #include < > iostream. h **

A Simple Program source code preprocessor #include< > expanded source code C++ compiler

A Simple Program Parts of a simple program #include<iostream. h> void main( ) { } **

Function Header Line Parts of a simple program function name argument void main ( ) type of returned value ****

A Simple Program Parts of a simple program Function: header body { void main( ) { note alignment } *

A Look at cout Parts of a simple program << redirection t n º endl tab hard return begin a new line **

A Look at cout Parts of a simple program cout <<"Here is 5: "<<5<<"n"; Output Here is 5: 5 **

A Look at cout Parts of a simple program cout <<"A big number: t"<<70000<<endl; Output A big number: 70000 **

A Look at cout Parts of a simple program cout <<"The sum of 8 & 5 is "<<8 + 5<<endl; Output The sum of 8 & 5 is 13 **

A Look at cout Parts of a simple program cout <<"Big # : "<< 7000*7000<<endl; Output Big # : 4. 9 e+07 **

A Look at cout Parts of a simple program cout <<"A fraction: "<<5/8 <<endl; Output A fraction: 0. 625 **

A Look at cin Parts of a simple program >> redirection Paired with cout.

A Look at cin Parts of a simple program cout << “Enter a number: “; cin >> num 1; The contents of the address named num 1 is. . .

A Look at cin Parts of a simple program cout << “Enter 3 numbers: “; cin >> num 1 << num 2 << num 3; The contents of the address named num 1 is … num 2 is … num 3 is. . .

Reserved Words that have special meanings in the language. They must be used only for their specified purpose. Using them for any other purpose will result in a error. e. g. cout do cin while if switch else return *

Reserved Words C++ is case-sensitive. Thus: cout COUT Cout c. Out all have different meanings. The reserved words are all in lowercase. **

Statements A statement controls the sequence of execution, evaluates an expression, or does nothing, and ends with a semicolon.

Statements { cout <<"A fraction: "<<5/8 <<endl; cout <<"Big # : "<< 7000*7000<<endl; cout <<8 + 5 <<" is the sum of 8 & 5n"; cout << “Hello world”; } There are 5 statements.

Comments These are important parts of a program. Two types // /* */ or /* */ **

Comments Do: Add comments to source code. Keep comments up to date. Use comments to explain sections of code. Don't: Use comments for code that is self-explanatory. ****

Programming Style one main function and use braces void main ( void ) { statements; } optional **

Programming Style group declarations at the beginning void main (void) { declaration statements; other statements; }

Programming Style blank lines before and after control structures void main (void) { statements; if (expression) { } } statement; statements;

Success comes before work only in the dictionary.
- Slides: 29