SlideShare a Scribd company logo
1 of 15
Download to read offline
THE NAME OF ALLAH
                                 C++ Course
                                 First Lesson
First we will talk about some concepts of programming......

First we must think before beginning in our coding and we should build our idea
in our mind and write it on paper as ships to express our idea to make it easy for
anyone to work in our project and this method called "Flow Chart". and we will
talk about it again because we will use it.

Second we should know that the programmer not making a program from
NOTHING but it use some steps and rules to make it's idea or to make a
program to do anything.....so I decide to make our course as stairs for any
code.....we will talk about every step in the general case of any code and explain
everything about it.

Libraries :
According to last words that every code consist of some steps and we
know that the computer is a stupid machine so it must have everything to
work to avoiding anything need to thinks so the libraries likes boxes
contains this steps of the programming .and every library contain some
steps and we write this line to use any library:

#include <LibraryName.h>

For Example:

the most important library

#include <iostream.h >

And we will begin our program now with this step.
Variables:
we use variables look like boxes to save any number to use it now or after
some time in our operations that the program like the human mind it need
to save any number or anything to do everything on it later so in
programming we use variables and memory boxes and it is different in its
size and in its uses and we will talk about it after 5 min :D :D bust you
must know that every variable has a name and we can't declare 2
variable with the same name....it will make an ERORR in
Compiler........what is Compiler?? I will explain it later.

Data Types :
As we were talking about variables we will talk about its types

     ‫س‬
    Name         Description                      Range     Examples
 int           It contains just integers                    1,2,3
Short       It take small range                             1,2
long        It take a great range for numbers                1 , 2 ,3
float       It take float points                            1.20 , 2.453
double      It could take float or int                      1.203 OR 1
char        It take anything as character                   'a' , '1' , '&'
string      It used for text                                "Khaled"
bool        It take: True OR False



And in first w make declaration for any variable by its data type as:

Int x ;

Char y ;

And w make an "initialization" it means to give the variable an initial value
so it will be:

Int x = 0 ;……..or any value as we need and look ' ; ' ..this character is
very important to know the compiler that this step is finished.
Inputs and Outputs:
Any program need to show a lot of things to user and may be take inputs
from user or not. so we will find methods to show anything.

To show anything we will write it:

Cout<<"The Name Of Allah" ;

And we could use it as:

Cout<<"The" << "Name" << "Of"<< "Allah" ;

And this method could show the result of an operation that

Int x = 5 ;

int y = 6 ;

cout << x + y ;  it will show 11.

But if we need to take the value of x and y from user so we will need to
use input method . it will be:

Int x = 0 ;

Int y = 0 ;

Cin >> x ;

Cin >> y ;

Cout << x + y ;

And we could use it to notify the user what will user input to the program

As before every cin we will use cout to give an inform to user as :

Cout << " Enter the First Number : " ;

Cin >> x ;

Now we will try First Code……But Now we will take this form as const
and I will explain it later:
#include <iostream>

using namespace std ;

int main ()

{



//Write Your Code Here



system("pause");

return 0 ;

}

Download this program Dev c++

http://bloodshed-dev-c.en.softonic.com/

and set up it and choose FileNewSource File

and write your Code and Press F9

this called Compiler it look like translator but it translate the C++ Code
to EXE file you could use it later.
As you see it is very nice to try but you need to think how to build a good
idea and good interface.

Operators:

There are operators to make calculations as we know + , - , * , / , %.

There are anther operator make update to variable as plus 1 to the

++ To plus one.

--To minus one.

As X++; OR X-- ;

There is different from X++ and ++X as in first we will add one to X before
do any operation and in second it will add one to X after make the
operation.

And there are anther operations as:

+= , -= , /= / %= ,…….

X+= 5 ; as the same X = X+5 ; and it will be the same in all.

And there are logical operators to make checks such as if (5 == 3)

== it used to test it 2 variables equal or Not

<= To check if the first number less than or Equal the Second.

>= To check if the first number greater than or Equal the Second.

And to use this operators we should know



