LectureThree - C+ Programming Lecture 3 C+ Basics Part I By...

Info iconThis preview shows pages 1–8. Sign up to view the full content.

View Full Document Right Arrow Icon
Lecture 3 C++ Basics – Part I By Ghada Al-Mashaqbeh The Hashemite University Computer Engineering Department
Background image of page 1

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
Outline ± Introduction to C++ code. ± Data types. ± Identifiers. ± C++ keywords.
Background image of page 2
Sample C++ Program //Sample C++ Program /* This program prompt the user to enter two integers and return their sum*/ #include <iostream.h> int main() { int a1, a2, sum; cout<<"Enter the first number:"; cout << endl; cin >> a1; cout<<"Enter the second number:"; cout<<endl; cin >> a2; sum = a1 + a2; cout <<"The sum of " << a1 << " and " << a2 << " = " << sum << "\n"; return 0; }
Background image of page 3

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
Output
Background image of page 4
Program Explanation I ± Comments: ± Single line comment: after \\ ± Multi-line comments: between \* and *\ ± Comments are not processed by the compiler, feel free to write anything you want. ± Preprocessor directives: ± Special instructions for the preprocessor. ± Start with # and come at the beginning of the program. ± Tell the preprocessor to perform code substitutions in the source code. ± More about this later. ± .h file: ± Header file which is simply a library that includes the definitions of the used functions within the program, i.e. the frequently used to avoid repeating the code. ± Two types: standard (comes with C++ package) and user defined.
Background image of page 5

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
Program Explanation II ± int main(): ± The main part of your program and it represents the entry point of it. ± The compiler will compile all instructions inside the main(). ± So, place all instruction within the main function, i.e. between its braces { }. ± { }: ± Braces define a block of code. ± { is the start of this block and } is its end. ± a1, a2, sum: ± Names of variables. ± int: ± Define the data type of the used variable. ± intmeans an integer variable.
Background image of page 6
Program Explanation III ± cout: ± Function defined in the iostream library. ± An output operator.
Background image of page 7

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
Image of page 8
This is the end of the preview. Sign up to access the rest of the document.

Page1 / 22

LectureThree - C+ Programming Lecture 3 C+ Basics Part I By...

This preview shows document pages 1 - 8. Sign up to view the full document.

View Full Document Right Arrow Icon
Ask a homework question - tutors are online