c++ lectures by Dr.Mohamed Torad, Slides of Computer Science

lecture slides of compuuuuter Engineeeering softwaaaare

Typology: Slides

2020/2021

Uploaded on 05/27/2021

nour-el-sayed
nour-el-sayed 🇪🇬

1 document

1 / 27

Toggle sidebar

This page cannot be seen from the preview

Don't miss anything!

bg1
Computer Engineering II
Lecture 6
EEC 124
pf3
pf4
pf5
pf8
pf9
pfa
pfd
pfe
pff
pf12
pf13
pf14
pf15
pf16
pf17
pf18
pf19
pf1a
pf1b

Partial preview of the text

Download c++ lectures by Dr.Mohamed Torad and more Slides Computer Science in PDF only on Docsity!

Computer Engineering II

Lecture 6

EEC 124

Data Abstraction, Classes, and Abstract Data Types

Separating the design details from its use is called abstraction.

A struct Versus a class

This definition of components in a struct included only member variables.

However, a C++ struct is very similar to a C++ class. As with a class, members

of a struct can also be functions, including constructors and a destructor.

The only difference between a struct and a class is that, by default, all members

of a struct are public, and all members of a class are private.

You can use the member access specifier private in a struct to make a member

private.

Information Hiding

Is it a good practice to include the specification and implementation details of a

class in the program? Definitely not.

There are several reasons for not doing so. Suppose the definition of the class

and the definitions of the member functions are directly included in the user’s

program. The user then has direct access to the definition of the class and the

definitions of the member functions.

Thus, we must hide the implementation details.

To implement clockType in a program, the user must declare objects of type

clockType and know which operations are allowed and what the operations do.

So, the user must have access to the specification details. Because the user is

not concerned with the implementation details, we must put those details in a

separate file called an implementation file.

therefore, put the specification details in a separate file. The file that contains

the specification details is called the header file (or interface file ).

Information Hiding

Information Hiding

Information Hiding

Executable Code

Executable Code

Executable Code

Executable Code

Static and Automatic Variables from Ch

The following program shows how static and automatic variables behave.

Memory for the variable y is allocated and deallocated every time the function test is called. So, it prints the same value for y. However, because x is a static variable, memory for x remains allocated as long as the program executes.

Static Members of a Class