OBJECT-ORIENTED PROGRAMMING WITH C++

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

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

180 εμφανίσεις


1

OBJECT
-
ORIENTED PROGRAMMING WITH
C++


1.

WHAT IS
SOFTWARE
?

1.1

Brief Definition of Software

1.2

Software Engineering

1.3

Software Production Process


2
.

C
OVERVIEW

2
.1

Data Types
,

Modifiers

and Qualifiers

2
.2

Operators

(Aithm
etic,
Assignment,
Relational, Logical
,

Bitwise
)

2.3 Conversions

(Implicit,

Explicit)

2.
4

Struct
ure


2.5 Arrays

2
.
6

Pointers

2
.
7


Conditionals

2.
8


Loops


2.9
Scope Rule

2
.
10


Functions

2
.
1
1

C Library and
Some
Functions


3
.

C++

3.1

History

3.2

Weaknesses

3.3

Strengths

3.4

Best Uses



4
.

OBJECT
-
ORIENTED CONCEPT
S


4
.1

Advantages of Object
-
Oriented Technique

4
.2

Terminology

(Class,

Object)

4
.3

Features (Abstraction,

Encapsulation,

Inheritance,

Polymorphism,

Dy
n
amic
Bind
ing,

Overriding,

Overloading)


5
.

DIFFERENCES BETWEEN C AND C++

5
.1

Comments

5
.
2

Declaration

&

Definition

5
.
3

Constant Description

5.
4

Boolean Type

5
.
5

Functional Style of Type Conversion

5
.
6

Default Function Arguments

5.
7

Reference Operator

5
.
8

Inlin
e

of
Function Code

5
.
9

Character Constant

5.
10

Conversion to Void *

5.
11

Enumeration Type

5.
12

Character Array Initialization

5.
13

Old Style Function Declaration


2

5.
14

Assign Data to Pointers

5.
15

Character Data

5.
16

New Keywords


6
.

OBJECT
-
ORIENTED FEATURES IN
C++

6
.1

Class Initialization (Constructor/Destructor Functions)

6.
2

Inheritance and Virtual Functions
(Friend Functions)

6
.3

Templates

6.4
Standar
d

Input and Output

(iostream library)

6
.
5

Overloading


6
.
6

Exception Handling


6
.
7

File Input and Outpu
t(fstream library)



































3

1.

WHAT IS
SOFTWARE
?



















1.1.

Brief Definition of Software


SOFTWARE

CORRECT RESULT

REQUIREMENTS

SOFTWARE

COMPONENT

FILES


DOCUMENTS


DEVELOPMENT


OPERATING


MAINTENANCE



4





Includes





Goal
s




1.

Low cost
of construction


2.

High perfo
rmance


3.

Portability


4.

Low cost of

maintenance



5.

High r
eliability


6.

Delivery

on Time





1.2.

Software Engineering

PRINCIPLES

METHODS &

TECHNIQUES

WAYS

TOOLS



5











Ease of

maintenance


Cost of
Production


Reliability


Performance

Meeting
deadlines

Conflicted goals

Complementary goals



6





This model is sometimes referred to as

the linear sequential model

or

the

software life
cycle
.





1.3.

Software Production Process



7

2.

C
OVERVIEW





Data Types


int :

int

is used to define integer numbers.




int number;



int digit=3;




fl
oat:

float

is used to define floating point numbers.





float length;




length = 11.3;





double:

double

is used to define BIG floating point numbers.





double total=250000000;




char:

char

defines characters.





char letter = ‘X’;



















2.1.


Data Types
,Modifiers
and Qualifiers



8

void:

The
void

keyword

allows us to create functions that either
do not require any parameters or do not return a value.



v
oid Square_Area(int numbe
r);


main()

{



Square_Area(10);



exit(0);

}



v
oid Square_Area(int number)