if
else
that: I said that if this condition it true do something if not do anther
something and may be not to do anything. and it will be:
if (Check condition)

{

//What it will do if true

}

else

{

//what it will do if false

}

NOTE the prickets {} very important as if you forget it

By default the program will take the first step after it and will never see
what after it.

Example:
if(x == y)

{

cout << "X is Equal Y";

}

else

{

cout<< "X Not Equal Y";

}

But we can use it for more comparisons as:

If(x == y)

{

cout<<"X Equal Y ";

}

else if (x > y)

{
cout << "X is Greater Than Y";

}

else

{cout << "X is Less Than Y"; }

Note that you can use it cout << endl; to make a new line in the screen to
know the meaning of it try this code:


#include <iostream>

using namespace std ;

int main ()

{

cout << "The Name OF Allah" ;

cout << "This Lesson ONE";

system("PAUSE");

return 0 ;

}

And try this:
#include <iostream>

using namespace std ;

int main ()

{

cout << "The Name OF Allah" << endl ;

cout << "This Lesson ONE" << endl;

system("PAUSE");

return 0 ;

}




Anther way to make new line is : cout <<"n";

You can use n "fe west el kalam ":D :D.
Switch:
It look like if with more one comparison. You can use it when you have
more choice as if the user chosen it the prog should make something and
if user chosen anther so the prog will make anther something

And the general case will be:

swithch (what will the prog depend on in choices )

{

case choice :

//what will do

break ;

case anther choice :

//what will do

break ;

default:

//what will do

break ;

}

And for example if you need to write code take a number from user and
check if the number

r  show "Number 1 Mean RED "

g  show "Number 1 Mean GREEN "

b  show "Number 1 Mean BLUE "

if not 'r' nor 'g' nor 'b'

show "Wrog"
now we will think to take an input from user as character

so you should look to this code:
#include <iostream>

using namespace std ;

int main ()

{char ch ;

cout << "Enter The Char : " << endl ;

cin >> ch ;

switch(ch)

{

    case 'r':

    {

        cout << "Number 1 Mean RED n" ;

        break ;

    }

    case 'g':

    {

        cout << "Number 1 Mean GREEN n";

        break ;

    }

    case 'b' :

    {

        cout << "Number 1 Mean BLUE n";

        break ;

    }

    default:

        cout <<"Wrong";

        break ;

}

system("PAUSE");
return 0 ; }

Looping:
If you want the prog to do anything more than one….what will you do??

Will you re-write the code more than one??

We will use the looping to do it.

Looping has 3 ways for loop or while loop or do while loop.

For loop:
I think that I can anyone from the 3 to do the same loop but let us see
how it work:

The general case:

for (initial ; check ; update )

{

//write you code here

}

For loop need know when it will stop or it will infinite loop as in this case
for (int I = 0 ; I <= 5 ; )

{

cout <<"For LOOPn";

}

Look I decelerate variable I in the for. It will let the for to control it self and
you can use it in the scope of for "y3ny ben el prickets bta3t el for bs"

I wrote it as the for will find the i= 0 and look to check case that if I less
than or equal 5 so it will return true so it will compile what will be written
between the prickets but look I will equal to 0 for ever so we need to
increment I to equal 5 to stop the for loop so it will be:
for (int I = 0 ; I <= 5 ; I++)

{

cout <<"For LOOPn";

}

    If you write it:
for( ; ; )

{

cout <<"For LOOPn";

}

*you can use two for loop as
for(int I = 0 ; I < 5 ; I++)

{

             For(int j = 1 ; j <5 ; j++)

             {

             cout<<"Two Loop";

             }

}

It will never stop.

While Loop:
It is different in its shape from for as if check and if true it will do if now the
prog will skip what among its prickets.

The General case of it:

while(check case)

{

//write your code

}

Example:
#include <iostream>

using namespace std ;

int main ()

{

int x ;

while(x <= 5)

{

    cout << "While loop. n";

}

x++;

system("PAUSE");

return 0   ;
}




Do While Loop:
It different from while loop as it will do it code first without any check

