+ All Categories
Home > Documents > Introduction to Object-Oriented Programming

Introduction to Object-Oriented Programming

Date post: 16-Jan-2023
Category:
Upload: apcoms
View: 0 times
Download: 0 times
Share this document with a friend
25
1 Advanced Object-Oriented Programming
Transcript

1

Advanced Object-Oriented Programming

2

Introduction• Introduction• Pause to Look Backwards and Forwards

• Course Objectives• Course Operation/Expectations• Course Plan and Syllabus• OO Basic Concepts

3

Look Backwards and Forwards

• Students– Expected Background– Going Forward– Your Future

Course Objectives• To expose students to Object oriented design strategy and problem solving, objects and classes,

• To learn various important OO concepts, i.e. – member functions,– public and private members,– dynamic memory management,– constructors and destructors,– templates, – object encapsulation,– derived classes,

4

Course Objectives– class hierarchies,– inheritance and polymorphism, – operator overloading,– stream class, – practical design through object-oriented programming.

• To learn the advantages of programming in an object-oriented language such as C++.

• To experience programming in the

Large 5

6

Course Operation/Expectations

• The course web site:–????????

• Contains:–• Syllabus• General overview• Rules and expectations• All lecture notes• All programming and lab assignments

• …

You are responsible for

everything on the course

web site

7

Course Operation/Expectations (continued)

• Labs per week ??

• Approx 6 Assignments and 6 quizzes

• 2 Exams• Mid-term• Final

Plagiarism Policy

•  No Plagiarism will be tolerated.

• Any attempt of copying code during the lab and assignment will result in a disciplinary action and zero marks in that lab/assignment to the students.

• The quizzes will be mostly unannounced and normally last for fifteen minutes. It will be the instructor’s will to choose the number of quizzes for evaluations purposes.

8

Plagiarism Policy

• In order to give practice and comprehensive understanding of subject, home assignments will be given.

• Late assignments will not be accepted / graded.

9

10

Grading

• Exams:– ~60%• Mid Term:- 20%• Final Term:- 40%

• Assignments and Quizzes:– ~20%

• Labs and Subjective Evaluation:– ~20%

Satisfac

tory gra

des in L

abs are

required to pass this course

11

Recommended Books• Object Oriented Programming in C++

• Fourth Edition,

• Robert Lafore

12

Alternative Textbook• Deitel & Deitel

– How to Program

13

Questions?

A sample Code in C++• */• // include header file with the class

declaration• #include "frac.hpp"

• // include standard header files• #include <iostream>• #include <cstdlib>

• // **** BEGIN namespace CPPBook ********************************

• namespace CPPBook {

14

A sample Code in C++…• /* default constructor• */• Fraction::Fraction()• : numer(0), denom(1) // initialize fraction

with 0• {• // no further statements• }• /* constructor for whole number• */• Fraction::Fraction(int n)• : numer(n), denom(1) // initialize fraction

with n• {• // no further statements• }

15

A sample Code in C++…• /* constructor for numerator and denominator• */• Fraction::Fraction(int n, int d)• : numer(n), denom(d) // initialize

numerator and denominator as passed• {• // 0 as denominator is not allowed• if (d == 0) {• // exit program with error message• std::cerr << "error: denominator is 0"

<< std::endl;• std::exit(EXIT_FAILURE);• }• } 16

A sample Code in C++…• /* print• */• void Fraction::print()• {• std::cout << numer << '/' << denom <<

std::endl;• }

• } // **** END namespace CPPBook

• ********************************

17

OO Programming Concepts

Object-oriented programming (OOP) involves programming using objects. An object represents an entity in the real world that can be distinctly identified. For example, a student, a desk, a circle, a button, and even a loan can all be viewed as objects.

An object has unique identitystatebehaviors

State(attributes) consists of a set of data fields (properties) with their current values.

Behavior(operations) of an object is defined by a set of methods.

OO Programming Concepts

data field 1

method n

data field m

method 1

(A) A generic object

...

...

State (Properties)

Behavior

radius = 5

findArea()

Data field, State Properties

M ethod, Behavior

(B) An example of circle object

• Classes:– People,books,dogs,cats,cars,airplanes,trains,etc.

• Instance of a class– You, your parents, the book you are reading, the car you drive

Example: Car classProperty namesMethod Namesmodel startEngineyear stopEngineColor accelerate

OO Programming Concepts

Objects

An object has both a state and behavior. The state defines the object, and the behavior defines what the object does.

Class Name: Student Data Fields: name is _______

M ethods: takeCourse

Student Object 1 Data Fields: name is Kerem

Student Object 2 Data Fields: name is Onur

Student Object 3 Data Fields: name is M eltem

A class template

Three objects of the Student class

22

Concept: Classes describe objects

• Every object belongs to (is an instance of) a class

• An object may have fields, or variables– The class describes those fields

• An object may have methods– The class describes those methods

• A class is like a template, or cookie cutter– You use the class’s constructor to make objects

Solve it!

• Define a class for Employee,– Data Members– Functions

23

SummaryTerm Description

class Is a group of data and methods (functions). 

object

Is an instance of a class, which is similar to a variable, defined as an instance of a type.  An object is what you actually use in a program since it contains values and can be changed.

method

Is a function contained within the class.  You will find the functions used within a class often referred to as methods in programming literature.

24

25

Questions?


Recommended