c++ programming
TRANSCRIPT
Agenda
Why c++ Basics Pointer Oop Data structure C/C++ under Linux Create GUI by GTK+ C++ and netbeans
Why C++ ?!!
Pointer → The power Oop → Ease of understanding and clarity Memory Controller → Good but dangerous
All → Fun and simple :)
Basics
Data type Commentes Functions Special symbols
Data type
Int 4byte Double 8byte Float 4byte Char 1byte Bool 1byte true or false
Functions
return_type function_name(args);
main(){
function_name();
}
return_type function_name(args)
{
//
}
Another way
return_type function_name(args)
{
//statements
}
main(){
function_name();
}
Special symbols
\n new line \b backspace \t tab \r start of line \a Bell sound \' to print ' \” to print “ \? to print ?
Conditions
If esle Switch case
If else
if(condition){
//statments
}
Else{
//statmets
}
Switch case
switch c{
case a:
//statements;
break;
case b:
//statements;
break;
default:
//statements
break;
}
Loops
For loop While Do while Goto Break & continue
For loop
Nested for
for(int i=1;i<10;i++){
for(int j=1;j<=i;j++){
cout <<j<<” ”;
}
cout<<endl;
}
1
1 2
1 2 3
1 2 3 4
1 2 3 4 5
1 2 3 4 5 6
1 2 3 4 5 6 7
1 2 3 4 5 6 7 8
1 2 3 4 5 6 7 8 9
while
while(condition)
{
//statments
}
Do while
{
//statmentes
}dowhile(condition)
GO TO
a: //label
//statments
if(condition){
goto a;
}
Pointer is very easy
int *xadd; int x=7; --->(1) int y=x; --->(2) xadd=&x; -->(3) cout<<x<<endl; -->(1) cout<<y<<endl; -->(2) cout<<xadd<<endl;(3) cout<<*xadd<<endl;(3)
Data type *pointer _name; pointer _name=&variable name Data type &Reference _name=variable name; ptr2 = (char*) ptr1;
converts ptr1 to char pointer before assigning it to ptr2.
Pointer Ex int x=5;
int y=105;
int *p1=&x;
int *p2=&y;
cout<<" p1="<<p1<<"p2="<<p2;
cout<<"\n x= "<<x<<"y="<<y;
y=x;
cout<<"\n p1="<<p1<<"p2="<<p2;
cout<<"\n x= "<<x<<"y="<<y;
x=10;
*p2=*p1;
cout<<"\n p1="<<p1<<"p2="<<p2;
cout<<"\n x= "<<x<<"y="<<y;
Can be =null; Can be redeclared Deleted by delete Delete p1;
p1= 0x222 p2=0x223X=5 y=105p1= 0x222 p2=0x223X=105 y=105p1= 0x222 p2=0x222X=10 y=10
Reference Exint x=300;
int &ref=x;
cout<<" x= "<<x;
cout<<" ref= "<<ref;
ref=600;
cout<<"\n x= "<<xx;
cout<<" ref= "<<ref;
-----------------------
x=300 ref=300
X=600 ref=600
notes Can't be=null; Can't be redeclared ----------------------- int &Ref= *(new int); int x=99; &Refr=x; //wrong
Oop
Constractor & destractor Class Header file
Demo
Data structure
Array Linked list
Array
Data type array_name[size]; Multidimensional Arrays Data type array_name[width,high];
Linked list
Demo
C/C++ under Linux
Install on debian family
sudo apt-get install gcc Install on redhat family
yum -i gcc Complie
gcc filename.cpp -o filename Run
./filename
Make executable file
Change the extension of complied file to .sh
then click on it ,it will run
Create GUI by GTK+ It's work under Linux and windows Very beautiful Free
examples Gnome Gimp
tutorial1
tutorial2 For c++ we use gtkmm
C++ and netbeans
Demo
References
Robert_Lafore-Object_Oriented_Programming_in_C++
Data Structures and Algorithm Analysis in C http://www.brpreiss.com/books/opus4/html/book
.html http://cpp.datastructures.net/
With best wishesAbuouf
http://abuouf.wordpress.com