Se ha denunciado esta presentación.
Se está descargando tu SlideShare. ×

C++ Course - Lesson 1

Anuncio
Anuncio
Anuncio
Anuncio
Anuncio
Anuncio
Anuncio
Anuncio
Anuncio
Anuncio
Anuncio
Anuncio
THE NAME OF ALLAH
                                 C++ Course
                                 First Lesson
First we will ...
Variables:
we use variables look like boxes to save any number to use it now or after
some time in our operations that the...
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 f...
Anuncio
Anuncio
Anuncio
Próximo SlideShare
C++ programming
C++ programming
Cargando en…3
×

Eche un vistazo a continuación

1 de 15 Anuncio

Más Contenido Relacionado

Presentaciones para usted (20)

Similares a C++ Course - Lesson 1 (20)

Anuncio

C++ Course - Lesson 1

  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. 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. 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. 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. 5. 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:
  6. 6. 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) {
  7. 7. 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.
  8. 8. 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"
  9. 9. 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");
  10. 10. 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:
  11. 11. 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:
  12. 12. #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++; }
  13. 13. 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:
  14. 14. If you not write the codes you will not be with us in the next lesson . GOOD LUCK ENG Khaled

×