And will check if true so it will do it again till return false to stop looping
and the update statement will be in the code within prickets

Example for it:
#include <iostream>

using namespace std ;

int main ()

{

int x ;

do

{

    cout << "While loop. n";

    x++;

}
while(x <= 5);

system("PAUSE");

return 0 ;

}

THE END OF LESSON ONE




AASIGMENT ONE 
Write code to make a calculator which take 2 numbers from user and the
operation that will make it of the 2 numbers if '+' make plus operation on
the 2 and show on the screen "The Result ="and show your result . do
it for all operation + , - , *, /

And after showing the result show it in the screen

Please choose:

1:New Operation

2:Exit

And take the user choice and do it.

Hint

You will use

if else

switch

may be any kind of looping

send the cpp file to this mail

engkhaled.nlpt@ymail.com

Attention:
If you not write the codes you will not be with us in the
next lesson .




                                 GOOD LUCK
                                 ENG Khaled

More Related Content

What's hot

C Sharp Jn (3)
C Sharp Jn (3)C Sharp Jn (3)
C Sharp Jn (3)jahanullah
 
Conditional statements in vb script
Conditional statements in vb scriptConditional statements in vb script
Conditional statements in vb scriptNilanjan Saha
 
C lecture 4 nested loops and jumping statements slideshare
C lecture 4 nested loops and jumping statements slideshareC lecture 4 nested loops and jumping statements slideshare
C lecture 4 nested loops and jumping statements slideshareGagan Deep
 
Presentation on nesting of loops
Presentation on nesting of loopsPresentation on nesting of loops
Presentation on nesting of loopsbsdeol28
 
C++ control structure
C++ control structureC++ control structure
C++ control structurebluejayjunior
 
Final requirement in programming niperos
Final requirement in programming   niperosFinal requirement in programming   niperos
Final requirement in programming niperosmarkings17
 
Algorithm and Programming (Branching Structure)
Algorithm and Programming (Branching Structure)Algorithm and Programming (Branching Structure)
Algorithm and Programming (Branching Structure)Adam Mukharil Bachtiar
 
Algorithm and Programming (Looping Structure)
Algorithm and Programming (Looping Structure)Algorithm and Programming (Looping Structure)
Algorithm and Programming (Looping Structure)Adam Mukharil Bachtiar
 
Looping statements in C
Looping statements in CLooping statements in C
Looping statements in CJeya Lakshmi
 
Spf Chapter4 Variables
Spf Chapter4 VariablesSpf Chapter4 Variables
Spf Chapter4 VariablesHock Leng PUAH
 
Loops and conditional statements
Loops and conditional statementsLoops and conditional statements
Loops and conditional statementsSaad Sheikh
 
Loops in c language
Loops in c languageLoops in c language
Loops in c languagetanmaymodi4
 
Looping statement
Looping statementLooping statement
Looping statementilakkiya
 
Spf Chapter5 Conditional Logics
Spf Chapter5 Conditional LogicsSpf Chapter5 Conditional Logics
Spf Chapter5 Conditional LogicsHock Leng PUAH
 

What's hot (19)

C Sharp Jn (3)
C Sharp Jn (3)C Sharp Jn (3)
C Sharp Jn (3)
 
Conditional statements in vb script
Conditional statements in vb scriptConditional statements in vb script
Conditional statements in vb script
 
Loops
LoopsLoops
Loops
 
C lecture 4 nested loops and jumping statements slideshare
C lecture 4 nested loops and jumping statements slideshareC lecture 4 nested loops and jumping statements slideshare
C lecture 4 nested loops and jumping statements slideshare
 
Looping statements
Looping statementsLooping statements
Looping statements
 
C++ loop
C++ loop C++ loop
C++ loop
 
Presentation on nesting of loops
Presentation on nesting of loopsPresentation on nesting of loops
Presentation on nesting of loops
 
C++ control structure
C++ control structureC++ control structure
C++ control structure
 
Final requirement in programming niperos
Final requirement in programming   niperosFinal requirement in programming   niperos
Final requirement in programming niperos
 
