Lecture 3. Elementary Programming
Lecture 3. Elementary Programming
Programming Languages
Lecture (3)
Submitted By:
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.
4
Basic Control Structures
Statement 1
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 ;
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!