






















Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
Prepare for your exams
Study with the several resources on Docsity
Earn points to download
Earn points by helping other students or get them with a premium plan
These are the lecture notes for ece 575: object-oriented modeling and programming in c++, taught at the university of arizona during the fall semester of 2006. The notes cover topics such as object-oriented programming, object modeling, inheritance, abstract and concrete classes, constructors and destructors, virtual functions, static and constant functions, value, pointer, and reference, and stack vs heap memory.
Typology: Papers
1 / 30
This page cannot be seen from the preview
Don't miss anything!























1
Moon Ho Hwang [email protected]
2006 Fall ECE Department,University of Arizona
© 2006 Moon Ho Hwang
2
Categorization ofProgram Languages^ ECE 575, Dept. of ECE,
Structured Programming Language^ ^
FORTURAN, COBOL, ^
C, Pascal ^
Object-Oriented ProgrammingLanguage ^
C++ ^
Java, C# ^
Python
Modeling OOM/P
© 2006 Moon Ho Hwang
4
Modeling OOM/P
class Student{
string Name;string ST_id;void Do_Take_Class() const{ cout << “take a class.”<< endl;} }; Figure1. C++ code for Student class.
© 2006 Moon Ho Hwang
5
Modeling OOM/P
class Professor{
string Name;string EP_id;void Do_Teach_Class() const{ cout << “teach a class.”<< endl;} }; Figure2. C++ code for Professor class.
© 2006 Moon Ho Hwang
7
Modeling OOM/P
© 2006 Moon Ho Hwang
8
Modeling OOM/P
Person String Name;void Do();
Student String ST_ID;void Take_Class();void Do();
Professor String EP_ID;void Teach_Class();void Do();
Base/parentclass
Derived/childclass
© 2006 Moon Ho Hwang
10
Making Abstract/Concreteclasses ECE 575, Dept. of ECE,
Modeling OOM/P
^
Member Encapsulation:^ public, protect, private ^
Using encapsulation of
Constructor
class Person{ protected
: string Name;Person(string name): Name(name){}};
class Student: public Person{ public
: Student(string name):Person(name){} };
© 2006 Moon Ho Hwang
11
Making an Abstract/Concreteclass (cont.) ECE 575, Dept. of ECE,
Modeling OOM/P
^
Using
pure virtual
functions
virtual void Do() = 0; };
© 2006 Moon Ho Hwang
13
Modeling OOM/P
© 2006 Moon Ho Hwang
14
Modeling OOM/P
class Student: public Person{…/virtual/ void Do(){ cout << Name << " takes ECE575." << endl;} };
class Professor: public Person{ public:/virtual/ void Do(){ cout << Name << " teachs ECE575." << endl;} };
© 2006 Moon Ho Hwang
16
Modeling OOM/P
^
A function with its body of a derived classis called a
overriding
function.
^
void Student::Do() { /* … */ } ^
Notice that
overloading
functions are a
set of functions whose names areidentical,
with different arguments.
^
void Student::Do(int n){ /* … */ }
© 2006 Moon Ho Hwang
17
Modeling OOM/P
^
In Java, all functions are virtual. ^
In C++ and C#, only functions having amodifier
virtual
are virtual.
^
If we define
all
functions as
virtual
(or
overriding
) functions, what can be
advantage or disadvantage? ^
Advantage: Easy to use ^
Disadvantage: Slower and bigger memorystorage ^
See
VirtualFuncs
Example.
© 2006 Moon Ho Hwang
19
Modeling OOM/P
class Person{ public:
virtual static Do(); };
© 2006 Moon Ho Hwang
20
constant function (in C++)ECE 575, Dept. of ECE,
Modeling OOM/P
^
A constant function is a function in whichdata of an instance cannot change. Wecan access data for
reading
but not
writing
.
class Person{ string Name;string get_name() const { return Name; }void set_name(string n) const {Name
= n; }//<-wrong
}