Algorithm and Programming (Branching Structure)
Algorithm and Programming (Branching Structure)Algorithm and Programming (Branching Structure)
Algorithm and Programming (Branching Structure)
 
Algorithm and Programming (Looping Structure)
Algorithm and Programming (Looping Structure)Algorithm and Programming (Looping Structure)
Algorithm and Programming (Looping Structure)
 
Looping statements in C
Looping statements in CLooping statements in C
Looping statements in C
 
Spf Chapter4 Variables
Spf Chapter4 VariablesSpf Chapter4 Variables
Spf Chapter4 Variables
 
Loops and conditional statements
Loops and conditional statementsLoops and conditional statements
Loops and conditional statements
 
Loops in c language
Loops in c languageLoops in c language
Loops in c language
 
Lecture 10 - Control Structures 2
Lecture 10 - Control Structures 2Lecture 10 - Control Structures 2
Lecture 10 - Control Structures 2
 
Looping statement
Looping statementLooping statement
Looping statement
 
C++ Presentation
C++ PresentationC++ Presentation
C++ Presentation
 
Spf Chapter5 Conditional Logics
Spf Chapter5 Conditional LogicsSpf Chapter5 Conditional Logics
Spf Chapter5 Conditional Logics
 

Similar to C++ Course - Lesson 1

Switch case and looping new
Switch case and looping newSwitch case and looping new
Switch case and looping newaprilyyy
 
My programming final proj. (1)
My programming final proj. (1)My programming final proj. (1)
My programming final proj. (1)aeden_brines
 
Yeahhhh the final requirement!!!
Yeahhhh the final requirement!!!Yeahhhh the final requirement!!!
Yeahhhh the final requirement!!!olracoatalub
 
Programming ppt files (final)
Programming ppt files (final)Programming ppt files (final)
Programming ppt files (final)yap_raiza
 
CMIS 102 Hands-On Lab Week 4OverviewThis hands-on lab all.docx
CMIS 102 Hands-On Lab Week 4OverviewThis hands-on lab all.docxCMIS 102 Hands-On Lab Week 4OverviewThis hands-on lab all.docx
CMIS 102 Hands-On Lab Week 4OverviewThis hands-on lab all.docxmonicafrancis71118
 
Programming basics
Programming basicsProgramming basics
Programming basicsillidari
 
Enrich enriching mathematics conversi biner 16 pada sisikomputerize indoensia...
Enrich enriching mathematics conversi biner 16 pada sisikomputerize indoensia...Enrich enriching mathematics conversi biner 16 pada sisikomputerize indoensia...
Enrich enriching mathematics conversi biner 16 pada sisikomputerize indoensia...Dadangsachir WANDA ir.mba
 
OOPS using C++
OOPS using C++OOPS using C++
OOPS using C++cpjcollege
 
PROVIDE COMMENTS TO FELLOW STUDENTS ANSWERS AND PLEASE DON’T SAY G.docx
PROVIDE COMMENTS TO FELLOW STUDENTS ANSWERS AND PLEASE DON’T SAY G.docxPROVIDE COMMENTS TO FELLOW STUDENTS ANSWERS AND PLEASE DON’T SAY G.docx
PROVIDE COMMENTS TO FELLOW STUDENTS ANSWERS AND PLEASE DON’T SAY G.docxamrit47
 
Lec7 - Loops updated.pptx
Lec7 - Loops updated.pptxLec7 - Loops updated.pptx
Lec7 - Loops updated.pptxNaumanRasheed11
 
Fundamentals of prog. by rubferd medina
Fundamentals of prog. by rubferd medinaFundamentals of prog. by rubferd medina
Fundamentals of prog. by rubferd medinarurumedina
 
C++ Tutorial.docx
C++ Tutorial.docxC++ Tutorial.docx
C++ Tutorial.docxPinkiVats1
 
Help with Pyhon Programming Homework
Help with Pyhon Programming HomeworkHelp with Pyhon Programming Homework
Help with Pyhon Programming HomeworkHelpmeinhomework
 
