C++ Programming Overview

glintplainvilleΛογισμικό & κατασκευή λογ/κού

18 Νοε 2013 (πριν από 3 χρόνια και 8 μήνες)

92 εμφανίσεις

C++ Programming Overview

Object
-
Oriented Programming


Object
-
Oriented Programming



Object
-
Oriented Thinking

o

In everyday life, we work with different objects.

o

Each object has characteristics (attributes) and procedures.



Example: A door needs to be opened a
nd closed. We pass
messages to “
open
” the door by turning the door knob.



The same message has a different result when applied to a radio.



Both operations, even though different, open.

o

Consider our customer billing program.



It might contain an object cal
led PreferredCustomerBill.



This object will contain certain tasks that will be performed
(adjusted rates, discounts, and so on).


What to Know About OOP



Objects



Classes



Inheritance



Polymorphism


Objects and Classes



Object



any thing.



Class



consists of a

category of things.



An object is a specific item that belongs to a class; called an
instance
of a
class.

o

Example: Dish is a class.



You can hold a Dish object in your hand.



You can eat from a Dish object.



“MyDilber
Mug
WithTheChip is an object, instance, of

the Dish
class.



Why? Because a Mug is considered a Dish.

Inheritance



You can create new classes that are
descendents

of an existing class.



The descendent classes can
inherit

all of the attributes of the
parent

class.

o

Just like you inherit certain attribu
tes from your parents.



Example: In geometry, a cube is a descendent of a square. A cube has all
of the square attributes with the addition of depth.

Polymorphism



Functions may need to operate differently depending on context.



OO Programs use
polymorphi
sm

to carry out the same operation in a
manner customized to the object.



Without polymorphism, you would have to use a separate name to
multiply two integers or two floating point numbers.

o

You would have to use a third function to multiply three numbers
to
gether.



Polymorphism will allow you to use the same function regardless if you
are multiplying two numbers together or if you multiplying three numbers
together.


The C++ Environment



Editor



the main work area of the program.

o

Place where you type your pro
gramming statements (
Source Code
).



Source code files are saved with a .CPP file extension.

o

Similar to a word processing program.



Compiling



process of transforming the source code into machine language.



Object code



the output from the compilation.

o

When
a file is compiled, a file is created with a .OBJ extension.



Executable Program



a working C++ program as well as code from any outside
files to which it may reference.

o

This process of integrating outside files is called
linking
.

o

Executable files have a .
EXE file extension.



Errors



occur during the compiling process and will prevent a program from
being executed.



Warnings


occur during the compiling process, but will not prevent a program
from being executed. However, it probably indicates a problem wit
h the program.


The main( ) Function



C++ programs consist of routines called modules.



Every function includes a function header and a function body.



The initial line of a C++ function makes up the
function header
, which contains
3 parts.

o

The type of variab
le that the function will return to the function that calls
it.

o

The name of the function.

o

In parentheses, the types and names of any variables that the function
receives.



Every C++ program contains at least one function called
main
.

o

If the main function do
es not pass any values to other programs or receive
values from outside programs, the main( ) receives and returns a
void
(nothing) type.



void main ( )

{


}



C++ statements are typed between the
opening

and
closed

brackets
.



Every statement needs to
end

with

a
semicolon.



Sometimes, statements will be grouped together, such as loops,
which will require their own set of brackets inside the main set of
brackets, forming a
block
.