CMSC 202 Computer Science II for Majors. CMSC 202UMBC Topics Objects and Classes Project 2 description.

Slides:



Advertisements
Similar presentations
Classes & Objects INTRODUCTION : This chapter introduces classes ; explains data hiding, abstraction & encapsulation and shows how a class implements these.
Advertisements

Complete Structure class Date {class Date { private :private : // private data and functions// private data and functions public :public : // public data.
INHERITANCE BASICS Reusability is achieved by INHERITANCE
C++ Classes & Data Abstraction
Objectives Introduction to Inheritance and Composition (Subclasses and SuperClasses) Overriding (and extending), and inheriting methods and constructors.
1 Lab-1 CSIT-121 Spring 2005 Lab Targets Solving problems on computer Programming in C++ Writing and Running Programs Programming Exercise.
Classes and Objects April 6, Object Oriented Programming Creating functions helps to make code that we can reuse. When programs get large it becomes.
Evan Korth New York University Computer Science I Classes and Objects Professor: Evan Korth New York University.
Chapter Objectives You should be able to describe: Object-Based Programming Classes Constructors Examples Common Programming Errors.
UML Class Diagram: class Rectangle
CS 2511 Fall Features of Object Oriented Technology  Abstraction Abstract class Interfaces  Encapsulation Access Specifiers Data Hiding  Inheritance.
1 Lab-1 CSIT-121 Fall 2004 Lab Targets Solving problems on computer Programming in C++ Writing and Running Programs Programming Exercise.
C++ fundamentals.
 By Wayne Cheng.  Introduction  Five Tenets  Terminology  The foundation of C++: Classes.
1 Review: Two Programming Paradigms Structural (Procedural) Object-Oriented PROGRAM PROGRAM FUNCTION OBJECT Operations Data OBJECT Operations Data OBJECT.
Introduction to Object Oriented Design. Topics Designing Your Own Classes Attributes and Behaviors Class Diagrams.
C++ Object Oriented 1. Class and Object The main purpose of C++ programming is to add object orientation to the C programming language and classes are.
Data Structure and Algorithm: CIT231 Lecture 4: ADT and Introduction to Object Oriented Programming (OOP) DeSiaMore DeSiaMorewww.desiamore.com/ifm1.
Chapter 7 Objects and Classes 1 Fall 2012 CS2302: Programming Principles.
Tuc Goodwin  Object and Component-Oriented Programming  Classes in C#  Scope and Accessibility  Methods and Properties  Nested.
CHAPTER 13 CLASSES AND DATA ABSTRACTION. In this chapter, you will:  Learn about classes  Learn about private, protected, and public members of a class.
1 Special Programming Workshop CSIT-120 Fall 2000 Workshop Targets Solving problems on computer Programming in C++ Writing and Running Programs Programming.
1 Inheritance. 2 Why use inheritance?  The most important aspect of inheritance is that it expresses a relationship between the new class and the base.
CMSC 202 Lesson 7 Classes I. Warmup  Add the correct parameter list and return type to the following function: (hint: all the information you need is.
C++ Programming Basic Learning Prepared By The Smartpath Information systems
CS 210 DATA STRUCTURES AND ALGORITHIMS Fall 2006.
2 Objectives You should be able to describe: Object-Based Programming Classes Constructors Examples Common Programming Errors.
Object Oriented Programming
CSci 162 Lecture 10 Martin van Bommel. Procedures vs Objects Procedural Programming –Centered on the procedures or actions that take place in a program.
UMass Lowell Computer Science Java and Distributed Computing Prof. Karen Daniels Fall, 2000 Lecture 9 Java Fundamentals Objects/ClassesMethods Mon.
C++ Class. © 2005 Pearson Addison-Wesley. All rights reserved 3-2 Abstract Data Types Figure 3.1 Isolated tasks: the implementation of task T does not.
 In the java programming language, a keyword is one of 50 reserved words which have a predefined meaning in the language; because of this,
نظام المحاضرات الالكترونينظام المحاضرات الالكتروني Introduction to Object Oriented Programming (OOP) Object Oriented programming is method of programming.
Introduction to Programming Lecture 40. Class Class is a user defined data type.
Copyright © 2011 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Chapter 7: Introduction to Classes and Objects Starting Out with C++ Early.
Chapter 5 Classes and Methods II Lecture Slides to Accompany An Introduction to Computer Science Using Java (2nd Edition) by S.N. Kamin, D. Mickunas, E.
Object-Oriented Programming (OOP) What we did was: (Procedural Programming) a logical procedure that takes input data, processes it, and produces output.
CMSC 345 Fall 2000 OO Design. Characteristics of OOD Objects are abstractions of real-world or system entities and manage themselves Objects are independent.
Topic 8Classes, Objects and Methods 1 Topic 8 l Class and Method Definitions l Information Hiding and Encapsulation l Objects and Reference Classes, Objects,
نظام المحاضرات الالكترونينظام المحاضرات الالكتروني Object Oriented Programming(Objects& Class) Classes are an expanded concept of data structures: like.
Defining Classes I Part B. Information hiding & encapsulation separate how to use the class from the implementation details separate how to use the class.
Chapter 7 Classes and Methods III: Static Methods and Variables Lecture Slides to Accompany An Introduction to Computer Science Using Java (2nd Edition)
MY COLLEGE: BITM SANTINIKETAN Object oriented programming lets check through C++
1 Data Structures CSCI 132, Spring 2014 Lecture 2 Classes and Abstract Data Types Read Ch Read Style Guide (see course webpage)
Copyright © 2006 Pearson Addison-Wesley. All rights reserved. 6-1 Learning Objectives  Classes  Constructors  Principles of OOP  Class type member.
Class & Objects C++ offers another user-defined data type known class which is the most important feature of the object-oriented programming. A class can.
Structure A Data structure is a collection of variable which can be same or different types. You can refer to a structure as a single variable, and to.
CPSC 252 ADTs and C++ Classes Page 1 Abstract data types (ADTs) An abstract data type is a user-defined data type that has: private data hidden inside.
Computer Programming II Lecture 4. Functions - In C++ we use modules to divide the program into smaller and manageable code. These modules are called.
CMSC 202 Lesson 8 Classes II. Warmup Declare a class (.h part) named “Cup” It has a data member that says how full it is One method called “Drink” that.
CMSC 202 Computer Science II for Majors. CMSC 202UMBC Topics Templates Linked Lists.
CMSC 202 Lesson 9 Classes III. Warmup Using the following part of a class, implement the Sharpen() method, it removes 1 from the length: class Pencil.
Data Structures Lecture 4: Classes in C++ Azhar Maqsood NUST Institute of Information Technology (NIIT)
Computer Programming II Lecture 5. Introduction to Object Oriented Programming (OOP) - There are two common programming methods : procedural programming.
CMSC202 Computer Science II for Majors Lecture 06 – Classes and Objects Dr. Katherine Gibson Based on slides by Chris Marron at UMBC.
Topic: Classes and Objects
Inheritance CMSC 202, Version 4/02.
classes and objects review
Road Map Introduction to object oriented programming. Classes
UML Class Diagram: class Rectangle
CS148 Introduction to Programming II
Function Overloading C++ allows us to define functions that have the same name but different sets of parameters This capability can be used to define similar.
Learning Objectives Classes Constructors Principles of OOP
Object-Oriented Programming
CLASSES AND OBJECTS.
UNIT I OBJECT ORIENTED PROGRAMMING FUNDAMENTALS
CMSC202 Computer Science II for Majors Lecture 07 – Classes and Objects (Continued) Dr. Katherine Gibson Based on slides by Chris Marron at UMBC.
CMSC 202 Lesson 8 Classes II.
Computer Science II for Majors
INTERFACES Explained By: Sarbjit Kaur. Lecturer, Department of Computer Application, PGG.C.G., Sector: 42, Chandigarh.
Presentation transcript:

CMSC 202 Computer Science II for Majors

CMSC 202UMBC Topics Objects and Classes Project 2 description

CMSC 202UMBC Objects What are objects ?  Real-world objects E.g. Car, Fruit A real-world object is an entity in the world  An object is an entity in an OO system  OO programming approach Programming problem is in terms of objects and communication between them

CMSC 202UMBC Class A Class is a user-defined data type whose instances are objects Objects are variables of type class Thus, class is an abstraction of objects of similar type E.g. automobile is a class whose objects could be Bob’s car, Mary’s car etc.

CMSC 202UMBC Class … cont One important feature of class is Data hiding or Encapsulation A class wraps data and functions into a single unit Thus data is typically not accessible to outside world Member functions provide an interface between object’s data and program

CMSC 202UMBC Class … cont Object User of objects Member Functions Member Variables ( Data ) An Interface

CMSC 202UMBC Class … cont Syntax class class-name { access-specifier : data and functions access-specifier : data and functions access-specifier : data and functions … } ;

CMSC 202UMBC Class … cont Access – specifier  private : Private to class  public : Accessible to other parts of program  protected : Needed in inheritance (later) By default, all members are private

CMSC 202UMBC Class … cont E.g. of a class named Date class Date { public : // public member functions Date (int month=1, int day=1, int year=2003); void Print ( void ) const; private : // private data members int m_month; int m_day; int m_year; };

CMSC 202UMBC Class … cont Defining constructor & member functions Date :: Date (int month, int day, int year) { m_month = month; m_day = day; m_year = year; } void Date :: Print ( void ) const { cout << month << “-” << day << “-” << year; }

CMSC 202UMBC Class … cont In C++, you can add new features to existing structure of object / class Suppose we need to add a member function called NextDay  NextDay increments day by 1  Where do we make changes in the class ?

CMSC 202UMBC Class … cont class Date { public : // public member functions Date (int month=1, int day=1, int year=2003); void Print ( void ) const; void NextDay( void ); private : // private data members int m_month; int m_day; int m_year; };

CMSC 202UMBC Class … cont Defining NextDay member function void Date :: NextDay ( void ) {..// logic to increment date..// Also need to consider incrementing to next // month and next year }

CMSC 202UMBC Class … cont Declaring an object as data member of another class  A class is a data-type, a class can use an object as a data member  This is known as aggregation or composition  Consider adding a Time object in our Date class  Exercise 6.10 on page 466

CMSC 202UMBC Class … cont class Time { public : // Constructor and all member function will come // here // Function to increment time by one second void Increment ( void ); private : int m_hour; int m_minute; int m_second; };

CMSC 202UMBC Class … cont class Date { public : // Constructor and all member function will come // here // Add member function Tick which calls Increment void Tick ( void ); private : Time currentTime; // Declare Time object in Date // other data members };

CMSC 202UMBC Class … cont How is the Tick() member function defined ? void Date :: Tick ( void ) {..// logic to increment date // This is how we make use of Increment function of Time class currentTime.Increment(); } But you still cannot access private members of Time class from Date class - Encapsulation

CMSC 202UMBC Class … cont m_month m_day m_year m_hour m_minute m_second Date Object Time Object User Member Functions Member Func

CMSC 202UMBC Project 2 Objective  To implement and use objects  To understand aggregation  To practice formatted output, makefiles Given a quadrilateral, it can be a  Parallelogram  Rectangle  Square  Trapezoid  Irregular

CMSC 202UMBC Project 2 … cont Classes  A Point class Encapsulates x and y co-ordinates of a point  A Quadrilateral class Encapsulates a quadrilateral Uses Point class for each of its four corners The corners are referred as ‘UpperRight’, ‘UpperLeft’, ‘LowerLeft’ and ‘LowerRight’

CMSC 202UMBC Project 2 … cont What you need to do ?  Accept x and y co-ordinates of four corners  Classify the quadrilateral as one of the five types  Compute and display its area and perimeter Assume  Co-ordinate values are integers  Base is parallel to x axis  Area of irregular quadrilateral is

CMSC 202UMBC Project 2 … cont Sample run (taken from Project 2 description) linux3[3]% Proj2 This is my optional greeting Please enter x- and y-coordinates of the UpperLeft corner: 6 4 Please enter x- and y-coordinates of the LowerLeft corner: 9 1 Please enter x- and y-coordinates of the LowerRight corner: 16 1 Please enter x- and y-coordinates of the UpperRight corner: 13 4 The Quadrilateral's Corners Upper Left: ( 6, 4) Upper Right: (13, 4) Lower Left: ( 9, 1) Lower Right: (16, 1) This Quadrilateral is a Parallelogram Area: Perimeter: linux3[4]%