C++ Course - Lesson 3
C++ Course - Lesson 3C++ Course - Lesson 3
C++ Course - Lesson 3Mohamed Ahmed
 
C++ and OOPS Crash Course by ACM DBIT | Grejo Joby
C++ and OOPS Crash Course by ACM DBIT | Grejo JobyC++ and OOPS Crash Course by ACM DBIT | Grejo Joby
C++ and OOPS Crash Course by ACM DBIT | Grejo JobyGrejoJoby1
 

Similar to C++ Course - Lesson 1 (20)

Switch case and looping new
Switch case and looping newSwitch case and looping new
Switch case and looping new
 
My programming final proj. (1)
My programming final proj. (1)My programming final proj. (1)
My programming final proj. (1)
 
My final requirement
My final requirementMy final requirement
My final requirement
 
Yeahhhh the final requirement!!!
Yeahhhh the final requirement!!!Yeahhhh the final requirement!!!
Yeahhhh the final requirement!!!
 
Programming ppt files (final)
Programming ppt files (final)Programming ppt files (final)
Programming ppt files (final)
 
lecture 2.pptx
lecture 2.pptxlecture 2.pptx
lecture 2.pptx
 
Oop object oriented programing topics
Oop object oriented programing topicsOop object oriented programing topics
Oop object oriented programing topics
 
Python basics
Python basicsPython basics
Python basics
 
CMIS 102 Hands-On Lab Week 4OverviewThis hands-on lab all.docx
CMIS 102 Hands-On Lab Week 4OverviewThis hands-on lab all.docxCMIS 102 Hands-On Lab Week 4OverviewThis hands-on lab all.docx
CMIS 102 Hands-On Lab Week 4OverviewThis hands-on lab all.docx
 
Programming basics
Programming basicsProgramming basics
Programming basics
 
Enrich enriching mathematics conversi biner 16 pada sisikomputerize indoensia...
Enrich enriching mathematics conversi biner 16 pada sisikomputerize indoensia...Enrich enriching mathematics conversi biner 16 pada sisikomputerize indoensia...
Enrich enriching mathematics conversi biner 16 pada sisikomputerize indoensia...
 
C++ programming
C++ programmingC++ programming
C++ programming
 
OOPS using C++
OOPS using C++OOPS using C++
OOPS using C++
 
PROVIDE COMMENTS TO FELLOW STUDENTS ANSWERS AND PLEASE DON’T SAY G.docx
PROVIDE COMMENTS TO FELLOW STUDENTS ANSWERS AND PLEASE DON’T SAY G.docxPROVIDE COMMENTS TO FELLOW STUDENTS ANSWERS AND PLEASE DON’T SAY G.docx
PROVIDE COMMENTS TO FELLOW STUDENTS ANSWERS AND PLEASE DON’T SAY G.docx
 
Lec7 - Loops updated.pptx
Lec7 - Loops updated.pptxLec7 - Loops updated.pptx
Lec7 - Loops updated.pptx
 
Fundamentals of prog. by rubferd medina
Fundamentals of prog. by rubferd medinaFundamentals of prog. by rubferd medina
Fundamentals of prog. by rubferd medina
 
C++ Tutorial.docx
C++ Tutorial.docxC++ Tutorial.docx
C++ Tutorial.docx
 
Help with Pyhon Programming Homework
Help with Pyhon Programming HomeworkHelp with Pyhon Programming Homework
Help with Pyhon Programming Homework
 
C++ Course - Lesson 3
C++ Course - Lesson 3C++ Course - Lesson 3
C++ Course - Lesson 3
 
C++ and OOPS Crash Course by ACM DBIT | Grejo Joby
C++ and OOPS Crash Course by ACM DBIT | Grejo JobyC++ and OOPS Crash Course by ACM DBIT | Grejo Joby
C++ and OOPS Crash Course by ACM DBIT | Grejo Joby
 