{



printf("%d square area is %d
\
n",number, number*number);



}





int Random(void);


main()

{


printf("A random number is %d
\
n",

Random());


exit(0);

}


int Random(void)

{


srand((unsigned int)time((time_t *)NULL));


return( rand());

}









9










Modifiers


The modifiers define the amount of storage allocated to the
variable. The amount of storage allocat
ed is not cast in stone.
ANSI has the following rules:




short int <= int <= long int


float <= double <= long double




short



long



signed



unsigned

Fol
l
owing figures only apply to todays generation of PCs.
Mainframes and midrange machines could use di
fferent figures,
but would still comply with the rule below.




T
ype

Bytes Bits Range



short int 2 16
-
32,768
-
> +32,767


unsigned short int 2 16 0
-
> +65,535




unsigned int 4 32 0
-
> +4,294,967,295


int 4

32
-
2,147,483,648
-
> +2,147,483,647



long int 4 32
-
2,147,483,648
-
> +2,147,483,647


signed char 1 8
-
128
-
> +127


unsigned char 1 8 0
-
> +255



float 4 32


double 8 64


long double 12 96






10



Qualifiers




Const


Unlike variables, and as the name implies,constants don't change.
You must initialize a constant then you create it, and you cannot
assign a new value l
ater.


C++ has two types of constants: literal and symbolic.


A literal constant is a value typed directly into your program
wherever it is needed. For example


int length = 39;


length
is a variable of type
int
;
39
is a literal constant.



A symbolic cons
tant is a constant that is represented by a name,
just as a variable is represented.


If your program has one integer variable named
students
and
another named
classes
, you could compute how many students
you have, given a known number of classes, if you k
new there
were 15 students per class:


students = classes * 15;


In this example,
15
is a literal constant. Your code would be
easier to read, and easier to maintain, if you substituted a symbolic
constant for this value:


students = classes * studentsPerC
lass


There are two ways to declare a symbolic constant in C. The old,
traditional, and now obsolete way is with a preprocessor directive,
#define
.


#define studentsPerClass 15




11

Although
#define
works, there is a new, much better way to
define constants in

C:


const unsigned short int studentsPerClass = 15;



enum:

ENUM is closely related to the
#define

preprocessor.

It allows you to define a list o
f aliases which represent integer
numbers. For example if you find yourself coding something
like:


#define MON 1


#define TUE 2


#define WED 3


You could use
enum

as below.





enum week { Mon=1, Tue, Wed, Thu, Fri
Sat, Sun} days;




or





enum escapes { BELL = '
\
a', BACKSPACE = '
\
b',


HTAB

= '
\
t'

, RETURN = '
\
r',


NEWLINE = '
\
n', VTAB = '
\
v' };







or




enum boolean { FALSE = 0, TRUE };





Volatile


The
volatile

keyword

acts as a
data type

qualifier. The qualifier
alters the default w
a
y in which the compiler handles the variable
and does not attempt to optimize the storage referenced by it.

H
ere is an example for the

usage of the volatile keyword:




12

/* Base address of the data input latch */


volatile unsigned char *baseAddr;


/* read parts of output latch */


lsb = *handle
-
>baseAddr;

middle = *handle
-
>baseAddr;

M
sb = *handle
-
>baseAddr;


Between reads the by
tes are changed in the latch.

Without the volatile, the compiler optimises this to a single
assignment:

lsb = middle = msb = *handle
-
>baseAddr;






Logical Operator Table

A

B

A & B

A | B


A ^ B


0

0

0

0

0

1

0

0

1

1

0

1

0

1

1

1

1

1

1

0




A
rithmetic Operators


+ ,
-

, * , / , % , ++ ,
--

, ( )



2.2.

Operators



13



Assignment Operators


= , += ,
-
= , *= , /= , %= , >>= , <<= , &= , ^= , |=




Relational Operators


< , > , <= , >=

, == , !=




Logical Operators


! , && , ||




Bitwise Operators


~ ,
|
, & ,
^ ,
<< , >>


Operator precedence and associativity

Precedence

Associativity

()

[]



++
(postfix)
--
(postfix)

Left to right


+
(unary)


(unary)
++
(prefix)

-
(prefix)


! ~ &(address) *(dereference) sizeof(type)



R
ight to left

*

/

%

Left to right

+
-

Left to right

< <= > >=

Left to right

== !=

Left to right

&

Left to right

^

Left to right

|

Left to right

&&

Left to right

||

Left to right

?:

Right to left

= +=
-
= *= etc

Right to left




14

/*The header
<limits.h>

contains a macro,
CHAR_BIT
, that expands to an integer
constant specifying the number of bits in the character types.*/

#define

BITNUMOFINT
sizeof
(
int
) * CHAR_BIT

#define

MASK


1 << (BITNUMOFINT
-
1)



void

bitwiseWrite(
int
);


int

main()

{


int

num1=2, num2=3, result;


char

ch;




printf("num1 = %d ",num1);


bitwiseWrite(num1);




printf("num2 = %d ",num2);


bitwiseWrite(num2);



/*************************/


/* Bitwise operators */


/*************
************/



/* Bitwise or */


result= num1 | num2 ;


printf("
\
n num1 | num2 = %d
\
n",result);






/* Bitwise and */


result= num1 & num2 ;


printf("
\
n num1 & num2 = %d
\
n",result);



/* Bitwise exclusive or */


result= num1 ^ num2 ;


printf("
\
n num1 ^

num2 = %d
\
n",result);



/* Left shift */


result= num1 << 3 ;


printf("
\
n num1 << 3 = %d
\
n",result);


bitwiseWrite(result);





15




/* Right shift */


result= num1 >> 3 ;


printf("
\
n num1 >> 3 = %d
\
n",result);


bitwiseWrite(result);




/* bitwise complement */


result= ~num1 ;


printf("
\
n ~num1 = %d
\
n",result);


bitwiseWrite(result);



printf("Press E for exit...
-

");



while
(ch=getchar()!='E') {};




return

0;

}


void

bitwiseWrite(
int

number)


{


int

i,temp;


short

bit;



printf("Bitw
ise Value : ");


for

(i=0,temp=number ; i <BITNUMOFINT ;i++){



bit=((temp & MASK)==0) ?
0

:
1
;



printf("%d", bit);



temp <<= 1;




}


printf("
\
n");


}








16

2.3.

Conversions




Implicit


Implicit conversion is done automatically
.
Widening

is
applied on
mixed expressions and result is the bigger type. On the other hand,
right hand side value is converted left hand side value during
assignment. If the left hand variable is small type , some of right
hand value will be discarded. This is called
narrowing
. Some
examples are given below;


Declarations

char c;

long l; float f;

short s;

unsigned u; double d;

int i;

unsigned long ul; long double ld;


Expression

Type

c


s / i



int


u * 2.0


i double


d + s double


u
-

ul unsigned long








Explicit(Casting)


In addition to implicit conversions, we may explicitly define
conversion.

This is called casting. Casting can not be applied to
left hand side variables.








17

Declarations

char c; long l; float f;

short s; unsigned u; double d;

int i; unsigned long ul; long double ld;


(long)
(‘A’ + 1.0)



f = (float) ((int) d + l)


(double) i = 77 /*
Not allowed

*/



2.4.

Struct
ure



The structure mechanism provides a means to aggregate related
variables of different types.


Struct Staff {



char *Name;


char *Surname;


char *Birthdate;





int Salary;

}
;


typedef
struct
Staff staff;



staff staffvar, *staffp1=&staffvar;


For accessing structure members use following notation;


Structure_variable
.
member_name

/* staff
var
.Name */


If you use pointer referencing structure,
then

arrow will be used
instead of point
.



Pointer_variable
-
>
struct_
member_name

/*

staffp1
-
>
Name */



18

Within a given structure, the member names must be unique.
However, members in different structures are allowed to have the
same name.


struct

SCar{



char

*brand;



int

model;



char

*color;


};



typedef

struct

SCar scar;



scar scar1,*scar1p=&scar1;


/*struct SCar car2;*/



int


main(
int

argc,
char*

argv[])


{




/*
scar1.brand = new char[20];




scar1.color = new char[20];






scar1.brand = (
char

*) malloc(
sizeof
(
char
)*20);



scar1.color = (
char

*) malloc(
sizeof
(
char
)*20);





strcpy(scar1.brand,"Porche");



strcpy(scar1.color,"Red");
*/



/***************************************/


char

* brand="Porche";



char

* color="Red";



strcpy(scar1.brand,brand);



strcpy(scar1.color,color);




scar1.model=2004;






printf("
\
n STRUCT CAR INFORMATION
\
n");



printf("Car Brand: %s
\
n",scar1p
-
>brand);



printf("Car Color: %s
\
n",scar1p
-
>color);



printf("Car Model: %d
\
n",scar1p
-
>model);




return

0;


}



19

2.5.

Arrays



Arrays
are

used to hold homogeneous data. A
n array can be
thought of as a simple variable with

an index or subscript added. The
brackets [] are used to contain the array subscripts.

Array bounds can
be defined as follow;



Lower bound = 0;



Upper bound = size


1


#define

ARRAYSIZE 15


char

le
tters[]="cdakhlmbonegifj";

/* is equal to char
letters[]={'c','d','a','k','h','l','m','b','o','n','e','g','i','f','j'};


or char letters[ARRAYSIZE]="cdakhlmbonegifj";

*/

void

SortArray(
char

[]);

void

WriteArray(
char

[]);


int

main(
int

argc,
char *
argv[]
)

{


SortArray(letters);


WriteArray(letters);


return

0;

}


void

SortArray(
char

array[])


{

int

i,j,temp;


for

(i=0;i<(ARRAYSIZE
-
1);i++)



for

(j=i+1;j<ARRAYSIZE;j++)




if

(array[i] > array[j]){





temp=array[j];





array[j]=array[i];





array[i]=temp
;




};



}



20


void

WriteArray(
char

array[])


{


int

i;



printf(" ORDERED ARRAY ELEMENTS
\
n");


printf("=====================================
\
n");


for

(i=0;i<ARRAYSIZE;i++)



printf(" %c
\
n",array[i]);



}



Dimensional arrays res
embles matrix. Its
total
element
number

is
equal to multiplying all dimension

size
.

Array declaration will
have additional brackets for each dimension.



I
nt number[3][3];



Column1

Column2

Column3

Row 1

number[0][0]

number[0][1]

number[0][2]

Row 2

numb
er[1][0]

number[1][1]

number[1][2]

Row 3

number[2][0]

number[2][1]

number[2][2]














21

2.6.

Pointers


Pointers are used in programs to access memory and manipulate
addresses.

For variable x
,


&x describes its memory address.
Address

operator can only be
applied to variables and array
elements. The following usages cause error.


&23 /* For constants */


&(var1 + 23) /* ordinary expressions */



Pointer variables are declared as follow;


int *pointer;


Note:

An array name by itself is an address, or
pointer value. The
previous sorting algorithm is a clear example.



#define

ARRAYSIZE 15


char

letters[]="cdakhlmbonegifj";

char

*pt1=letters;


void

SortArray(
char

*);

void

WriteArray(
char

*);


int

main(
int

argc,
char
* argv[])

{


SortArray(pt1);


WriteArr
ay(pt1);


while

(
true
) {};


return

0;

}







22

void

SortArray(
char

*subpt1)


{


int

i,j,temp;


for

(i=0;i<(ARRAYSIZE
-
1);i++)



for

(j=i+1;j<ARRAYSIZE;j++)




if

(*(subpt1+i) > *(subpt1+j)){





temp=*(subpt1+j);





*(subpt1+j)=*(subpt1+i);





*(subpt1+i)=te
mp;




};


}


void

WriteArray(
char

*subpt1)


{


int

i;


printf(" ORDERED ARRAY ELEMENTS
\
n");


printf("=====================================
\
n");


for

(i=0;i<ARRAYSIZE;i++)



printf(" %c
\
n",*(subpt1+i));


}



var1

var2

var3

5

12

17

Pointer

0FCA

0FCA

*Pointer

0FCF

Pointer=&var1



23



2.7.

Conditionals




If


if allows for conditional execution of code.

if (ConditionExpression){


Then block statements;

}

else {


Else block statements;

}



ConditionExpression

contains the test expression. If the test
expression evaluates to true (
ie. non
-
zero), Then

block statements

are executed, otherwise the else block statements

are

executed.

∙ If there is more than one statement to be executed within the
‘then’

or
‘else’

branch
es
, the blocks must be enclosed with
{}
's.

∙ It is not necessary t
o have an else statement within each if
conditional.

∙ Multiple expressions can be evaluated by using conjunctions
(e.g. &&, ||).








24



Switch


The switch is a multi

way conditional statement generalizing the
if
-
else statement



switch

(integral expressi
on) {



case (constant integral expression):



statements;



break;



case (constant integral expression):



statements;



break;






default:



statements;

}




Integral expression

is an expression which type is one of the

integral type
s (char, short, int, long).





Conditional
(Ternary)

Operator


Conditional operator is one line if statement. It is easy to use if
you need a simple if
statement.




expression
1

? expression
2

: expression
3



e
xpression
1

is a group of arithmetic or logical op
erations which
yields

boolean


or integral data type.
If it is nonzero(or true) then
expression2

is evaluated, otherwise
expression3

is evaluated
.










25

int

main(
int

argc,
char

* argv[])

{


enum

colors {YELLOW=1,GREEN=2,BROWN=3,BLUE=4};


int

choos
ed=0;


int

number1=0,number2=0;



/* Conditional operator example */



printf("Insert first number:");


while

(scanf("%i",&number1)!=1)



printf("Insert first number:");


printf("Insert second number:");


while

(scanf("%i",&number2)!=1)



printf("Insert se
cond number:");



printf("The greater number is %i
\
n",(number1 > number2 ? number1:number2));



/* Switch example */



printf("Choose one of Colors
\
n");


printf("====================
\
n");


printf(" 1
-
YELLOW
\
n");


printf(" 2
-
GREEN
\
n");


printf(" 3
-
BROWN
\
n");


printf(" 4
-
BLUE
\
n");


printf("??????:");



scanf("%i",&choosed);



switch

(choosed){



case

YELLOW: printf("Choosed Color is YELLOW");







break
;




case

GREEN : printf("Choosed Color is GREEN");







break
;





case

BROWN
: printf("Choosed Color is BROWN");







break
;




case

BLUE : printf("Choosed Color is BLUE");







break
;



default

: printf("No color selected");


}




return

0;

}



26

2.8.

Loops


Repetition of action is one reason why we depend on computers. If
t
here is a large amount of data to be processed, the convenient way is
using control

mechanism
s

that repeatedly execute specific statements.
In C,

while, do and for statements are used
.





While




while

(expression) {



statements;


}





For




for

(expre
ssion
1;expression2;expression3
) {



statements;


}





Do




do

{



statements;


}

while
(expression)







27

Two special statements are used in loops. If you want to force
program break loop for a special condition you can use
break

statement. If you want
to skip
to next loop without executing all
statements in a loop you can use
continue

statement.



#define

INDEX 10

#define

MAXNUMBER 100

/* Finds the count of numbers which is
less

than MAXNUMBER */



int

main(
int

argc,
char

* argv[])

{


int

a[10];


i
nt

i=0;


int

numcount=0;


int

error=
0
;



printf("Insert integer value
\
n");


printf("====================
\
n");




for
(;i<10 && scanf("%i",&a[i]);i++);



i=0;


do

{




if

(a[i]
>

MAXNUMBER)
continue
;



if

(a[i] < 0) {




error=
1
;




break
;



}



numcou
nt++;


}
while

(++i<
INDEX
);



if

(error)



printf("You inputted a negative number
--
> Order is %i", i+1);


else



printf("The numbers less than
%i

is %i",
MAXNUMBER,
numcount);



return

0;

}



28



2.9.

Scope Rule


The basic rule of scoping is that identifiers ar
e accessible only within
the block in which they are declared.

They are unknown outside the
boundaries of that block.




int

main(
int

argc,
char

* argv[])

{


int

number1,number2
;



number1
=5
, number2=12
;



block1:


{


int

number1
=2;



printf("block1
number1
= %i ",
number1
);
/* block1 a */







}



printf(" main
number1
= %i ",
number1
);
/* main a */




return

0;

}















29

2.10.

Functions


The reason for writing functions is
to
divid
e

a problem into

simpl
e
problems
. So, you can solve problem easily, and also if any changes
are

required it will be
limited only one or more functions
.


Function parameters can be called by
value

or
reference
. The
difference is that a copy variable for former parameter type is c
reated
in called function, but the reference for the calling variable is used in
called function for the latter parameter type.



Pointers and arrays are
reference

variables. B
ut if you use another
data type parameter
and mean to change value in function t
hen you
should send address of th
is v
ariable. For this
&
operator is placed
beginning of the variable name while function called. However
function declaration is represented by
pointer variable

for the
referenced parameter.


#include <stdio.h>

void swap(in
t x, int y);


int main()

{


int x = 4;


int y = 2;



printf("Before swap, x is %d, y is %d
\
n",x,y);


swap(x,y);


printf("After swap, x is %d, y is %d
\
n",x,y);

}


void swap(int first, int second)

{


int temp;



temp = second;


secon
d = first;


first = temp;

}



30


#include<stdio.h>


void swap(
int *x
,
int *y
);


int main()

{


int x = 4;


int y = 2;



printf("Before swap, x is %d, y is %d
\
n",x,y);


swap(
&
x,
&
y);


printf("After swap, x is %d, y is %d
\
n",x,y);



return 0
;

}


void swap(int *first, int *second)

{


int temp;



temp = *second;


*second = *first;


*first = temp;

}


2.11.

C Library and Some Functions


1.

I
nput and output

functions(keyboard)


Library: <stdio.h>


int
getchar(
void
)

int
putchar(
int
)

int
scanf(
char *
cntrl_string
,

parameter list
)

int
printf(
char *
cntrl_string
,

parameter list
)





31

cntrl_string

includes the following
variable definition format, escape
characters and text
.


Format

Parameter
Data Type

%d

Int

%c

Character

%x

int for hexadecimal sy
stem (letters are small)

%X

int for hexadecimal system (letters are capital)

%o

int for octal system

%u

unsigned int

%ld

L
ong

%lx

long for hexadecimal system

%f

F
loat

%lf

D
ouble

%p

Pointer

%s

S
tring


Note :

%f format is used for both float and do
uble in printf


Escape Character

Usage

\
a

Bell ring

\
b

Backspace

\
f

Form feed

\
n

New line

\
r

Carriage return

\
t

Tab

\
v

Vertical Tab

\
\

Back slash

\


Double quote

\
0

NULL



32


2.

Character test functions

Library: <ctype
.h>



int isalpha
(
int c
)


-
-
is alphabetic

int isdigit
(
int c
)


--
is digit: 0
-
9

int islower
(
int c
)


--
is lowercase

int isupper
(
int c
)


--
is uppercase

int is
space
(
int c
)


--
is
whitespace (space,form feed,newline,carriage return,
horizontal tab,vertical tab)



3.

String functions


Libr
ary: <string.h>



int
strlen
(
char *

str
)


--
returns

str length


char *
strchr(char *

str
,

char

chr
)

--
search
es

chr in str
,

returns
its address

if found

otherwise

return
NULL


char *
strcpy(char *

destination ,
char *

source
)

--
copy
source stri
ng

onto the
destination
string



int
strcmp
(
char *

str1,
char *

str2
)


--
returns

pozitif number if str
1

is greater

than str2


negative if str
1

is smaller

than str2


zero both string are equal


char *
str
cat
(
char *

destination
,char
*
source
)


--
Attaches
source

string at the end of
destination

string





33

There is some functions widely used instead of strcpy,

strcmp and
strcat , called
n

versions. n meaning limits the function

operation

for a
given
length.


char * str
n
cpy
(
char
* d
estination
,

char *

source
,

i
nt
length
)



int str
n
cmp
(
char *

str1
,char *

str2
,

int
length
)



char *str
n
cat
(
char *

destination
,char *

source
,

int
length
)



4.

String
Conversion
functions


Library: <st
dlib
.h>



double atof
(
const char * str
)


--
Convert
s the

str
to
a
double and returns it


int atoi(char * str)

--
Converts the

str to an int and returns it


long atol(char * str)

--

Converts the

str
to a long and returns it


5.

File functions


Library: <st
dio
.h>



FILE *

fopen(char *filename,char *
mode)



--
open the file


Mode

Meaning

“r”

佰敮⁴lx琠晩l攠eo爠牥a摩ng

“w”

佰敮⁴lx琠晩l攠eo爠wri瑩ng

“a”

佰敮⁴lx琠晩l攠eo爠慰灥湤png

“rb”

佰敮⁢inary⁦ l攠eor⁲敡di湧

“wb”

佰敮⁢inary⁦ l攠eor w物瑩ng

“ab”

佰敮⁢inary⁦ l攠eor⁡灰敮 ing


If


+
’ op
erator used in mode , for example “r+”
,then operation will
be assumed for both writing and reading.



34

int fclose(FILE
*
filepointer
)

--
close the file


int

fgetc
(
FILE

*

filepointer
)


--
reads a character from the file


int
fputc
(
int
ch,
FILE

*
filepointer
)


--
puts a character into the file


int * fgets
(
char * str, int length, FILE * filepointer
)


--
reads a string from the file


int fputs
(
char * str,FILE *filepointer
)


--
puts a string into the file


int

feof(FILE
*
filepointer
)


--
Check if the end of t
he file is reached


int fprintf(FILE *filepointer, char * format
, parameter list
)


--
formatted write into the file


int fscanf(FILE *filepointer, char * format, parameter list
)


--
formatted read from the file


int fseek(FILE *filepointer, long offset, in
t origin
)


--
sets file pointer location
, origin may be
0:
SEEK_SET
,1:
SEEK_CUR
,2:
SEEK_END


void rewind(FILE *filepointer
)


--
sets the file pointer at the beginning of file


long ftell(FILE *filepointer
)


--
tells the location of filepointer


unsigned

f
read
(
void *ptr, unsigned size, unsigned length,
FILE
*filepointer
)


--
block

read from the file
, read byte is defined by
multiplying
size&length




35

unsigned fwrite(
const
void *ptr, unsigned size, unsigned length,
FILE *filepointer
)


--
block write to the

file


6.

Memory

functions


Library: <st
dlib
.h>



void *calloc(size_t n, size_t size
)


--
Allocates contiguous space in memory for an array of n
elements, with each element requiring size bytes.

The space
is initialized with all bits set to zero.


void

*
mallo
c
(
size_t

size
)

--
Allocates a block of space in memory consisting of size
bytes. The space is not initialized.


void

*
realloc
(
void

*

ptr

,
size_t

size
)


--
Changes the size of the block pointed to by ptr to size
bytes.



void

free
(
void

*
ptr
)


--
Causes

the space in memory pointed to by ptr to be
deallocated





#define

SHARP '#'

#define

MAXWORD 20

#define

MAXLEN 200


int

wordcount;

char

* words =(
char

*) malloc(
sizeof
(
char
)*MAXLEN+1);

int

wordpoint[10];

int

wordnum,i,size;


void

changeword
s(
int

,
int

);






36

int

main(
int

argc, char * argv[])

{


char

* sentence=(
char

*)malloc(
sizeof
(
char
)*MAXLEN+1);


char

* wsentence=(
char

*)malloc(
sizeof
(
char
)*MAXLEN+1);


char

* tempstr;


printf("Enter Sentence : ");


scanf("%s",sentence);






wordnum=0;


tempstr=sentence;




/* Parse the string into the words*/


wordcount=0;



while

((wsentence=strchr(tempstr,SHARP))!=NULL)


{



size=strlen(tempstr)
-
strlen(wsentence);



strncpy(words+wordnum,tempstr,size);



wordpoint[wordcount++]=wordnu
m;



*(words+wordnum+size)='
\
0';



wordnum+=size+1;



tempstr=wsentence+1;



//wordcount++;




}




if

(strlen(tempstr)>0)


{



size=strlen(tempstr);



strncpy(words+wordnum,tempstr,size);



wordpoint[wordcount++]=wordnum;



*(words+wordn
um+size)='
\
0';




wordnum+=size+1;



tempstr=wsentence+1;




}




for

(i=0;i<wordcount;i++){



printf("%d.kelime
-
> %s
\
n",i,words+wordpoint[i]);



printf("%d.kelime
-
> %d
\
n",i,wordpoint[i]);


}





37


changewords(1,3);



for

(i=0;i<wordcount;i
++){



printf("%d.kelime
-
> %s
\
n",i,words+wordpoint[i]);



printf("%d.kelime
-
> %d
\
n",i,wordpoint[i]);


}




system("pause");


return

0;

}


/* Change memory locations */

void

changewords(
int

wordnum1,
int

wordnum2)

{


char

* tempbuf =(
char

*) malloc(
sizeof
(
char
)*MAXLEN+1);


int

temppoint[10];



int

small=wordnum1 < wordnum2 ? wordnum1:wordnum2;


int

big =wordnum1 > wordnum2 ? wordnum1:wordnum2;





/* Make a copy of memory and copy the big memory part onto the small */


for

(i=0,wordnum=0 ;i<wordcou
nt;i++)


{



if

(i==small)




strcpy(tempbuf+wordnum,words+wordpoint[wordnum2]);






else

if

(i==big)




strcpy(tempbuf+wordnum,words+wordpoint[wordnum1]);






else




strcpy(tempbuf+wordnum,words+wordpoint[i]);






size=strlen(tempbuf+wordnum);





pri
ntf("size:%d",size);



temppoint[i]=wordnum;





*(tempbuf+wordnum+size)='
\
0';




wordnum+=size+1;




}




38


memcpy(words,tempbuf,
sizeof
(
char
)*MAXLEN+1);



for

(i=0 ; i<wordcount;i++)



wordpoint[i]=temppoint[i];

}



#include

<stdio.h>

#in
clude

<stdlib.h>


void

double_space(FILE *, FILE *);

void

prn_info(
char

*);


int

main(
int

argc,
char

*argv[])

{



FILE *ifp, *ofp;



if

(argc!=3){


prn_info(argv[0]);


exit(1);


}


ifp =fopen(argv[1],"r");


ofp =fopen(argv[2],"w");


double_space(ifp,o
fp);


fclose(ifp);


fclose(ofp);


return

0;

}


void

double_space(FILE *ifp, FILE *ofp)

{


int

c;



while

((c=getc(ifp))!=EOF){


putc(c,ofp);


if

(c=='
\
n')



putc('
\
n',ofp);

}




39

void

prn_info(
char

*pgm_name)

{


printf("
\
n%s%s%s
\
n
\
n %s%s
\
n
\
n",



"Usage
: ", pgm_name, " infile outfile",



"The contents of infile will be double spaced ",



"and written to outfile.");

}



3.

C++



C programming language was emerged
by Dennis Ritchie
at Bell
Laboratories in 1960’s. This was the start of struct
ured programming.
It is a powerful, aesthetic language which has gained more popularity
within programmers in a short time. By the way the projects size
increased unexpected way in 1970’s. Society noticed that C

(also
other structured languages)

couldn’t s
upport easy development of
projects which line size was over 3K or more. And also the need for
quick software development was become an important issue. Every
project was to start from beginning and no code was reusable.


These reasons started a new resear
ch for big projects. C with Class
was born at

Bell Laboratories in 19
79
.

Bjorne Stroustrup was the
father of idea. He changed the name as C++ in 1983. The meaning of
C++ is that it covers C language and moreover it is an object
-
oriented
programming languag
e.


C++ finished its evolution in 1990. Object
-
oriented programming
technique and languages has gained more popularity during this time.
To prevent misunderstanding and deviation, C++ standards was
defined in 1998(ISO/IEC 14882).





3.1.

History



40

3.2.


Weaknesses




Bac
kward Compability to C


C++ was developed on top of C,

and it has therefore retained a
very high degree of C compability.
However, many C
weaknesses have been merged into C++ as well. These involve
dealing with raw pointers, some not
-
so
-
straightforward
aut
omatic conversions, and a lot of error
-
prone functions such
as strncpy, memcpy, etc.




GUI


C++ does not mix well with GUIs. Simple tasks
-
such as adding
or removing a splitter, manipulating Property Pages, showing
tool tips, and handling menus are really
complicated to
implement in C++.




No Conforming Compilers


There is no compiler that fully implements the ANSI C++
standard, which was released in 1998.

Because C++ has so
many features that interact with each other, sometimes in a
surprising manner, compi
ler errors are common. Depending
on the code in question, compilers may generate a compiler
error on a good program, or successfully compile an ill
-
formed
program.




Portability


Due to the complexity of C++ and the fact that built in types
are not required

to have a fixed size
-

for example, on one
platform, int might occupy two bytes while on another
platform it may occupy four bytes
-

it is very hard to write a
portable code. Therefore, when switching from one compiler to
another, you might experience bugs
that are hard to find and
fix.




41



Bad Compile
-
Time Error Messages When Using Generic
Programming


A compile
-
time error generated when using generic
programming libraries will be so cryptic that you will usually

need to help an experienced programmer to deci
pher it.




Many String Implementations


A plethora of string classes exists, many with dubious features.
In addition, there still are programmers using raw functions
like strcat. The issue complicated even more by the fact you
can have ANSI strings(formed o
f one byte chars) and Unicode
strings(formed of two
-
byte or four
-
byte strings)



3.3.

Strengths





Support for Generic Programming


Generic programming allows programmers create algorithms
that will work with any data type, as long as data satisfies a
certain co
ncept. Therefore, the reusability of generic
programming classes and algorithms is an order of magnitude
higher than OOP. For example, C++ STL can handle arrays
and collections very efficiently.




Efficiency


C++

is the

younger and safer
brother

of C.

Sin
ce C was all
about of efficiency, Bjourne Stroustrup made C++ as efficient
as possible while also providing extra (type) safety.









42



Both High and Low Level Programming


C++ allows you to program at the level you desire, depending
on the module you are w
orking on. While high
-
level
programming is often preferable, there are times when you
need to get down and dirty and programs at low levels (for
instance, when developing drivers), and C++ provides you that
opportunity.




Enforcing the Const Keyword


The co
nst keyword in C++ makes programming safer. If you
know that your function won’t modify a parameter, you will
say so by making the parameter const. If by mistake you
modify that parameter, a compile
-
time error will occur. In
large applications this is a gr
eat help, just by looking at a
function, you will know
which arguments will be modified and
which will not.





Streams


Writing to and reading from streams is very simple and
straightforward. As a bonus, there are in
-
memory
-
streams(istringstream, and ostrin
gstream) that you can work
with.


out << users<< “users logged on at” << now; //writing


in >> a >> b; // reading




Multi
-
Paradigm Support


C++ does not force any single paradigm(such as OOP) on the
programmer. Different applications and even different
modules may require different paradigms.








43


3.4.

Best Uses




Efficiency is an issue.




Your application has a little or no GUI




You are dealing with lots of arrays and collections of custom data
-
types.




You need to do low
-
level programming




You are developing
a server application(other than a Web server
application)




You are increasing the speed of an application by moving the
heavy processing into a Component Object Model (COM)
compenent.


4.

OBJECT
-
ORIENTED CONCEPT
S



1.

It

is well
-
adjusted to human mind. It helps developers
understand user requirements correctly and easily.


2.

It supports easy development
,

especially for complex
systems.


3.

It decreases cost and time required for maintenance.


4.

It constructs more reliable system
s
.


5.

It reduces
size

of
the
code.


6.

It
produces re
-
usable code.


4.1

Advantages of Object
-
Oriented Techniques



44






Class



A class is a description of a group of objects with common
properties (attributes), behavior (operations), relationships, and
semantics













4.2

Terminology

Sample Class



Class


Course

Properties

Name

Location

Days offered

Cre
dit hours

Start time

End time

Behavior

Add a student

Delete a student

Get course roster

Determine if it is
full



45




Representing

C
lasses


A class is represented using a compartmented rectangle




The first section contains the class name




The second section shows the structure (attributes)




The third section shows the behavior (operations)





Lecturer

name

emp
Id

c
reate()

c
hange()

s
ave()

d
elete()






In other words class is a unit

that is
packaging related data

and
functionality

together. Class is the basis of modularity and
structure in an object
-
oriented computer program.







46

Header File


class Vehicle

{



private: int engine;//
Property or state variables





char *

color;




int model;



char *

brand;


int speed;


int maxspeed;




int gear;




…………

public: Vehicle(); //
Constructor


~Vehicle(); //
Destructor





//
Member functions


int getEngine();


void setEngine(int);




char *

getColor();




v
oid setColor(const char*);





…….




int accelerate(int);




int brake(int);




…….

}
;



Definition File


Resolution Operator


int
V
ehicle::ac
celerate(int value)

{





int newspeed = speed + value;




if (newspeed<=maxspeed) speed=newspeed;




return speed;


}



47





Object




Informally, an object represents an entity, either physical,
conceptual, or software



A
n object is something that has




State



Behavior



Identity











truck

Linked List
Data Structure


Chemical Process

Physical Entity

Conceptual Entity

Software Entity



48

The
state of an object

is represented by its
attribute values
.







Behavior
determines how an object
acts

and
reacts

to
requests

from other objects
. It is

repr
esented by the set of
messages

it
can respond to (the operations the object can perform)
.





Each object has a unique identity, even if its state is identical to
that of another object
.








CS617 CS412

CS617

Assign Metin TURAN

Confirmation

Name :

Metin

Employee Id :

489

Birth Date:

Oct 14,1967

Title :

Lecturer

Status :

Teaching

Registration System

Name :

Metin

Employee Id :

489

Birth Date:

Oct 14,1967

Title :

Lecturer

Status :

Teaching



49


Representing

Objects



An object is represented as rectangles with

underlined names







A unique instance of a data structure defined according to the
template

provided by
its class
. Each object has its
own values
for the variables

belonging to its class and can respond to the
messages

(meth
ods) defined by its class.


If we
wanted to
use
vehicle class the main would be like as

follow;


#include ".
\
vehicle.h"


using namespace

std;


int main(int argc, * argv[])

{






Ve
hicle
*
v1
=new Vehicle
;

// Create an object or instance




const char*

red="RED";






v1
-
>
setColor(red);

Hidden parameter
this

passes






cout << v1
-
>
getColor();






return 0;


}



:
Lecturer

Metin TURAN

:
Lecturer

Metin TURAN



50


A
bstraction
:
Also called g
enerali
z
ation
:

ignoring or hiding
details to capture s
ome kind of commonality between different
instances.


When one family builds a wall, two families benefit from it


-

Chinese proverb



Functional abstraction

means that
a functi
on can be used
without taking into account how the function is implemented.

F
or the following functions, you don’t care how the functions
are implemented, but only what they do and how to invoke
them.






Examples:


<string.h> :
strcat(), strcmp(), strcpy(), strlen()


<math.h> :
ceil(), sin(), exp(), log()




Data

abs
traction

means that
data

can be used without taking
into account how the
data

are stored.

For the following data
types, you don’t care how the data are stored, but only what
operations are provided and what properties are supported.


int i,j,k; // i

+ 0 = i


// i*(j+k) = i*j + i*k


float x,y; // floor(x) <= x


// ceil(x) >= x



5.1

Features





51




Technically, all data types are abstract:




No unique way to store data bits



No need to know how the bits are stored



No need to kn
ow how the operations are performed;
only need to know what properties are supported when
the operations are performed.



Abstract Data Type
(ADT) i
s refer to new types of data,
defined by the programmer, where the implementation
details are hidden from th
e user, and access to the data is
provided through an interface to a specific set of
operations.


Stack or list data type implementations are the examples
of ADT.

// Source code Uslist1



C
onst int LISTSIZE=100



class List

{

private:


int intlist[LIST
SIZE];




int size;


public :


List() {size=0;} // Default constructor





int getLength() { return size;}



void insertItem(int, int ,bool &);


void removeItem(int, bool &);

int retrieveItem(int , int &, bool &);


}




52

void List::i
nsertItem(int pos,int newitem,bool &success)

{


success= bool(pos >=1 && pos <= size+1

&&





size < LISTSIZE);





if (success){






for (int i = size; i >= pos; i
--
)




intlist[ i ] = intlist[ i


1];







intlist[pos
-
1 ] = newitem;







size++;


}

}



void List::removeItem(int pos, bool &success)

{


success= bool(pos >=1 && pos <= size);










if (success){






for (int i = pos; i < size ; i++)




intlist[ i ] = intlist[ i


1];







intlist[i
-
1 ] = intlist[ i ];







size
--
;


}


}


in
t List::retrieveItem(int pos, int &item, bool &success)

{


success= bool(pos >=1 && pos <= size);







if (success) item= intlist[ pos


1];




}




53



Encapsulation
:

Al
so called
information hiding
:
The ability to
provide users with a well
-
defined interface to a set of functions
in a way which hides their internal workings.
Ensures tha
t users
of an object cannot change the internal state of the object in
unexpected ways; only the object

'

s own internal methods are
allowed to access its state
.
The definitions of encapsulation
focus on the grouping and packaging of related information
(
cohesion
) rather than security issues.



#include ".
\
vehicle.h"


using namespace

std;


int

main(int argc,
*

argv[])

{



Ve
hicle
*
v1
=new Vehicle
;


const char* red="RED";



/* s
trcpy(
v1
-
>
c
olor
,
red
);



that is forbidden,no access

*/




v1
-
>
setColor(red);





cout << v1
-
>
getColor();





return 0;


}











54


Inheritance

:

Organizes and facilities polymorphism and
encapsulation by permitting objects to be defined and crea
ted
that are specialized types of already
-

existing objects


these
can share (and extend) their behavior without having to
reimplement that behavior. This is typically done by grouping
objects into classes, and defining classes as extensions of
existing c
lasses, thus and grouping classes into trees or lattices
reflecting behavioral commonality.


class

Class1
// The base class

{





protected
:



int

var1;



int

var2;



static

int

staticvar1;


public
:



Class1() {};



~Class1() {};



static

void

func
1() {};



static

void

func2() {};



static

void

func3() {};



};


class

Class2 :
public

Class1
// The derived class

{



int

var1;


public
:



void

func1();

};


int

Class1:: staticvar1=5;
// Sets class Class1’s staticvar1
=
=
void
=
䍬~ss2WW晵ncN⠩
=
{
=
††
v慲~=NMX†††††††==
// Sets Class2’s var1
=
††
䍬慳sNWWv慲N=N5X†=
// Sets Class2’s Class1::var1
=
††
v慲~=2MX†††††††==
// Sets Class2’s Class1::var2
=
}
=


55



int

main()

{



Class2 *obj=
new

Class2;



obj
-
>func1();


// Uses Clas
s2’s func1()



obj
-
>Class1::func1();


// Uses Class2’s inherited



Class1::func1();




obj
-
>func2();
// Uses Class1’s inherited



Class1::func2();


return

0;

}



In C++, inheritance defines an "is a" relation
ship. The
derived
class

is a type of its base class. For instance, a "cat" class could
be derived from an "animal" class. A cat is an animal. A cat is a

type of animal. A derived class inherits both the
properties

and
member functions

of its base class. It may also define additional
properties

and
member functions

that support specialized
functionality.


The last thing
constructors
,

destructors
,
friend functions
,
static
class functions
,
static class data
,
copy constructors

are not
inherited. Each subtype has its own constructor and destructor.
The reason

for this is that each object of a subtype consists of
multiple parts, a base class part and a subclass part.


Multiple inheritance is possible in C++.













56

Polymorphism

:

Different things or objects can have the same
interface or answer the same message (based on message name)
and respond appropriately depending on the thing's nature or
type. This potentially allows multiple things to

be
interchangeable with each other. For example, if a bird receives
the message "move fast", it will flap its wings and fly. If a lion
receives the same message, it will run with its legs. Both
answer the same request, but in ways appropriate to each
crea
ture.


#include <iostream>


using namespace std;


class Polygon

{


protected:


int width, height;



public:


void
setWidth

(int a) { width=a; }


void
setHeight

(int
b
) {
height
=
b
; }


int area (void) { return (width * height); }


};


cla
ss Rectangle: public Polygon

{


public:


int area (void) { return (width * height); }

};



class Triangle: public
Polygon

{


public:



int area (void) { return (width * height / 2); }


};






57


int main ()


{



Rectangle rect;



Triangle

trg
l;



Polygon * poly1 = &rect;



Polygon * poly2 = &trgl;



poly1
-
>set
Width
(4);


poly1
-
>set
Height
(
5
);




poly
2
-
>set
Width
(4);


poly
2
-
>set
Height
(
5
);



cout << rect.area() << endl;



cout << trgl.area()

<< endl;



return 0;


}



The only limitation
of using
*poly1

and
*poly2

instead of
rect

and
trgl

is that both
*
poly1

and
*
poly2

are of type
Polygon*

and therefore we can only refer to the members
that
Rectangle

and
Triangle

inherit from
Polygon
. For
that reason when calling the
area()

members we have

not
been able to use the pointers
*poly1

and
*poly2
.


Dynamic Binding:

Object
-
Oriented programming extends the
use of ADT s to permit a new type to be derived through the
mechanism of inheritance and to delay until run
-
time

whether a
base class
version o
f a redefined function or the derived class
version is called through the mechanism of dynamic binding.


#include <iostream>


using namespace std;


class Polygon

{


protected:



int width, height;


public:



58



void
setWidth

(int a) { width=a; }



void
setHeight

(int
b
) {
height
=
b
; }


virtual int area(void) {return 0;}

};


class Rectangle: public Polygon

{


public:



int area (void) { return (width * height); }


};


class Triangle: public
Polygon

{


public:



int area (void) { return

(width * height / 2); }


};



int main ()

{



Rectangle rect;



Triangle trgl;



Polygon poly;



Polygon * poly1 = &rect;



Polygon * poly2 = &trgl;



Polygon * poly3 = &poly;



poly1
-
>set
Width
(4);


poly1
-
>set
Height
(
5
);




poly
2
-
>set
Width
(4);


poly
2
-
>set
Height
(
5
);




poly
3
-
>set
Width
(4);


poly
3
-
>set
Height
(
5
);




cout << poly1
-
>area() << endl;



cout << poly2
-
>area() << endl;



cout << poly3
-
>area() << endl;



return 0;

}






59

Overriding:

A
derived class

can use the methods of its
base
class
(es), or it can
override

them. The method in the derived
class must have the same signature and return type as the base
class method to override. The signature is number and type of
arguments a
nd the constant
ness

(const, non
-

const) of the
method.


It is a result of
both
polymorphism and inheritance. For
example you may not write area member function for Rectangle
class. It would
inherit

area member function of Polygon class.


Overloading:

One f
unction can be used
more than once
in a
project with the same name. Every definition works as a
different function. This is called overloading. Every function
template has its own sign. Sign is determined by the function
argume
n
t

order, type
and number
. Re
turn type is not important.



#include <iostream>


using namespace std;


int Max(int number1, int number2)

{


return number1 < number2 ? number2 : number1;}

}


char Max(char char1, char char2)

{


return char1 < char2 ? char2 : char1;}

}


int main()

{


int

var1=Max(10,12);


char var2=Max(‘B’,’A’);
=
=
=
cout << “Greater character is “ << var2;
=
†††††
cout << “Greater number is “ << var1;
=
=
}
=


60

Operator Overloading:
The C++ language provides a set of
operators that can be used on built

in data types of the
lan
guage. For example, the + operator can be used with
shorts,ints,longs,floats and doubles. But C++ have no idea what
to do with user
-
defined data types. When designing a class,you
may want to provide a set of operators that work on the objects
of the class.


#include <iostream>

using namespace std;


class Complex

{


double real,imag;

public:


Complex() {};


Complex(double r, double
i
) { real=r; imag=i;}


Complex operator+(Complex);


void display(){ cout << real << “ + “ << imag << ‘
y
n’;}
=

=
=
䍯mpl數†Compl數WWop敲慴o爫⡃EmplexumN)
=
{
=
=
䍯mpl數=t敭pX
=
=
t敭p⹲敡.†㴠=his
-
㹲敡l†⬠
numN
⹲敡.X
=
†††††
temp⹩.慧㴠瑨is
-
[im慧‫=
numN
⹩m慧X
=
=
牥ru牮=t敭pX
=
}
=
=
int†m慩n⠩
=
{
=
=
䍯mpl數⁣ompN⠲.4IN2.N⤬)omp2⠴.3ⰳIN⤬捯mpt敭pX
=
=
捯mpt敭p㴠捯=pN‫=捯mp2X
=
=
捯m
pt敭p⹤.spl慹⠩E
=
=
=
䍯mpl數⁣omp
3
⠴.4IN2.N⤬)omp
4
⠶.3ⰳIN⤬捯mpt敭pX
=
=
捯mpt敭p㴠捯=p
3
⹯.敲eto爫⡣omp
4

=
⼯L
ft⁩=⁡lso⁡=function
=
=
捯mpt敭p⹤.spl慹⠩E
=
}
=


61


5.

DIFFERENCES BETWEEN C AND C++


5.1.

Comments


C++ allows you to begin a comment with
//

and use the remainde
r of
line for comment text
.


I
nt main()


{


int var1=Max(10,12); //
call integer max function


char var2=Max(‘B’,’A’);
=
=
†††††
/* Display max values




C style comment is still exist
*/


cout << “Greater character is “ << var2;
=
†††††
cout << “Greater number is “ << var1;
=
=
=
}
=

5.2.

Declaration within Blocks


A
declaration

introduces an identifier to the compiler. It declares how it
should look like.

A
definition

says create it, in other words, allocates memory.



function declaration





int get(void)

;










62


class description




class Description{


private

: String description

;




public


: Description()

;


~Description()

;


void displayDesc()

;




}

;





definitions




int weight;



Description d1,d2;



Declarations and descriptions
can only be

defined at the beginning of
any block(any executable code before them is inhibited)

in C. However
in C++, y
ou can use declarations and definitions anywhere inside the
code before they are used.
Moreover they obey the scope rule.



{int i=12;



if (num>20){ ….
=
=
††††††=
….
=
††††††=
int⁩
=
=MX=
=
††††††=
….
=
††††††=
景爠⡩湴⁩=M
=
X=i㱍慸
=
Xi⬫⥻
=
=
=
=
†††=††=
素LL⁦潲
=
=
††††
累}if
=
=
††
累}m慩n
=




63

Resolution operator

can also be used for scoping. In other words, it is
possible using a hidden global name by the resolution operator.