C++ Programming: Academic Year 2018-2019 Lecturer Zanco A. Taha (MSC.)
C++ Programming: Academic Year 2018-2019 Lecturer Zanco A. Taha (MSC.)
C++ Programming
Academic Year
2018-2019
Lecturer
Zanco A. Taha (MSc.)
Lecture Outlines
1. Flowchart and Algorithm
2. Structure of C++ Program.
2
Flowchart for finding the area of a rectangle
Start
Input
Length
Input
Width
Area=Length * Width
Output
Area
End
3
Algorithm for finding the area of a rectangle
Input: Length and Width
Output: Area
#include <iostream>
Steps: Using namespacestd;
input Length Int main (){
input Width Int L,W,A;
Area = Length * Width Cin>>L>>W;
Output Area A=L*W;
Cout<<“Area=” <<A;
Return 0;
|
Flowchart for finding max of 3 numbers
Start
Input
A,B,C
No No
Output
C
End
5
Algorithm for finding max of 3 numbers
Input: Three numbers A,B,C
Output: Max of numbers A,B,C
Steps:
input A,B,C
If A > B
If A > C
Output A
else
Output C
Else
If B > C
Output B
else
Output C
Comments
1- // line comment
2- /* block comment */
Example:
/* my second program in C++
with more comments */
#include <iostream>
using namespace std;
int main ()
{
cout << "Hello World! "; // prints Hello World!
cout << "I'm a C++ program"; // prints I'm a C++ program
return 0;
}
Variables and Types
• We can now define variable as a portion of memory to store a
value
• Each variable needs a name that identifies it and distinguishes it
from the others.
• The Name of variable (identifier) is a sequence of one or more
letters, digits, or underscore characters _.
• Spaces, punctuation marks, and symbols cannot be part of an
identifier. In addition, identifiers shall always begin with a letter.
• They shouldn’t be keywords like (cout,cin …etc).
• The C++ language is a "case sensitive" language.
Fundamental data types
• Character types: They can represent a single character, such as
'A' or '$'.
• Numerical integer types: They can store a whole number value,
such as 7 or 1024. They exist in a variety of sizes, and can either
be signed or unsigned.
• Floating-point types: They can represent real values, such as
3.14 or 0.01, with different levels of precision.