C++ Course - Lesson 1

  • 1. THE NAME OF ALLAH C++ Course First Lesson First we will talk about some concepts of programming...... First we must think before beginning in our coding and we should build our idea in our mind and write it on paper as ships to express our idea to make it easy for anyone to work in our project and this method called "Flow Chart". and we will talk about it again because we will use it. Second we should know that the programmer not making a program from NOTHING but it use some steps and rules to make it's idea or to make a program to do anything.....so I decide to make our course as stairs for any code.....we will talk about every step in the general case of any code and explain everything about it. Libraries : According to last words that every code consist of some steps and we know that the computer is a stupid machine so it must have everything to work to avoiding anything need to thinks so the libraries likes boxes contains this steps of the programming .and every library contain some steps and we write this line to use any library: #include <LibraryName.h> For Example: the most important library #include <iostream.h > And we will begin our program now with this step.
  • 2. Variables: we use variables look like boxes to save any number to use it now or after some time in our operations that the program like the human mind it need to save any number or anything to do everything on it later so in programming we use variables and memory boxes and it is different in its size and in its uses and we will talk about it after 5 min :D :D bust you must know that every variable has a name and we can't declare 2 variable with the same name....it will make an ERORR in Compiler........what is Compiler?? I will explain it later. Data Types : As we were talking about variables we will talk about its types ‫س‬ Name Description Range Examples int It contains just integers 1,2,3 Short It take small range 1,2 long It take a great range for numbers 1 , 2 ,3 float It take float points 1.20 , 2.453 double It could take float or int 1.203 OR 1 char It take anything as character 'a' , '1' , '&' string It used for text "Khaled" bool It take: True OR False And in first w make declaration for any variable by its data type as: Int x ; Char y ; And w make an "initialization" it means to give the variable an initial value so it will be: Int x = 0 ;……..or any value as we need and look ' ; ' ..this character is very important to know the compiler that this step is finished.
  • 3. Inputs and Outputs: Any program need to show a lot of things to user and may be take inputs from user or not. so we will find methods to show anything. To show anything we will write it: Cout<<"The Name Of Allah" ; And we could use it as: Cout<<"The" << "Name" << "Of"<< "Allah" ; And this method could show the result of an operation that Int x = 5 ; int y = 6 ; cout << x + y ;  it will show 11. But if we need to take the value of x and y from user so we will need to use input method . it will be: Int x = 0 ; Int y = 0 ; Cin >> x ; Cin >> y ; Cout << x + y ; And we could use it to notify the user what will user input to the program As before every cin we will use cout to give an inform to user as : Cout << " Enter the First Number : " ; Cin >> x ; Now we will try First Code……But Now we will take this form as const and I will explain it later:
  • 4. #include <iostream> using namespace std ; int main () { //Write Your Code Here system("pause"); return 0 ; } Download this program Dev c++ http://bloodshed-dev-c.en.softonic.com/ and set up it and choose FileNewSource File and write your Code and Press F9 this called Compiler it look like translator but it translate the C++ Code to EXE file you could use it later.
  • 5.
  • 6. As you see it is very nice to try but you need to think how to build a good idea and good interface. Operators: There are operators to make calculations as we know + , - , * , / , %. There are anther operator make update to variable as plus 1 to the ++ To plus one. --To minus one. As X++; OR X-- ; There is different from X++ and ++X as in first we will add one to X before do any operation and in second it will add one to X after make the operation. And there are anther operations as: += , -= , /= / %= ,……. X+= 5 ; as the same X = X+5 ; and it will be the same in all. And there are logical operators to make checks such as if (5 == 3) == it used to test it 2 variables equal or Not <= To check if the first number less than or Equal the Second. >= To check if the first number greater than or Equal the Second. And to use this operators we should know if else that: I said that if this condition it true do something if not do anther something and may be not to do anything. and it will be:
  • 7. if (Check condition) { //What it will do if true } else { //what it will do if false } NOTE the prickets {} very important as if you forget it By default the program will take the first step after it and will never see what after it. Example: if(x == y) { cout << "X is Equal Y"; } else { cout<< "X Not Equal Y"; } But we can use it for more comparisons as: If(x == y) { cout<<"X Equal Y "; } else if (x > y) {
  • 8. cout << "X is Greater Than Y"; } else {cout << "X is Less Than Y"; } Note that you can use it cout << endl; to make a new line in the screen to know the meaning of it try this code: #include <iostream> using namespace std ; int main () { cout << "The Name OF Allah" ; cout << "This Lesson ONE"; system("PAUSE"); return 0 ; } And try this: #include <iostream> using namespace std ; int main () { cout << "The Name OF Allah" << endl ; cout << "This Lesson ONE" << endl; system("PAUSE"); return 0 ; } Anther way to make new line is : cout <<"n"; You can use n "fe west el kalam ":D :D.
  • 9. Switch: It look like if with more one comparison. You can use it when you have more choice as if the user chosen it the prog should make something and if user chosen anther so the prog will make anther something And the general case will be: swithch (what will the prog depend on in choices ) { case choice : //what will do break ; case anther choice : //what will do break ; default: //what will do break ; } And for example if you need to write code take a number from user and check if the number r  show "Number 1 Mean RED " g  show "Number 1 Mean GREEN " b  show "Number 1 Mean BLUE " if not 'r' nor 'g' nor 'b' show "Wrog"
  • 10. now we will think to take an input from user as character so you should look to this code: #include <iostream> using namespace std ; int main () {char ch ; cout << "Enter The Char : " << endl ; cin >> ch ; switch(ch) { case 'r': { cout << "Number 1 Mean RED n" ; break ; } case 'g': { cout << "Number 1 Mean GREEN n"; break ; } case 'b' : { cout << "Number 1 Mean BLUE n"; break ; } default: cout <<"Wrong"; break ; } system("PAUSE");
  • 11. return 0 ; } Looping: If you want the prog to do anything more than one….what will you do?? Will you re-write the code more than one?? We will use the looping to do it. Looping has 3 ways for loop or while loop or do while loop. For loop: I think that I can anyone from the 3 to do the same loop but let us see how it work: The general case: for (initial ; check ; update ) { //write you code here } For loop need know when it will stop or it will infinite loop as in this case for (int I = 0 ; I <= 5 ; ) { cout <<"For LOOPn"; } Look I decelerate variable I in the for. It will let the for to control it self and you can use it in the scope of for "y3ny ben el prickets bta3t el for bs" I wrote it as the for will find the i= 0 and look to check case that if I less than or equal 5 so it will return true so it will compile what will be written between the prickets but look I will equal to 0 for ever so we need to increment I to equal 5 to stop the for loop so it will be:
  • 12. for (int I = 0 ; I <= 5 ; I++) { cout <<"For LOOPn"; } If you write it: for( ; ; ) { cout <<"For LOOPn"; } *you can use two for loop as for(int I = 0 ; I < 5 ; I++) { For(int j = 1 ; j <5 ; j++) { cout<<"Two Loop"; } } It will never stop. While Loop: It is different in its shape from for as if check and if true it will do if now the prog will skip what among its prickets. The General case of it: while(check case) { //write your code } Example:
  • 13. #include <iostream> using namespace std ; int main () { int x ; while(x <= 5) { cout << "While loop. n"; } x++; system("PAUSE"); return 0 ; } Do While Loop: It different from while loop as it will do it code first without any check And will check if true so it will do it again till return false to stop looping and the update statement will be in the code within prickets Example for it: #include <iostream> using namespace std ; int main () { int x ; do { cout << "While loop. n"; x++; }
  • 14. while(x <= 5); system("PAUSE"); return 0 ; } THE END OF LESSON ONE AASIGMENT ONE  Write code to make a calculator which take 2 numbers from user and the operation that will make it of the 2 numbers if '+' make plus operation on the 2 and show on the screen "The Result ="and show your result . do it for all operation + , - , *, / And after showing the result show it in the screen Please choose: 1:New Operation 2:Exit And take the user choice and do it. Hint You will use if else switch may be any kind of looping send the cpp file to this mail engkhaled.nlpt@ymail.com Attention:
  • 15. If you not write the codes you will not be with us in the next lesson . GOOD LUCK ENG Khaled