CPS120: Introduction to Computer Science

Slides:



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

Introduction to Data Structures, Spring 2007 Slide- 1 California State University, Fresno Introduction to Data Structure Object Oriented Programming Concepts.
Chapter Objectives You should be able to describe: Object-Based Programming Classes Constructors Examples Common Programming Errors.
1 Introduction to C++ Programming Concept Basic C++ C++ Extension from C.
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.
OBJECT ORIENTED PROGRAMMING IN C++ LECTURE
Object Oriented Software Development
CSM-Java Programming-I Spring,2005 Introduction to Objects and Classes Lesson - 1.
Object Orientation An Object oriented approach views systems and programs as a collection of interacting objects. An object is a thing in a computer system.
Introduction to Object-oriented programming and software development Lecture 1.
CS200 Algorithms and Data StructuresColorado State University Part 4. Advanced Java Topics Instructor: Sangmi Pallickara
Copyright 2003 Scott/Jones Publishing Standard Version of Starting Out with C++, 4th Edition Chapter 13 Introduction to Classes.
Chapter 13. Procedural programming vs OOP  Procedural programming focuses on accomplishing tasks (“verbs” are important).  Object-oriented programming.
Copyright 2004 Scott/Jones Publishing Alternate Version of STARTING OUT WITH C++ 4 th Edition Chapter 7 Structured Data and Classes.
CPS120: Introduction to Computer Science Functions.
C++ Programming Basic Learning Prepared By The Smartpath Information systems
1 Programming Paradigms Object Orientated Programming Paradigm (OOP)
Simple Classes. ADTs A specification for a real world data item –defines types and valid ranges –defines valid operations on the data. Specification is.
Introduction to c++ programming - object oriented programming concepts - Structured Vs OOP. Classes and objects - class definition - Objects - class scope.
OOP using C Abstract data types How to accomplish the task??? Requirements Details Input, output, process Specify each task in terms of input.
1 OOP - An Introduction ISQS 6337 John R. Durrett.
2 Objectives You should be able to describe: Object-Based Programming Classes Constructors Examples Common Programming Errors.
CPS120: Introduction to Computer Science Lecture 15A Structures.
نظام المحاضرات الالكترونينظام المحاضرات الالكتروني Introduction to Object Oriented Programming (OOP) Object Oriented programming is method of programming.
Copyright © 2010 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Starting Out with Programming Logic & Design Second Edition by Tony Gaddis.
Chapter More on Classes Intro to Computer Science CS1510, Section 2 Dr. Sarah Diesburg.
Introduction To OOP 1.0 Fundamentals Of Java Programming Language 2.0 Exception Handling 3.0 Classes, Inheritance And Polymorphism © 2011 | PN AZRINA.
CPS120: Introduction to Computer Science Data Structures.
Classes, Interfaces and Packages
CPS120: Introduction to Computer Science Lecture 16 Data Structures, OOP & Advanced Strings.
1 CSE Programming in C++. 2 Overview Sign roster list Syllabus and Course Policies Introduction to C++ About Lab 1 Fill Questionnaire.
Object Oriented Programming. OOP  The fundamental idea behind object-oriented programming is:  The real world consists of objects. Computer programs.
Copyright © 2010 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Starting Out with Programming Logic & Design Second Edition by Tony Gaddis.
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.
1 C++ Classes & Object Oriented Programming Overview & Terminology.
CPS120: Introduction to Computer Science Lecture 16A Object-Oriented Concepts.
Liang, Introduction to C++ Programming, (c) 2007 Pearson Education, Inc. All rights reserved X 1 Chapter 9 Introduction of Object Oriented Programming.
Computer Programming II Lecture 5. Introduction to Object Oriented Programming (OOP) - There are two common programming methods : procedural programming.
Object-oriented programming (OOP) is a programming paradigm using "objects" – data structures consisting of data fields and methods together with their.
Inheritance Modern object-oriented (OO) programming languages provide 3 capabilities: encapsulation inheritance polymorphism which can improve the design,
Lecture 3 (UNIT -1) SUNIL KUMAR CIT-UPES.
Procedural and Object-Oriented Programming
Programming Logic and Design Seventh Edition
Pointers, Enum, and Structures
Review: Two Programming Paradigms
Road Map Introduction to object oriented programming. Classes
Inheritance Modern object-oriented (OO) programming languages provide 3 capabilities: encapsulation inheritance polymorphism which can improve the design,
This technique is Called “Divide and Conquer”.
INTRODUCTION TO OBJECT-ORIENTED PROGRAMMING (OOP) & CONCEPTS
Object Oriented Analysis and Design
CS212: Object Oriented Analysis and Design
Introduction to Classes
Chapter 3 Introduction to Classes, Objects Methods and Strings
IFS410: Advanced Analysis and Design
CONSTRUCTORS AND DESRUCTORS
Week 3 Object-based Programming: Classes and Objects
Starting to think about objects...
Dr. Bhargavi Dept of CS CHRIST
Classes and Objects.
UNIT I OBJECT ORIENTED PROGRAMMING FUNDAMENTALS
C++ Programming ㅎㅎ String OOP Class Constructor & Destructor.
COP 3330 Object-oriented Programming in C++
Introduction to Classes and Objects
Object Oriented Programming in java
Java Programming Language
CPS120: Introduction to Computer Science
CPS120: Introduction to Computer Science
Types of Computer Languages
Presentation transcript:

