2D1358 Object Oriented Program Construction in C++ Exercises & Labs. Course Registration / Accounts. Course Literature

Similar documents
Reusability. Relationships among Objects. Relationships among Objects

C How to Program, 6/e by Pearson Education, Inc. All Rights Reserved. 1

Object-Oriented Concepts and Principles (Adapted from Dr. Osman Balci)

What are the characteristics of Object Oriented programming language?

1. Software Systems Complexity, OO Paradigm, UML

Course Administration

Introduction to OO Concepts

Introduction to Object-Oriented Programming

Object Oriented Programming

Chapter 11 Object and Object- Relational Databases

CS304- Object Oriented Programming LATEST SOLVED MCQS FROM FINALTERM PAPERS. MC

Object Oriented Software Development CIS Today: Object Oriented Analysis

S T R U C T U R A L M O D E L I N G ( M O D E L I N G A S Y S T E M ' S L O G I C A L S T R U C T U R E U S I N G C L A S S E S A N D C L A S S D I A

1. Write two major differences between Object-oriented programming and procedural programming?

C++ Programming for Programmers

Object-Oriented Programming in C++/Handout 01 Page 1 of 8

C++ Programming for Programmers using Microsoft Visual C Professional

OOAD - OBJECT MODEL. The concepts of objects and classes are intrinsically linked with each other and form the foundation of object oriented paradigm.

OBJECT ORIENTED PROGRAMMING

B.C.A 2017 OBJECT ORIENTED PROGRAMMING USING C++ BCA303T MODULE SPECIFICATION SHEET

CSCI-142 Exam 1 Review September 25, 2016 Presented by the RIT Computer Science Community

EL2310 Scientific Programming

EL2310 Scientific Programming

UML Primer. -Elango Sundaram

CS304 Object Oriented Programming Final Term

An Introduction to Object Orientation

Object Orientated Analysis and Design. Benjamin Kenwright

What is a Programming Paradigm

JAVA: A Primer. By: Amrita Rajagopal

Understanding the Object Paradigm

BCS Higher Education Qualifications. Diploma in IT. Object Oriented Programming Syllabus

Programmazione. Prof. Marco Bertini

EL2310 Scientific Programming

Inheritance, and Polymorphism.

OBJECT ORIENTED PROGRAMMING USING C++ CSCI Object Oriented Analysis and Design By Manali Torpe

Credit where Credit is Due. Lecture 4: Fundamentals of Object Technology. Goals for this Lecture. Real-World Objects

James Newkirk

Object Oriented Programming. Assistant Lecture Omar Al Khayat 2 nd Year

Copyright 2016 Ramez Elmasri and Shamkant B. Navathe

Object-Oriented Programming Paradigm


Object-Oriented Design

B16 Object Oriented Programming

Introduction to Object-Oriented Programming

Object-Oriented Analysis and Design

Lecturer: Sebastian Coope Ashton Building, Room G.18 COMP 201 web-page:

What is Polymorphism? Quotes from Deitel & Deitel s. Why polymorphism? How? How? Polymorphism Part 1

CoSci 440 SYLLABUS Programming in C++ INSTRUCTOR Mari Rettke cell SECTION : and 13345

Cpt S 122 Data Structures. Course Review Midterm Exam # 2

Programming, numerics and optimization

Announcement. Agenda 7/31/2008. Polymorphism, Dynamic Binding and Interface. The class will continue on Tuesday, 12 th August

w3.ualg.pt/~jvo/poo

Object- Oriented Design with UML and Java Part I: Fundamentals

Advanced Programming CMPS 109

I BCS-031 BACHELOR OF COMPUTER APPLICATIONS (BCA) (Revised) Term-End Examination. June, 2015 BCS-031 : PROGRAMMING IN C ++

An Introduction to Patterns

Polymorphism Part 1 1

CS 6456 OBJCET ORIENTED PROGRAMMING IV SEMESTER/EEE


COMPUTER PROGRAMMING (ECE 431) TUTORIAL 9

Object-Oriented Programming (OOP) Fundamental Principles of OOP

C++ Programming: Introduction to C++ and OOP (Object Oriented Programming)

A - 1. CS 494 Object-Oriented Analysis & Design. UML Class Models. Overview. Class Model Perspectives (cont d) Developing Class Models

Objects and Classes. Amirishetty Anjan Kumar. November 27, Computer Science and Engineering Indian Institue of Technology Bombay

CS111: PROGRAMMING LANGUAGE II. Lecture 1: Introduction to classes

Object Oriented Programming is a programming method that combines: Advantage of Object Oriented Programming

Data Abstraction. Hwansoo Han

Outline. Logistics. Logistics. Principles of Software (CSCI 2600) Spring Logistics csci2600/

Object-Oriented Software Development Goal and Scope

OBJECT ORİENTATİON ENCAPSULATİON

administrivia today UML start design patterns Tuesday, September 28, 2010

Object-Oriented Design (OOD) and C++

Introduction to Design Patterns

MechEng SE3 Lecture 7 Domain Modelling

Object-Oriented Systems Analysis and Design Using UML

PROGRAMMING IN C++ COURSE CONTENT

CS313D: ADVANCED PROGRAMMING LANGUAGE

CS445 Week 9: Lecture

Inheritance and Polymorphism

Inheritance, Polymorphism, and Interfaces

Object Oriented Programming. C++ 6 th Sem, A Div Ms. Mouna M. Naravani

Chapter 12 Object-Oriented Programming. Starting Out with Games & Graphics in C++ Tony Gaddis

CMSC 202 Section 010x Spring Justin Martineau, Tuesday 11:30am

CE221 Programming in C++ Part 1 Introduction

Beijing Jiaotong University CS-23: C++ Programming Summer, 2019 Course Syllabus

CS304 Object Oriented Programming

Inheritance. OOP components. Another Example. Is a Vs Has a. Virtual Destructor rule. Virtual Functions 4/13/2017

Programmazione. Prof. Marco Bertini

Chapter 13. Object Oriented Programming

M301: Software Systems & their Development. Unit 4: Inheritance, Composition and Polymorphism

Subclass Gist Example: Chess Super Keyword Shadowing Overriding Why? L10 - Polymorphism and Abstract Classes The Four Principles of Object Oriented

LECTURE 3: SOFTWARE DESIGN. Software Engineering Mike Wooldridge

3F6 - Software Engineering and Design. Handout 1 Architecture of a Computer With Markup. Ed Rosten

C++ Inheritance and Encapsulation

Unified Modeling Language

Today s lecture. CS 314 fall 01 C++ 1, page 1

Data Structures using OOP C++ Lecture 3

Object Oriented Programming. Michał Bereta

Spring 2003 Instructor: Dr. Shahadat Hossain. Administrative Matters Course Information Introduction to Programming Techniques

CS313D: ADVANCED PROGRAMMING LANGUAGE

Transcription:

2D1358 Object Oriented Program Construction in C++ Exercises & Labs Lecturer: Frank Hoffmann hoffmann@nada.kth.se Assistents: Danica Kragic danik @nada.kth.se Anders Orebäck oreback @nada.kth.se Peter Raicevic peterr@nada.kth.se Mikael Rosbacke rosbacke@nada.kth.se Course webpages: general : http://www.nada.kth.se/kurser/kth/2d1358 period 4 : http://www.nada.kth.se/kurser/kth/2d1358/00-01/f group 1: Danica Kragic (in English) group 2: Anders Orebäck group 3: Peter Raicevic group 4: Mikael Rosbacke First exercises on Tuesday 20/3 11:00 group 1 : room D32 (notice room change) group 2 : room D33 (notice room change) group 3 : room E36 (will be held by Frank Hoffmann until Tuesday 3/4) group 4 : starts Monday 26/3 (first week attend either of the groups 1-3) lab groups 1-4, group 1-2 start Thursday 22/3 17:00 group 3-4 start Friday 23/3 10:00 Course Literature Course Registration / Accounts C++ C++ Programming Language, 3 rd edition, Bjarne Stroustrup, Addison-Wesley C++ Primer, 3 rd edition, Stanley B. Lippman, Josee Lajoie, Addison-Wesley The Waite s Group s Object-Oriented Programming in C++, 3 rd edition, Robert Lafore, SAMS Object Oriented Design and UML Design Patterns, Erich Gamma, Addison-Wesley The Unified Modeling Language User Guide, Grady Booch, Addison-Wesley UML Distilled, Martin Fowler, Addison-Wesley Obtaining a UNIX account at NADA sign up on the list with first and last name visit DELPHI to create your account http://www.sgr.nada.kth.se/delfi Register for the course with RES UNIX command : res checkin oopk01 or Via the web-form on the course webpage 1

Course Requirements regular attendance of lectures active participation in the exercises 7 lab exams lab1 : Matrices (optional but highly recommended) lab2 : Menu system (mandatory) : due 06.04.01 lab3 : Drawing program (mandatory ) : due 11.05.01 lab4 : Fia Game (mandatory ) : due 25.05.01 lab5 : Handling options ( 4 points ) : due 01.06.01 lab6 : Window library ( 4 points ) : due 01.06.01 lab7 : Adventure Game ( 5 points ) : due 01.06.01 if you fail a lab you can redo it within one week (only if you took the lab exam before the deadline) if you miss a lab exam or fail twice you can not take it earlier then the next omtentamenperiod in August 01 Procedural Languages Examples of procedural languages: C, Pascal, Fortran A program in a procedural language is basically a list of instructions As programs become larger they are usually broken down into smaller units, such as, procedures, subroutines Functions can be grouped together into modules according to their functionality, objectives and tasks. Structured programming is a programming paradigm that to a large extent relies on the idea of dividing a program into and modules. Problems with Structured Programming Functions have unrestricted access to global Function A: local global X Function B: local global Y Function C: local global Z Large number of potential connections between and (everything is related to everything, no clear boundaries) makes it difficult to conceptualize program structure makes it difficult to modify and maintain the program e.g. : it is difficult to tell which access the Problems with Structured Programming and function are considered as two separate entities makes it difficult to model things in the real world complex real world objects have both attributes and behaviours attributes people: name, date of birth, eye color, job title cars: horse power, number of doors, color behaviours people: ask a to bring you a beer cars: apply the brakes, turn on the engine attributes and behaviors alone are sufficient to realistically model real world objects but a unified view is needed 2

Object Oriented Approach Object Object Oriented Approach separation: objects interact with each other only via the their membership separation helps to maintain the integrity of the entire program Object A Encapsulation: integrate and into one object Data hiding : is hidden to the outside world and can only be accessed via the In C++ are called membership in other languages such as Smalltalk they are called methods Data items are called attributes or instance variables Object C Object B Abstraction Separation entity An abstraction is a named collection of attributes and behavior relevant to model a given entity for some particular purpose real-world abstraction software attributes {,, } independent specification of a visible interface and a hidden implementation interface is some kind of contract between the object and the user of this object or module separation is not restricted to object-oriented programming for example header files in standard C can be regarded as interfaces visible interface behavior { method, method } hidden Implementation 3

Structure of an Object Interface Implementation Object Examples of Objects physcial objects vehicles in a traffic-flow simulation electrical components in a circuit-design program elements of a computer user environment menus graphic objects -storage constructs arrays linked lists human entities employees students collections of an inventory an address book user defined types time complex numbers Example of a Class in C++ class someobject //declares a class { private: int some; //class public: void set(int d) //membership function to set { some=d; } int get() //membership function to get { return some; } } Classes versus Objects A class is a prototype specification from which one can generate a number of similar objects A class can be considered as an object factory. An object is said to be a member or instance of a class A class can be considered as a more complex structure than an ordinary built-in type Standard C already knows the struct command for user defined types: struct complex { double re; double im; }; complex x; 4

Instantiation of Objects : name, p_nummer, address, date of birth methods: getage(), changeaddress(newaddress) : Lena Brat, 761203-7111, Stureplan 4, female Class : Erik Olsson, 780605-4789, Hamngatan 3, male : Lars Backe, 671110-A562, Mälartorget 19, male Relationships among Objects Attribute: One object uses as another object as an attribute, namely as member, for example a Person contains an attribute Name. This type of relationship is also called a weak association or has-a relationship. Example: A Person has a Name Association: One object uses another to help it carry out a task. Classes that collaborate are usually related through associations. This type of relationship is also called a uses relationship. Example: The object Driver invokes the method Brakeof the object BrakingSystem. Relationships among Objects Aggregation: Aggregation means that one object contains other objects. Aggregation is also called part-of relationship. Example: The class Adressbook contains many People Objects. Composition: Composition is building objects from parts. It is a stronger type of aggregation in which the parts are necessary to the whole, namely they are permanently bound to the object and do not exist outside the object. A class Processor contains a CPU, Memory and I/O-Ports. Relationships among Objects Generalization Generalization is a relationship defined at the class level not the object level, which means that all objects of this class must obey the relationship. This is type of relationship is also called a is-a-kind-of relationship. Generalization in object oriented languages is realized by means of inheritance. Example: A car is a kind of vehicle. 5

Inheritance In our daily lives we use the concept of classes divided into subclasses, for example vehicles are divided into cars, trucks, buses and motor cycles. The principle in this sort of division is that each sub-class shares some common features with the base class from which it is derived, but also has its own particular features. base class Car wheels engine trunk Vehicle wheels engine sub-classes or derived classes Truck wheels engine trailer Inheritance A sub-class also shares common methods with its super-class but can add its own methods or overwrite the methods of its super-class. base class Car brake() start_engine() open_door() Vehicle brake() start_engine() sub-classes or derived classes Truck brake() start_engine() open_door() pull_trailer() Inheritance Terminology: Car is a sub-class (or derived class) of Vehicle Car inherits from Vehicle Car is a specialization of Vehicle Vehicle is a super-class (or base class) of Car Vehicle is a generalization of Car In C++ an object of a sub-class is substitutable for an object of the super-class, in other words an object of class Car can be used whenever an object of class Vehicle is required. Reusability Reusability means that a class that has been designed, created and debugged once can be distributed to other programmers for use in their own programs. Similar to the idea of a library of in a procedural language. The concept of inheritance provides an important extension to the idea of reusability, as it allows a programmer to take an existing class without modifying it and adding additional features and functionality. This is done by inheriting a new sub-class from the exisiting base class. 6

Polymorphism & Overloading Polymorphism : using and operators in different ways, depending on what they are operating on. Polymorphism allows it to manipulate objects without knowing their exact type but only their common property. for example, the classes Triangle and Circle both have their own (polymorphic) version of the method Draw, but a graphic routine that draws graphical elements does not have to know which object it manipulates. Overloading: an existing operator, such as + or = is given the capability to operate on a new type, for example define the operator + for the class Complex such that it realizes the addition of two complex numbers. Polymorphism polymorphism means having many shapes in C++ it refers to a situation in which an object could have any of several types a polymorphic variable can refer to objects of different classes, for example a graphic object can be either a circle or a triangle a polymorphic function or operator can take arguments of different types example: int max(int a, int b); double max(double a, double b); Polymorphism and Dynamic Binding suppose we have a class Shape for graphical objects with subclasses Circle and Triangle Circle and Triangle both provide their own polymorphic method void Draw() to draw the shape on the screen The term dynamic binding refers to the process of identifying at run time what code should be executed as a result of a message Circle c; Triangle t; Shape &s; s=c; s.draw(); // bounded to Circle Draw() s=t; s.draw(); // bounded to Triangle Draw() C++ and C C++ is derived from the language C C++ is a superset of C, that means almost every correct statement in C is also correct in C++ The most important elements added to C are concerned with classes, objects and object-oriented programming New features of C++ improved approach to input/output standard template library (STL) container classes for vectors, lists, maps, etc. reference type replaces pointers const variables replaces #define statements string type replaces C-style strings char[] new comment style augments C-style comments /* */ 7