Lab 02 - SNAP.

Slides:



Advertisements
Similar presentations
Overriding CMPS Overriding Recall, a method in a child class overrides a method in the parent class, if it has the same name and type signature.
Advertisements

Module 8 “Polymorphism and Inheritance”. Outline Understanding Inheritance Inheritance Diagrams Constructors in Derived Classes Type Compatibility Polymorphism.
Class Hierarchies. Inheritance is the capability of a class to use the properties and methods of another class while adding its own functionality. An.
UML Class and Sequence Diagrams Violet Slides adapted from Marty Stepp, CSE 403, Winter 2012 CSE 403 Spring 2012 Anton Osobov.
Object Oriented Programming.  OOP Basic Principles  C++ Classes  September 2004  John Edgar 22.
Software Engineering Principles and C++ Classes
UML a crash course Alex Lo Brian Kiefer. Overview Classes Class Relationships Interfaces Objects States Worksheet.
Inheritance and Polymorphism CS351 – Programming Paradigms.
Virtual Functions Junaed Sattar November 10, 2008 Lecture 10.
Unified Modeling Language
Chapter 12: Adding Functionality to Your Classes.
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.
OBJECT ORIENTED PROGRAMMING LECTURE 12 Instructor: Rashi Garg Coordinator: Gaurav Saxena.
Copyright © 2011 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Taken from slides of Starting Out with C++ Early Objects Seventh Edition.
Overview of Previous Lesson(s) Over View  OOP  A class is a data type that you define to suit customized application requirements.  A class can be.
1 Chapter 10: Data Abstraction and Object Orientation Aaron Bloomfield CS 415 Fall 2005.
What is inheritance? It is the ability to create a new class from an existing class.
Chapter 7 Objects and Classes 1 Fall 2012 CS2302: Programming Principles.
Engineering H192 - Computer Programming The Ohio State University Gateway Engineering Education Coalition Lect 24P. 1Winter Quarter C++ Lecture 24.
Data Structures Using C++1 Chapter 1 -Software Engineering Principles -ADT and Classes.
Designing Classes Chapter 3. 2 Chapter Contents Encapsulation Specifying Methods Java Interfaces Writing an Interface Implementing an Interface An Interface.
Chapter 9 Questions 1. What are the difference between constructors and member functions? 2. Design and implement a simple class as you want, with constructors.
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.
CS-1030 Dr. Mark L. Hornick 1 Basic C++ State the difference between a function/class declaration and a function/class definition. Explain the purpose.
UML Part 1: Class Diagrams. Introduction UML stands for Unified Modeling Language. It represents a unification of the concepts and notations presented.
Terms and Rules II Professor Evan Korth New York University (All rights reserved)
Polymorphism and Virtual Functions One name many shapes behaviour Unit - 07.
Object-Oriented Programming (OOP) and C++
CSC241 Object-Oriented Programming (OOP) Lecture No. 17.
 Virtual Function Concepts: Abstract Classes & Pure Virtual Functions, Virtual Base classes, Friend functions, Static Functions, Assignment & copy initialization,
ISBN Chapter 12 Support for Object-Oriented Programming.
A First Book of C++ Chapter 12 Extending Your Classes.
C++ How to Program, 7/e.  There are cases in which it’s useful to define classes from which you never intend to instantiate any objects.  Such classes.
UML Review – class diagrams SE-2030 Dr. Mark L. Hornick 1.
Lecture 2 (UNIT -1) SUNIL KUMAR CIT-UPES.
Inheritance Modern object-oriented (OO) programming languages provide 3 capabilities: encapsulation inheritance polymorphism which can improve the design,
Object-Oriented Programming Concepts
INTRODUCTION TO OBJECT-ORIENTED PROGRAMMING
Unified Modeling Language
CMSC 202 Polymorphism.
Class and Objects UNIT II.
CS3340 – OOP and C++ L. Grewe.
Polymorphism &Virtual Functions
Object-Oriented Programming
Review: Two Programming Paradigms
Wednesday, January 31, 2018 Announcements… For Today… For Next Time…
group work #hifiTeam
1.4 Abstract Data Types, Interfaces, and Pre- and Postconditions
Polymorphism Lec
(5 - 1) Object-Oriented Programming (OOP) and C++
Object Oriented Analysis and Design
3.3 Abstract Classes, Assignment, and Casting in a Hierarchy
Inheritance: Polymorphism and Virtual Functions
Polymorphism CMSC 202, Version 4/02.
(5 - 1) Object-Oriented Programming (OOP) and C++
Inheritance: Polymorphism and Virtual Functions
Object-Oriented Programming (OOP) Lecture No. 22
From C to C++: Summary of weeks 1 - 4
2.1 Program Defects and "Bugs''
CS410 – Software Engineering Lecture #5: C++ Basics III
Eighth step for Learning C++ Programming
Inheritance: Polymorphism and Virtual Functions
CECS 130 Final Exam Review Session
2.6, pgs Efficiency of Algorithms Big-O Notation
C++ Object Oriented 1.
Static Binding Static binding chooses the function in the class of the base class pointer, ignoring any versions in the class of the object actually.
Programming in C# CHAPTER 5 & 6
Presentation transcript:

Lab 02 - SNAP

S.N.A.P Lab Lab 02 - SNAP Class design is type design - defining effective classes can be challenging. For the SNAP lab you are to design classes for a school database with has-a and is-a relationships that have natural syntax, intuitive semantics, and efficient memory allocation. The class objects are populated from parsed input strings. Use object inheritance, polymorphism, and function and operator overloading where needed. All member data and internal functions are private. All classes have a "toString" method with friends for the insertion ("<<") operator. Use UML diagrams to describe your implementation.

