ECE 264 Object-Oriented Software Development Instructor: Dr. Honggang Wang Fall 2012 Lecture 11: Examples—creating a basic class.

Slides:



Advertisements
Similar presentations
PHY283 Scientific Modelling Week 1Slide 1 Physics Simulations In this lab class we will be creating Simulations of Gravitational Systems. This will involve.
Advertisements

Engineering Problem Solving With C++ An Object Based Approach Additional Topics Chapter 10 Programming with Classes.
ECE 264 Object-Oriented Software Development
ECE 264 Object-Oriented Software Development Instructor: Dr. Honggang Wang Fall 2012 Lecture 10: Continuing with classes Constructors, using classes.
ECE 264 Object-Oriented Software Development Instructor: Dr. Honggang Wang Fall 2012 Lecture 21: Strings (cont.)
ECE Application Programming Instructor: Dr. Michael Geiger Spring 2012 Lecture 31: PE5.
Week 11 - Friday.  What did we talk about last time?  Object methods  Accessors  Mutators  Constructors  Defining classes.
1 Using Classes and Working With Class Interfaces November 20, 2002 CSE103 - Penn State University Prepared by Doug Hogan.
Const Parameters & In Line Functions 04/15/11. Next Time  Quiz, Monday, 04/18/11  Over 5.2 and 5.3 void functions pass-by-reference  Read 7.1 about.
1 Classes Overview l Classes as Types l Declaring Instance Variables l Implementing Methods l Constructors l Accessor and Mutator Methods.
ECE122 L6: Problem Definition and Implementation February 15, 2007 ECE 122 Engineering Problem Solving with Java Lecture 6 Problem Definition and Implementation.
1 Fall 2007ACS-1903 Chapter 6: Classes Classes and Objects Instance Fields and Methods Constructors Overloading of Methods and Constructors Scope of Instance.
CSE 115 Week 4 February 4 - 8, Monday Announcements Software installation fest Tuesday & Wednesday 4-7 in Baldy 21. Software installation fest Tuesday.
CS 2511 Fall Features of Object Oriented Technology  Abstraction Abstract class Interfaces  Encapsulation Access Specifiers Data Hiding  Inheritance.
ECE 264 Object-Oriented Software Development Instructor: Dr. Honggang Wang Fall 2012 Lecture 15: Class diagrams; class relationships.
ECE 264 Object-Oriented Software Development Instructor: Dr. Honggang Wang Fall 2012 Lecture 6: Continuing with output formatting.
ECE 264 Object-Oriented Software Development Instructor: Dr. Honggang Wang Fall 2012 Lecture 4: Continuing with C++ I/O Basics.
ECE 264 Object-Oriented Software Development Instructor: Dr. Honggang Wang Fall 2012 Lecture 3: Requirements Specification, C++ Basics.
Creating Simple Classes. Outline of Class Account Class Account Account # Balance Holder name phone# Overdrawn (true/false) Data Members Open Credit Debit.
An Introduction to Java Chapter 11 Object-Oriented Application Development: Part I.
Spring 2008 Mark Fontenot CSE 1341 Principles of Computer Science I Note Set 2.
Object-Oriented Programming in C++
ECE 264 Object-Oriented Software Development Instructor: Dr. Honggang Wang Fall 2012 Lecture 26: Exam 2 Preview.
ECE 264 Object-Oriented Software Development Instructor: Dr. Honggang Fall 2012 Lecture 8: File I/O; Introduction to classes.
Reformatted slides from the textbook, C++ How to Program, 6/e Pearson Education, Inc. All rights reserved Chapter 3. [Lecture 02] Introduction to.
An Object-Oriented Approach to Programming Logic and Design Chapter 3 Using Methods and Parameters.
ECE 264 Object-Oriented Software Development Instructor: Dr. Honggang Wang Spring 2013 Lecture 19: Exam 3 Preview.
11-1 Computing Fundamentals with C++ Object-Oriented Programming and Design, 2nd Edition Rick Mercer Franklin, Beedle & Associates, 1999 ISBN
ECE 264 Object-Oriented Software Development Instructor: Dr. Honggang Wang Spring 2013 Lecture 5: Continuing with C++ I/O Basics.
Chapter 3 (B) 3.5 – 3.7.  Variables declared in a function definition’s body are known as local variables and can be used only from the line of their.
ECE 264 Object-Oriented Software Development Instructor: Dr. Honggang Wang Fall 2012 Lecture 31: Operator overloading examples, inheritance intro.
ECE 264 Object-Oriented Software Development Instructor: Dr. Honggang Wang Fall 2012 Lecture 24: Pointers and Dynamic Allocation.
ECE 264 Object-Oriented Software Development Instructor: Dr. Honggang Wang Fall 2012 Lecture 22: Pointers.
ECE 264 Object-Oriented Software Development Instructor: Dr. Honggang Wang Spring 2013 Lecture 11: Class diagrams; class relationships.
ECE 264 Object-Oriented Software Development Instructor: Dr. Honggang Wang Fall 2012 Lecture 9: Continuing with classes.
ACM/JETT Workshop - August 4-5, : Defining Classes in Java.
CIS 270—Application Development II Chapter 8—Classes and Objects: A Deeper Look.
EGR 2261 Unit 11 Classes and Data Abstraction  Read Malik, Chapter 10.  Homework #11 and Lab #11 due next week.  Quiz next week.
CSci 162 Lecture 10 Martin van Bommel. Procedures vs Objects Procedural Programming –Centered on the procedures or actions that take place in a program.
ECE 264 Object-Oriented Software Development Instructor: Dr. Honggang Wang Fall 2012 Lecture 29: Operator overloading.
Week 11 - Friday.  What did we talk about last time?  Object methods  Accessors  Mutators  Constructors  Defining classes.
ECE 264 Object-Oriented Software Development Instructor: Dr. Honggang Wang Spring 2013 Lecture 5: Continuing with output formatting.
SE1011 Week 6, Class 2 Today Return Half Exam 2 (cont.) Object Oriented Programming (cont.) UML class diagrams Muddiest Point Next Half Exam: Week 7, Monday.
 2005 Pearson Education, Inc. All rights reserved Introduction to Classes and Objects.
