C++ course start


Published on

Published in: Technology
  • Be the first to comment

No Downloads
Total views
On SlideShare
From Embeds
Number of Embeds
Embeds 0
No embeds

No notes for slide

C++ course start

  1. 1. Goal
  2. 2. Staff
  3. 3. Products
  4. 4. Contact us01211992678 www.net3lem.com01211992674 https://www.facebook.com/net3lem
  5. 5. C++ CourseAlaa RamadanNet3lem
  6. 6. History Of Programming Languages
  7. 7. // CODE// my first program in C++#include <iostream>using namespace std;int main (){cout << "Hello World!" ;return 0;}/////////////////OR//////////////////////////////////int main () { cout << "Hello World!" ; return 0; }OutputHello World!
  8. 8. Physical MemoryVariablea
  9. 9. FunctionsDivide your Code
  10. 10. FunctionsA function is a group of statements that together perform a taskC++ program has at least one function which is main(),divide up your code into functions each function performs a specific task.
  11. 11. Defining a Function:functions name,return type,parameters.actual body of the function.return_type function_name( parameter list ){body of the function}
  12. 12. Example:
  13. 13. Calling a Function:return_type function_name( parameter list );int max(int num1, int num2);int max(1, 2);
  14. 14. Call TypeCALL BY VALUEThis method copies the actual valueof an argument into the formalparameter of the function. In thiscase, changes made to theparameter inside the function haveno effect on the argument.CALL BY REFERENCEThis method copies the referenceof an argument into the formalparameter. Inside the function, thereference is used to access theactual argument used in the call.This means that changes made tothe parameter affect the argument.
  15. 15. /passing parameters by reference
  16. 16. DefaultValuesforParameters:Total value is :300Total value is :120
  17. 17. Functions with no type. The use of void.
  18. 18. Overloaded functions.
  19. 19. Strings#include<string>
  20. 20. To initialize a variable of type string:string s1=“hello”string s2=“Net3lem”;s1=s2;s3=s1+s2;s1.swap(s2);S1=Net3lmS2=helloS1.size() or s1.length() get length of stringstring library
  21. 21. Files manipulation#include<fstream>
  22. 22. Including Library#include<fstream>Members of fstream are: Ifstream Ofstream Fstreamofstream out (“name of the file with its extension”);ifstream in (“name of the file with its extension”);fstream both (“name of the file with its extension”);
  23. 23. Write on file ExampleFirst we need to make an output file stream so:Ofstream out (“file.txt”);Then we can write by this wayOut<<“Welcome”<<“ ”<<“In”<<“ ”<<“Net3lem”;
  24. 24. Append on fileIn ofstream we make a new file with this name and begin to write on itWhat if I want to append on the file ?!The solution : >> Ios:: appOfstream out (“file.txt” , ios::app);
  25. 25. Open() / close()Ofstream out;Out.open(“file.txt”,ios::app);If(!out)cout<<“File couldn’t be open”;Out.close();
  26. 26. Read from a fileIfstream In;In.open(“file.txt”);Int x,z;Char y;In>>x>>y>>z;I must know the format of the file
  27. 27. GetlineGetline (name of ifstream , name of string,stopping character);Ex:getline(index,text,|);
  28. 28. Eof()while(!index.eof()){Statement 1;Statmenet 2;}
  29. 29. Bubble Sort
  30. 30. IntroThe Bubble sorting works at this way:First: the program will compare between the first element & the second elementthen between the first & the third then between the first & the forth then betweenthe first & the fifth “every time we do swapping if the condition met”Second: the program will compare between the second & the third then betweenthe second & the forth then between the second & the fifth “every time we doswapping if the condition met”We repeat this till we reach the last element in the array
  31. 31. ImplementationThe array before sorting is: (45,30,90,5,70)The array after sorting is: (5,30,45,70,90)We need two loops to implement this methodThe first for loop will get the first element that we want to compare so we needanother for loop “the second one” to get the another elements from the array
  32. 32. Codefor(i=0;i<10;i++){for(j=0;j<i;j++){if(array[i]>array[j]){int temp=array[i]; //swaparray[i]=array[j];array[j]=temp;}}}
  33. 33. Arrays
  34. 34. Declaring Arraysfixed-size sequential collection of elements of the same type.type arrayName [ arraySize ];double balance[10];
  35. 35. Initializing Arrays:double balance[5] = {1000.0, 2.0, 3.4, 17.0, 50.0};.double balance[] = {1000.0, 2.0, 3.4, 17.0, 50.0};Accessing Array Elements:balance[4] = 50.0;double salary = balance[9];
  36. 36. Code
  37. 37. Multi-dimensional Arraystype name[size1][size2]...[sizeN];type arrayName [ x ][ y ];int threedim[5][10][4];
  38. 38. AccessingTwo-DimensionalArrayElements:int val = a[2][3];Initializing Two-Dimensional Arrays:int a[3][4] = {0,1,2,3,4,5,6,7,8,9,10,11};
  39. 39. Code
  40. 40. Pointers
  41. 41. WhySome C++ tasks are performed more easily with pointers,
  42. 42. ampersand (&)denotes an address in memory.cout << "Address of var1 variable: ";cout << &var1 << endl;
  43. 43. What Are Pointers?A pointer is a variable whose value is the address of another variable.
  44. 44. Declarationtype *var-name;int *ip; // pointer to an integerdouble *dp; // pointer to a doublefloat *fp; // pointer to a floatchar *ch // pointer to character
  45. 45. Recursion
  46. 46. DefA recursive function in C++ is a function that calls itself.