Sie sind auf Seite 1von 46

CompuruIson BeLween C++

WILI Juvu C#( C SIurp)


Preenlnlion
M.Zeeshan Ashraf 404
Azeem Mumtaz 413
AbduI Hanan 425
re mem0er
nlruclor
rogram
W CompuLers perform many Lasks from slmple
maLhemaLlcal operaLlons Lo complex
anlmaLed slmulaLlons
W 1hese Lasks are performed followlng a serles
of predeflned lnsLrucLlons called a program
rogrammlng Language
W A programmlng language ls a seL of
lnsLrucLlons and a serles of lexlcal
convenLlons speclflcally deslgned Lo
order compuLers whaL Lo do
W rogrammers use a programmlng
language Lo perform new Lasks
eflnlLlon of C++
W C++ was developed by 8[arne SLrousLrup aL
bell labs
W C++ was developed by 8[arne SLrousLrup aL
bell labs
W C++ ls Lhe language whlch ls famous for
graphlcal appllcaLlons
eflnlLlon of !AvA
W !AvA was developed by Sun MlcrosysLems
W lL ls a hlgh level programmlng language
W lL was modeled afLer C++
Comparlson beLween C++ and !AvA
Data types purpose
lnL 1o sLore numerlc values
floaL 1o sLore real values
ouble 1o sLore large real value
char 1o sLore characLer values
Comparlson
W 1he daLa Lypes ln C++ are slmllar Lo Lhose ln !ava
W 1he C++ sLrlng Lype ls qulLe slmllar Lo Lhe !ava SLrlng Lype
W C++ sLrlngs sLore ASCll characLers noL unlcode characLers
W C++ sLrlngs can be modlfled whereas !ava sLrlngs are
lmmuLable meanlng unchangeable
W ?ou can only concaLenaLe sLrlngs wlLh oLher sLrlngs noL wlLh
arblLrary ob[ecLs
varlables and ConsLanLs
W A varlable ls a named memory
locaLlon or memory cell
W lL ls used Lo sLore program's lnpuL
daLa and lLs compuLaLlon resulLs
durlng execuLlon
W Lhe name of varlable cannoL be
changed
Comparlson
W ln C++ local varlables are deflned [usL as ln !ava
W 1he C++ compller does noL check wheLher all
local varlables are lnlLlallzed before Lhey are read
W 8oLh use global varlables C++ programs should
avold global varlables
W lf we Lry Lo use a varlable wlLhouL flrsL glvlng lL a
value Lhe compller wlll Lhrow an error
W lnL numberCfays
W //Lry and add 10 Lo Lhe value of numberCfays
numberCfays numberCfays + 10
W varlable numberCfays mlghL noL have been
lnlLlallzed
Comparlson
W lf we Lry Lo use a varlable wlLhouL flrsL glvlng lL a
value Lhe compller wlll Lhrow an error
W lnL numberCfays
W //Lry and add 10 Lo Lhe value of numberCfays
numberCfays numberCfays + 10
W varlable numberCfays mlghL noL have been
lnlLlallzed
W C++ uses Lhe "consL" keyword lnsLead [ava uses
flnal"
olnLers
W A polnLer ls a varlable LhaL ls used Lo sLore a
memory address
W 1he reference operaLor " ls used Lo access Lhe
memory address of a varlable
Comparlson
W ln C++ ob[ecL varlables hold ob[ecL values
W ln !AvA an ob[ecL varlable ls a reference Lo an ob[ecL value
LhaL ls sLored elsewhere
W ln C++ a polnLer varlable can be lnlLlallzed wlLh nuLL wlLh
anoLher polnLer varlable or wlLh a call Lo new Same ls Lhe
case ln [ava
W lnL *pLr nuLL
W lnL *pLr n
W ln !AvA Lhere ls no polnLer concepL only reference Lo varlable
Comparlson
W ln C++ a polnLer varlable can be lnlLlallzed wlLh nuLL wlLh
anoLher polnLer varlable or wlLh a call Lo new Same ls Lhe
case ln [ava
W lnL *pLr nuLL
W lnL *pLr n
W lnL maln()
SLudenL *pLr
pLr new SLudenL

m mkmI
ne
A coIIection of objects with same
properties and functions is known as
cIass.
As a modeI for creating different
objects of same type
omnrion
n C++ a cIass ends with a simicoIon.
But in JAVA this is not the case.
CIass A{
....
...
};
n C++, there are pubIic and private sections,
started by the keywords pubIic and private.
n Java, each individuaI item must be tagged
with pubIic or private.
nme
class a
prlvaLe lnL number1
publlc lnL number2
prlvaLe vold meLhod1()

publlc vold meLhod2()

0jecl
bject is an entity that consists of data
and functions.
An object has to things:
Properties
Functions
omnrion
hen one object is assigned to another, a
copy of the actuaI vaIues is made.
n Java, copying an object variabIe mereIy
estabIishes a second reference to the
object.
Two object variabIes cannot jointIy access
one object. f you need this effect in C++,
then you need to use pointers.
unclion
A function is a named bIock of code
that perform some action.
Functions are the buiIding bIocks of
C++ programs.
They encapsuIate piece of code to
perform specified operations.
omnrion
n Java, every function must be an instance
method or a static function of a cIass.
n C++ it aIso permits functions that are not a
part of any cIass. Such functions are
caIIed gIobaI functions.
C++ has two parameter passing
mechanisms, caII by vaIue and caII by
reference. n JAVA there is onIy caII by vaIue.
n4erilnnce
A programming technique that is used to
reuse an existing cIass to buiId a new cIass
is known as inheritance.
New cIass inherits aII the behavior of the
originaI cIass.
W Parent cIass
W ChiId cIass
omnrion
n java there is a structure caIIed
interface.
Java does not support muItipIe
inheritance but C++ has this feature.
However more than one "interface"
can be impIemented in java which
amounts to the same thing.
onlruclor nnd :erondinq
A type of member function that is automaticaIIy
executed when an object of that cIass is created is
known as constructor.
There can be muItipIe constructors, with different
numbers or types of arguments.
Constructor overIoading is a technique in which a
cIass can have any number of constructors that
differ in parameter Iists.
The process of defining additionaI meanings is
known as overIoading.
omnrion
ernlor :erondinq
lncludelosLreamh
lncludeconloh
class Pello
publlc
Pello()

couL"ob[ecL creaLed"

omnrion
JAVA:
ExampIes of vaIid constructors for cIass
Account are
Account(int a);
Account (int a,int b);
Account (String a,int b);
ernlor o:erondinq
n JAVA you cannot overIoad
operators, but in C++ you can do that.
void operator ++()
{
function body;
}
eflnlLlon of C
W C ls also known as C sharp
W ln !une 2000 MlcrosofL announced boLh Lhe nL1 plaLform
and a new programmlng language called C
W Ma[or parL of C ls based on C++ and lL conLalns feaLures
slmllar Lo programmlng language !ava
W C ls a sLronglyLyped ob[ecLorlenLed language deslgned Lo
glve Lhe opLlmum blend of slmpllclLy expresslveness
and performance
eflnlLlon of C
W lL was coauLhored by Anders Pe[lsberg (who ls famous for Lhe
deslgn of Lhe elphl language) and ScoLL WllLamuLh
W C uses a synLax somewhaL based on C++
W lL ls an ob[ecL orlenLed language and Lakes parL of lLs CC
model from C++
MeLhod/luncLlon eclaraLlon
W ++
publlc
ConsLrucLor()

vold aMemberluncLlon()

vold aluncLloneclaraLlon()
prlvaLe
vold someCLherluncLlon()

lnL avarlable
MeLhod/luncLlon eclaraLlon
W
prlvaLe avarlable
publlc vold aMemberluncLlon()

publlc vold aluncLloneclaraLlon()
prlvaLe vold someCLherluncLlon()

Class eclaraLlon
W ++
class A_Class
C++ classes end wlLh a "
W lorward declaraLlons are requlred
W amp|e
class A()
class 8(

class A(

Class eclaraLlon
W
class A_Class
W no semlcolon afLer a class declaraLlon ln C
W no forward declaraLlons requlred classes can be arranged aL
wlll
amp|e
class 8(

class A(

lnherlLance
W ++
wlll allow mulLlple lnherlLence eg allows a meLhod Lo be
overrlden many Llmes ln subclasses (derlved classes)
W
supporLs lnherlLence buL noL mulLlpleln oLher words a class
can lnherlL lmplemenLaLlon from one base class only
W when a vlrLual meLhod ls called ln a consLrucLor Lhe meLhod
ln Lhe mosL derlved class ls used
Peader llles and lncludes
W ++
allows header flles and oLher class flles Lo be lncluded uslng
Lhe n|ude keyword
W
no need for header flles and lncludes
SwlLch
W ++
supporLs Lhe swlLch sLaLemenL and fall Lhrough
W
supporLs swlLch sLaLemenL buL does noL supporL fall Lhrough
ln Lhe swlLch sLaLemenL
Access Lo class members/funcLlons
W ++
access Lo class members / funcLlons ls done by Lhe doL
and
class A(
publlc
vold show()

class 8
publlc
vold show()

class C publlc A publlc 8

Access Lo class members/funcLlons


vold maln()

C ob[
ob[Ashow()
ob[8show()

W
access Lo class members / funcLlons ls done only by Lhe doL
(no more or )
olnLers
W ++
W offers polnLers
W
W only offers polnLers ln unsafe mode
Language
W C++ ls a language LhaL runs on all sorLs of plaLforms belng
exLremely popular on unlx and unlxllke sysLems C whlle
sLandardlzed ls rarely seen ouLslde Wlndows
W 1hls means LhaL C++ ls very powerful and exLendable buL C
ls almosL cerLalnly golng Lo be easler Lo learn and use for mosL
purposes
Plerarchy
W C has a common Lype hlerarchy C++ does noL
1PAnk ?Cu

Das könnte Ihnen auch gefallen