KIU student of BSCS-3rd to expend knowlege for good will persons I am try to expend my mind actually.
My main objective is that of expending knowledge and happness
1. Intro to Programing
Content ..
Variables, Switch statement,
Conditional statement, Loop and Array;
By: Ghulam Raxa
2. A memory location whose content may change
during program execution.
The syntax for declaring one variable or multiple
variables is ……..
VARIABLE
dataType identifier, identifier, . . .;
int a, b, ………;
3. The first statement tells the compiler to allocate memory space to store
decimal or double type value and call it overs.
The second statement tells the compiler to allocate memory space to store
chr (a,….to…z) and call it ch.
The third statement tells the compiler to allocate memory space to store
int type value and call it x and y here we have two identifiers.
The fourth statement tells the compiler to allocate memory space to store
string and call it name.
DIFFERENT MEMORY
ALLOCATIONS
double overs;
char ch;
int x, y;
string name;
4. How do you put data into those variables?
Use C++’s assignment statement.
In an assignment statement, the value of the expression
should match the data type of
the variable.
In C++, = is called the assignment operator.
PUTTING DATA INTO
VARIABLES
variable = expression;
a = 12;
5. C++’s switch structure gives the computer the power to choose from among
many alternatives.
A general syntax of the switch statement is:
In C++, switch, case, break, and default are
. reserved words.
SWITCH STATEMENT
6. EXAMPLE
switch (grade)
{
case 'A':
cout << "The grade point is 4.0.";
break;
case 'B':
cout << "The grade point is 3.0.";
break;
case 'C':
cout << "The grade point is 2.0.";
break;
default:
cout << "The grade is invalid.";
}
SWITCH STATEMENT
7. After giving value of ch “A” what will happen:
After giving value of ch “R” what will happen:
SWITCH STATEMENT
8. The two most common Conditional statement are use in selection
and repetition.
CONDITIONAL STATEMENT
OR SELECTION STATEMENT
Selection Repetition
9. One Way Selection
The syntax of one-way selection is:
CONDITIONAL STATEMENT
CONDITIONAL STATEMENT
OR SELECTION STATEMENT
12. Set of instructions that repeat themselves until a certain
condition is fulfilled.
We can call these looping statements or loops.
It is also called iteration statement.
There are three types of loop in C++;
for loop
while loop
do while loop
LOOPING
STATEMENTS
13. A general syntax of the for loop is:
FOR LOOP
for (starting expression; test expression; update expression)
{
}
17. DO WHILE LOOP
The general form of a do. . .while statement is as follows:
It runs atleast once! weather test-condition is TRUE or FALSE.
Therefore it’s called exit controlled loop.
18. DO WHILE LOOP
Let’s check that if the test-condition is FALSE but still the loop will run once.
Code Out put
19. An array is a collection of variables of the same types that
are referenced by a common name.
Array are a way of grouping together similar item to form a
larger unit.
The general form for declaring a one-dimensional array is:
ARRAYS