0% found this document useful (0 votes)
9 views

Lecture 3. Elementary Programming

The document contains lecture notes on elementary programming, focusing on variables, data types, and basic control structures in programming. It includes examples of variable declaration, initialization, and simple C++ programs for adding numbers and printing user information. Additionally, it outlines the constraints for naming variables and provides flowchart symbols for program structure.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
9 views

Lecture 3. Elementary Programming

The document contains lecture notes on elementary programming, focusing on variables, data types, and basic control structures in programming. It includes examples of variable declaration, initialization, and simple C++ programs for adding numbers and printing user information. Additionally, it outlines the constraints for naming variables and provides flowchart symbols for program structure.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 26

Lectures Notes in

Programming Languages

Lecture (3)
Submitted By:

Dr. Ahmed Mohamed Abd-Elwahab


Lecturer in BIS Department,
Faculty of Commerce & Business Administration,
Helwan University, Cairo, Egypt.
CHAPTER (2)

Elementary Programming

2
Ch. 2. OUTLINE (Part One)
❑ Introduction.
❑ Variables.
❑ Data Types.
❑ Declaration of Variables.
❑ Initialization of Variables.
❑ Reading Inputs from User.
❑ A Simple Program for Adding Two Numbers.
❑ Program for Printing a Print Complete Name and Age.
❑ Assignment.
3
Flow Charts
Symbol Name Function
Terminal or Oval Indicates Start or End of a program.

Input/Output Used for Input/Output operations.

Process Indicates any type of internal operation inside the


Processor or Memory.

Decision Used to ask a Question that can be answered in a


binary format (Yes/No, True/False).

Flow Lines or Arrows Shows direction of flow.

4
Basic Control Structures

Statement 1
Condition ?

Statement 2 Statement Condition ?

Statement 1 Statement 2
Statement 3

5
F9
Build and Run
6
Program
Variables Methods

1 2 3 1 2 3 4
Datatype Name Value Datatype Name return
{
of Var. of Fun.
Statements;
}

10
7
Variables
➢ Variables is a location in the computer’s
memory where a value can be stored for
use by a program.
1
➢ All variables must be declared with a data
2
type and name before they can be used in
a program.

8
9
char Bool

string
10
Declaration of Variables
number1 Constraints for Name of Variables:
int number1 ; 1. To begin with a letter A → Z ... A ≠ a
int A ; ≠ int a ;
float GPA ; 2. Don’t start with a number
int 2Level ; → int Level2 ;

char grade ; 3.
4.
Don’t use Space int G 2 ; → int G2 ;
int G-2 ; → int G_2 ;

string name ;
5. Don’t use Keywords in C++ Language

int num1 ;
int num1 , num2 , num3 ; = int num2 ;
int num3 ;

double Salary , NetSalary ; 11


Initialization of Variables
x
int x = 5 ; 5
x = 10 ; 10
float GPA = 3.6 ; grade
char grade = ‘A’ ; A
string Address = ‘‘ Street 9 Maadi ’’ ;
num1 num2
int num1 , num2 = 10 ; 10
a c d
long a , b , c = 20 , d ;
b
20
12
Write C++ Program that can Read from user two positive integer
numbers, and then Print the Sum.
Start

Read num1 and num2

Sum = num1 + num2

Print Sum

End
13
14
15
16
Sum

Sum

17
18
num1 num2 sum
10 20 0
30

19
Run or Execute program
Build and Run
F9

20
Write C++ program that can Read from user F_Name , M_Name , L_Name
and age. Then Print complete name and your age.

21
Run or Execute program
Build and Run
F9

22
Write C++ program that can Read from user Full Name and age. Then
Print complete name and your age. (using getline).

23
Run or Execute program
Build and Run
F9

24
Assignment
Write a C++ Program that read
from user the width and length of
a rectangle to calculate the Area
and Perimeter of the Rectangle.
Then Print the results.
25
Thanks!

Ahmed Mohamed Abd-Elwahab


26

You might also like