OOP vs. Procedural Programming Lab 02 - SNAP Division Of Program: In procedural programming a program is divided into small functions while in OOP it is divided into objects. Importance: In procedural programming importance is not given to data but to procedures. In OOP importance is given to data rather than functions, because OOP works with real world objects. Approach: Procedural programming is top down (design functions first.) OOP is bottom up (design objects then interactions.) Access Specifiers: In procedural programming no access specifiers are used. In OOP different type of specifiers are used for different levels of data protection. Data Moving: In procedural programming, data can move freely from function to function. In OOP, data can only move via member functions. Data Access: In procedural programming global data is acceptable and freely accessible. In OOP, public or private access specifiers are used to control data access. Data Hiding: In procedural programming, no particular method is used for data hiding and therefore it is less secure. A particular method is used for data hiding in OOP so it is more security. Overloading: Overloading is not possible in procedural programming. Overloading is possible in OOP in the form of function overloading and overloading operator.

Example SNAP Output Student # Name Address Phone # Course Student # Lab 02 - SNAP Input Strings: snap(12345,Carlie Brown,Manager,555-1234). snap(67890,Lucy,Right Field,555-5678). csg(CS101,12345,A). csg(CS101,67890,B). xxxx ** Undefined xxxx cdh(CS101,M,9AM). cdh(CS101,W,9AM). cr(CS101,1170 TMCB). Vectors: snap(12345,Carlie Brown,Manager,555-1234) snap(67890,Lucy,Right Field,555-5678) csg(CS101,12345,A) csg(CS101,67890,B) cdh(CS101,M,9AM) cdh(CS101,W,9AM) cr(CS101,1170 TMCB) Course Grades: CS101 MW, 1170 TMCB Carlie Brown 12345, A CS101 MW, 1170 TMCB Lucy 67890, B Student Schedules: Carlie Brown, 12345, Manager, 555-1234, CS101 MW 9AM, 1170 TMCB Lucy, 67890, Right Field, 555-5678, CS101 MW 9AM, 1170 TMCB Student # Name Address Phone # Course Student # Grade Course Day Hour Input Error Course Room

UML This class is called Passenger. Lab 02 - SNAP This class is called Passenger. The data members are all listed by visibility, name, and type. Visibility: A '-' in front of a data member or function means that the data or function is private. A '+' indicates public visibility and a '#' indicates a protected visibility Type: You may indicate parameter type and return type before or after the name of the data member/function. Both of the following are acceptable: +string getName() +getName():string

UML: Interfaces / Abstract Functions Lab 02 - SNAP There is an important distinction between a concrete class and an abstract class or interface. An interface has strictly pure virtual functions. An abstract class has at least one pure virtual function, but other functions may be defined. Both interfaces and abstract classes have italicized class names. Interfaces are denoted with <<interface>> (not in italics) above the class name. Virtual functions are italicized. In this example, because not all of Locomotive's functions are pure virtual, Locomotive is not an interface.

UML Inheritance ("Is-a") Lab 02 - SNAP In this example, the class Steam Engine inherits from the abstract class Locomotive. It has access to all of the concrete functions of Locomotive, and also defines the abstract functions of Locomotive. Note that not all of the concrete functions from Locomotive are included in SteamEngine. This is because they are accessed through inheritance structure. On the other hand, the abstract functions appear in both places. It is a good practice to show a function both where it is declared and where it is defined. For the interfaces that you will use in this class, it is acceptable to omit the inherited functions from the child class. Inheritance is indicated with a white triangle arrowhead facing the parent class.

UML Inheritance ("Has-a") Lab 02 - SNAP In this example, the class Steam Engine references the class Passenger, placing pointers to Passenger objects inside of its private vector. This relationship is indicated by using a filled diamond arrow. The arrow faces towards the class that "has" the other thing in it. Note: For the purposes of our class, we do not distinguish between having an object and having a pointer to an object. Just use the same type of arrow.

UML Inner Classes Lab 02 - SNAP Sometimes, we will define a class within a class, or a struct within a class. When we do this, we include the class/struct declaration inside of the outer class, and then create another box to hold the information for the class/struct. To show this connection, we use a circle with a cross through it. The circle should be closest to the class that contains the inner class/struct.

UML Lab 02 - SNAP

UML Summary Lab 02 - SNAP

Lab 02 - SNAP Animal legs:int class Animal { private: string name; public: Animal(string name) { this->name = name; } virtual string getName() = 0; } Animal legs:int class Dog: public Animal { private: int legs; public: Dog(string name, int legs) { this->name = name; this->legs = legs; } T getLegs() { return lets; } virtual string getName() { return name; } } int main() { Animal* dog = new Dog("Rover", 4); cout << dog->getName() << " " << dog->getLegs(); return 0; }

Lab 02 - SNAP Animal legs:int #include <iostream> #include <string> using namespace std; class Animal { private: string name; public: Animal() {} void setName(string name) { this->name = name; } string getName() { return name; } }; class Dog : public Animal int legs; Dog(string name, int legs) setName(name); this->legs = legs; } int getLegs() { return legs; } int main() Dog* dog = new Dog("Rover", 4); cout << dog->getName() << " " << dog->getLegs(); delete dog; return 0; Animal legs:int

UML Summary Lab 02 - SNAP is-a