c++ programming

32
C/C++ By Abdallah Abuouf 3 rd IT abdallah.abuouf @gmail.com

Upload: abdallah-abuouf

Post on 28-Jun-2015

1.069 views

Category:

Education


1 download

TRANSCRIPT

Page 1: C++ programming

C/C++

By

Abdallah Abuouf

3rd IT

[email protected]

Page 2: C++ programming

Agenda

Why c++ Basics Pointer Oop Data structure C/C++ under Linux Create GUI by GTK+ C++ and netbeans

Page 3: C++ programming

Why C++ ?!!

Pointer → The power Oop → Ease of understanding and clarity Memory Controller → Good but dangerous

All → Fun and simple :)

Page 4: C++ programming

Basics

Data type Commentes Functions Special symbols

Page 5: C++ programming

Data type

Int 4byte Double 8byte Float 4byte Char 1byte Bool 1byte true or false

Page 6: C++ programming

Functions

return_type function_name(args);

main(){

function_name();

}

return_type function_name(args)

{

//

}

Page 7: C++ programming

Another way

return_type function_name(args)

{

//statements

}

main(){

function_name();

}

Page 8: C++ programming

Special symbols

\n new line \b backspace \t tab \r start of line \a Bell sound \' to print ' \” to print “ \? to print ?

Page 9: C++ programming

Conditions

If esle Switch case

Page 10: C++ programming

If else

if(condition){

//statments

}

Else{

//statmets

}

Page 11: C++ programming

Switch case

switch c{

case a:

//statements;

break;

case b:

//statements;

break;

default:

//statements

break;

}

Page 12: C++ programming

Loops

For loop While Do while Goto Break & continue

Page 13: C++ programming

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

Page 14: C++ programming

while

while(condition)

{

//statments

}

Page 15: C++ programming

Do while

{

//statmentes

}dowhile(condition)

Page 16: C++ programming

GO TO

a: //label

//statments

if(condition){

goto a;

}

Page 17: C++ programming

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)

Page 18: C++ programming

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.

Page 19: C++ programming

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

Page 20: C++ programming

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

Page 21: C++ programming

Oop

Constractor & destractor Class Header file

Page 22: C++ programming

Demo

Page 23: C++ programming

Data structure

Array Linked list

Page 24: C++ programming

Array

Data type array_name[size]; Multidimensional Arrays Data type array_name[width,high];

Page 25: C++ programming

Linked list

Demo

Page 26: C++ programming

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

Page 27: C++ programming

Make executable file

Change the extension of complied file to .sh

then click on it ,it will run

Page 28: C++ programming

Create GUI by GTK+ It's work under Linux and windows Very beautiful Free

examples Gnome Gimp

tutorial1

tutorial2 For c++ we use gtkmm

Page 29: C++ programming

C++ and netbeans

Demo

Page 30: C++ programming
Page 32: C++ programming

With best wishesAbuouf

http://abuouf.wordpress.com

[email protected]