CPS120: Introduction to Computer Science Object-Oriented Concepts

The Procedural Paradigm The functions and algorithms are the focus, with data viewed as something for the functions to manipulate

Structures Structures group variables together in order to make one's programming task more efficient. Any combination of variables can be combined into one structure. This is a useful and efficient way to store data. struct Student { string socSecNum; string lastName; string firstName; int pointsEarned; double gpa; };

Using the new data structure The structure definition should be placed above the main function of a program but below the compiler directives Declare an actual variable of this programmer-created data type within a function (such as main) in order to make use of this structureDone with a declaration statement like Student freshmen; This reates a variable called freshmen of the data type Student Open struct2.cpp: #include<iostream.h> #include<iomanip.h> #include<string.h> struct inventory_item { char item_ID[11]; char description[31]; int quantity_on_hand; int reorder_point; double cost; double retail_price; }; int main() inventory_item todays_special; strcpy(todays_special.item_ID, "RGG456-299"); strcpy(todays_special.description, "Remote Control Monster Truck"); todays_special.quantity_on_hand = 19; todays_special.reorder_point = 3; todays_special.cost = 47.80; todays_special.retail_price = 98.99; cout << "Today's Special \n"; cout << " Item ID: " << todays_special.item_ID << endl; cout << " Description: " << todays_special.description << endl; cout << " Quantity: " << todays_special.quantity_on_hand <<endl; cout << "Regular Price: " << setprecision(2) << todays_special.retail_price << endl; cout << " Sale Price: " << todays_special.retail_price * 0.8 << endl; return 0; }

Assigning values to the structure To assign a grade point average (GPA) of 3.4 to the gpa member of the variable freshmen, use the statement: freshmen.gpa = 3.4; The period (.) that is used between the variable name freshmen and the member gpa is called the dot operator. The dot operator simply us to reference individual members of a structure struct Student { string socSecNum; string lastName; string firstName; int pointsEarned; double gpa; }; To assign a last name, you could use the statement, freshmen.lastName = "Smith";

Object-Oriented Paradigm Data should be placed inside the objects and that these objects should communicate with each other in the form of messages

Designing a Class Think in an object-oriented way E.g. an answering machine encapsulates the functions of an answering machine with the data (messages). The buttons are the equivalent of sending messages to the machine

Functionality of Object-Oriented Languages Encapsulation Inheritance Polymorphism

Encapsulation Encapsulation is a language feature that enforces information hiding

Inheritance Inheritance fosters reuse by allowing an application to take an already-tested class and derive a class from it that inherits the properties the application needs

Polymorphism The ability of a language to have duplicate method names in an inheritance hierarchy and to apply the method that is most appropriate for the object which the method is applied

Object-Oriented Design An object is a self-contained entity that makes sense within the context of the problem For example, a student

Object-Oriented Design A group of similar objects is described by an object class, or class

OOP Advantages: Reusability Reusability is a major benefit of object-oriented programming

Classes The definition of an object is know as a class It is similar to using basic data structures in C++ When you declare an object, you are said to have instantiated it (given it instances) Objects are members of a class Paul Millis, George Bush and George Washington being members of the human being class The design of a class is as important as its implementation

Relationships Between Classes Containment “part-of” An address class may be part of the definition of a student class Inheritance Classes can inherit data and behavior from other classes “is-a”

Public vs Private Private: Cannot be accessed outside the object Public: Can have access to all the variables and functions public: // constructors circle(); // default constructor circle(const circle &); // copy constructor // member functions void SetRadius(float); double Area(); private: // data float radius;

Constructors Allow all data encapsulated within an object to be initialized to preset values so that errors can be avoided

Member Functions Provide a way for a programmer to pass data to and get data from an object Implemented like a normal C++ function Except -- The class name and the scope-resolution operator (: :) precede the function name circle : : circle() // default constructor