1 COMS 261 Computer Science I Title: Classes Date: November 9, 2005 Lecture Number: 29.
ECE 264 Object-Oriented Software Development Instructor: Dr. Honggang Wang Spring 2013 Lecture 18: More on inheritance and Polymorphism.
ECE 264 Object-Oriented Software Development Instructor: Dr. Honggang Wang Fall 2012 Lecture 20: Container classes; strings.
1 COMS 261 Computer Science I Title: Classes Date: November 4, 2005 Lecture Number: 27.
Monday, Jan 27, 2003Kate Gregory with material from Deitel and Deitel Week 4 Questions from Last Week Hand in Lab 2 Classes.
ECE 264 Object-Oriented Software Development Instructor: Dr. Honggang Wang Fall 2012 Lecture 24: Pointers and Dynamic Allocation.
ECE 264 Object-Oriented Software Development
ECE 264 Object-Oriented Software Development Instructor: Dr. Honggang Wang Spring 2013 Lecture 16: Destructors, Copy Constructors and Exam 2 Review.
ECE 264 Object-Oriented Software Development Instructor: Dr. Honggang Wang Spring 2013 Lecture 19: Abstract Classes.
11/07/11Engineering Problem Solving with C++, second edition, J. Ingber 1 Engineering Problem Solving with C++, Etter/Ingber Chapter 8 An Introduction.
ECE 264 Object-Oriented Software Development Instructor: Dr. Honggang Wang Fall 2012 Lecture 19: Container classes; strings.
ECE 264 Object-Oriented Software Development Instructor: Dr. Honggang Wang Fall 2012 Lecture 13: Exam 1 Preview.
ECE 264 Object-Oriented Software Development Instructor: Dr. Honggang Wang Spring 2013 Lecture 17: Operator overloading and inheritance intro.
6/24/2016Engineering Problem Solving with C++, second edition, J. Ingber 1 Engineering Problem Solving with C++, Etter/Ingber Chapter 8 An Introduction.
Programming in Java Transitioning from Alice. Becomes not myFirstMethod but …. public static void main (String[] arg) { // code for testing classes goes.
Asif Nawaz University Institute of Information Technology, PMAS-AAUR Lecture 07: Object Oriented Programming:2014 Object-Oriented Programming in C++ Operator.
ECE 264 Object-Oriented Software Development
System Programming Practical Session 8 C++ classes.
HIGHLEVEL REVIEW Chapter 9 Objects and Classes
COMS 261 Computer Science I
Midterm Exam Information
EECE.3220 Data Structures Instructor: Dr. Michael Geiger Spring 2019
EECE.3220 Data Structures Instructor: Dr. Michael Geiger Spring 2019
Instructor: Dr. Michael Geiger Spring 2017 Lecture 12: Exam 1 Preview
Day 11 The Last Week!.
Presentation transcript:

ECE 264 Object-Oriented Software Development Instructor: Dr. Honggang Wang Fall 2012 Lecture 11: Examples—creating a basic class

Lecture outline Announcements / reminders  Lab 3 due Monday, 10/1  No Monday class (Columbus day) next week  Exam 1: 10/10 (review lecture on Friday, 10/05) Last time  Constructors  Using classes 3/13/2016 ECE 264: Lecture 11 2

Classes: Programmer Defined Types Classes allow programmer to define their own types Constructor(s): function called at object creation  Default constructor takes no arguments Should always define—set default value(s) for data member(s)  Parameterized constructors initializes data members to specific values Once class is created, can  Create objects (instances of class)  Call member functions  Change data members using functions Can’t directly access if private 3/13/2016 ECE 264: Lecture 11 3

Example: Creating a class Say we have a class to represent a point in a 2-dimensional plane  What data should this class hold?  What should the constructor(s) look like?  How would we write the mutator function(s)?  How would we write the accessor function(s)?  How would we write additional functions to: “Move” the point by a constant amount? Print the point in the format (X, Y)? 3/13/2016 ECE 264: Lecture 11 4

Example: Creating a class (Point.h) // Class to represent points. class Point { private: double xval, yval; public: Point(); // Default Construcutor // Constructor uses default arguments to allow //two values. Point(double x, double y); // mutator function void Setpoint (double x, double y); // Accessor. double x(); double y(); 3/13/2016 ECE 264: Lecture 10 5

Example: Creating a class (Point.h) // Distance to another point. double dist(Point other) ; // Add or subtract two points. Point add(Point b); Point sub(Point b); // Move the existing point. void move(double a, double b); // function that displays a welcome message void displayMessage(); } 3/13/2016 ECE 264: Lecture 10 6

Example: Creating a class (Point.cpp) #include #include “Point.h” // Constructor Point :: Point() { xval = 0; yval = 0; } // Parameterized Constructor Point :: Point(double x, double y ) { xval = x; yval = y; } void Point :: Setpoint(double x, double y ) { xval = x; yval = y; } // Extractors. double Point:: double x() { return xval; } double Point :: y() { return yval; } 3/13/2016 ECE 264: Lecture 11 7

Example: Creating a class (Point.cpp) // Distance to another point. double Point :: dist(Point other) { double xd = xval - other.xval; double yd = yval - other.yval; return sqrt(xd*xd + yd*yd); } // Add or subtract two points. Point Point :: add(Point b) { return Point(xval + b.xval, yval + b.yval); } Point Point :: sub(Point b) { return Point(xval - b.xval, yval - b.yval); } 3/13/2016 ECE 264: Lecture 11 8

Example: Creating a class (Point.cpp) // Move the existing point. void Point::move(double a, double b) { xval += a; yval += b; } // Print the point on the stream void Point::displayMessage() { cout << "(" << xval << "," << yval << ")"; } 3/13/2016 ECE 264: Lecture 11 9

Example: Main Program (test.cpp) main() { // Some points. Point a(5.2, -4.8); Point b(3.0, 9.0); Point c(-3.38); Point d; // Some arith. on the points. d = b.sub(c); // Point variables are not references. Point fred[5]; for(int m = 0; m < 5; m++) fred[m] = a; double w = 4.5; double x = -2.31; for(int m = 0; m < 5; m++) { fred[m].move(w, x); w += 3.4; x -= 1.3; } for(int m = 0; m < 5; m++) { fred[m].displayMessage(); } 3/13/2016 ECE 264: Lecture 11 10

Final notes Next time More class code examples UML class diagrams (if the time is permited) 3/13/2016 ECE 264: Lecture 11 11