19. // 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; }
Output
Hello World!
27. 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.
28. Defining a Function:
function's name,
return type,
parameters.
actual body of the function.
return_type function_name( parameter list )
{
body of the function
}
31. Call Type
CALL BY VALUE
This method copies the actual value
of an argument into the formal
parameter of the function. In this
case, changes made to the
parameter inside the function have
no effect on the argument.
CALL BY REFERENCE
This method copies the reference
of an argument into the formal
parameter. Inside the function, the
reference is used to access the
actual argument used in the call.
This means that changes made to
the parameter affect the argument.
37. To initialize a variable of type string:
string s1=“hello”
string s2=“Net3lem”;
s1=s2;
s3=s1+s2;
s1.swap(s2);
S1=Net3lm
S2=hello
S1.size() or s1.length() get length of string
string library
39. Including Library
#include<fstream>
Members of fstream are:
Ifstream
Ofstream
Fstream
ofstream 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”);
40. Write on file Example
First we need to make an output file stream so:
Ofstream out (“file.txt”);
Then we can write by this way
Out<<“Welcome”<<“ ”<<“In”<<“ ”<<“Net3lem”;
41. Append on file
In ofstream we make a new file with this name and begin to write on it
What if I want to append on the file ?!
The solution : >> Ios:: app
Ofstream out (“file.txt” , ios::app);
47. Intro
The Bubble sorting works at this way:
First: the program will compare between the first element & the second element
then between the first & the third then between the first & the forth then between
the first & the fifth “every time we do swapping if the condition met”
Second: the program will compare between the second & the third then between
the second & the forth then between the second & the fifth “every time we do
swapping if the condition met”
We repeat this till we reach the last element in the array
48. Implementation
The 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 method
The first for loop will get the first element that we want to compare so we need
another for loop “the second one” to get the another elements from the array
59. ampersand (&)
denotes an address in memory.
cout << "Address of var1 variable: ";
cout << &var1 << endl;
60. What Are Pointers?
A pointer is a variable whose value is the address of another variable.
61. Declaration
type *var-name;
int *ip; // pointer to an integer
double *dp; // pointer to a double
float *fp; // pointer to a float
char *ch // pointer to character