C++ 프로그래밍실습. Visual Studio Smart Computing Laboratory
|
|
- Maude Moore
- 5 years ago
- Views:
Transcription
1 C++ 프로그래밍실습 Visual Studio 2015
2 Contents Inheritance Exercise
3 Practice1 Inheritance
4 Practice 1-1 : Inheritance What is inheritance? The heart of OO programming A mechanism to build a new class by deriving the new class from already existing base classes Single inheritance: inherits from one base class Multiple inheritance: inherits from more than two base classes Basic data members and methods for students (e.g., name, student_no, dept, and so on) Student Base class (also called superclass or parent class) Content of a derived class Data members and methods inherited from the base classes Except for constructors and destructors Additional data members and methods specific to the derived class Inherited methods can be overridden GradStudent Additional data members and methods specific to graduate students can be defined (e.g., advisor, degree_course, thesis_title, and so on) Derived class (subclass or child class)
5 Practice 1-1 : Inheritance #include<iostream> #define PI 3.14 using namespace std; class Circle int x; int y; int radius; double get_area() return (PI * radius * radius); ; class Sphere : public Circle int z; double get_volumn() return((4.0 / 3.0) * PI *radius * radius* radius); ;
6 Practice 1-1 : Inheritance int main() Circle c; c.x = 1; c.y = 1; c.radius = 5; Sphere s; s.x = 2; s.y = 2; s.z = 2; s.radius = 2; cout << " 원의면적 : " << c.get_area() << endl; cout << " 구의표면적 : " << s.get_area() << endl; cout << " 구의부피 : " << s.get_volumn() << endl; Execution Result: 원의면적 : 78.5 구의표면적 : 구의부피 :
7 Practice 1-2 : Indirect Inheritance class Animal string species; bool warmblooded;... ; // direct derived class of Animal class Cat : public Animal string range[100]; float favoriteprey[100][100];... ; // direct derived class of Cat // indirect derived class of Animal class HouseCat : public Cat string toys[10000]; string catdoctor; string apparentowner;... ; direct base class for Cat direct base class for HouseCat indirect base class for HouseCat Animal Cat HouseCat directly derived from directly derived from indirectly derived from
8 Practice 1-2 : Indirect Inheritance #include <iostream> using namespace std; class Baseclass1 void basefunc1(); ; void Baseclass1::basefunc1() cout << " 첫번째클래스 " <<endl; class Baseclass2: public Baseclass1 void basefunc2(); ; void Baseclass2::basefunc2() cout << " 두번째클래스 " <<endl;
9 Practice 1-2 : Indirect Inheritance class Baseclass3: public Baseclass2 void basefunc3(); ; void Baseclass3::basefunc3() cout << " 세번째클래스 " << endl; class Derivedclass : public Baseclass3 ; int main () Derivedclass myclass; myclass.basefunc1(); myclass.basefunc2(); myclass.basefunc3(); return 0; Indirectly derived from Baseclass1 Baseclass2 Baseclass3 Derivedclass directly derived from directly derived from directly derived from
10 Practice 1-3 : Protected Members In addition to public and private members, C++ provides protected members Without inheritance, a protected member is just like a private member I.e., only visible within the same class In public inheritance, a protected member of a base class is also protected in its derived classes I.e., also visible in the derived classes Consequently, methods of directly or indirectly derived classes can access protected members from their base classes Note that a friend function of a class can access both private and protected members of the class (refer to chap. 6)
11 Practice 1-3 : Protected Members #include<iostream> #include<string> using namespace std; class Point protected: int x, y; void set(int x, int y) this->x = x; this->y = y; void showpoint() cout << "(" << x << "," << y << ")" << endl; ; class ColorPoint :public Point string color; void setcolor(string color) this->color = color; void showcolorpoint(); ; void ColorPoint::showColorPoint() cout << "color: " << color << endl; showpoint(); int main() Point p; p.set(2, 3); //p.x =5; protected 멤버로선언된 x 접근X //p.y =5; protected 멤버로선언된 y 접근X p.showpoint(); ColorPoint cp; cp.set(3, 4); cp.setcolor("red"); cp.showcolorpoint(); Execution Result: (2,3) color: Red (3,4)
12 Practice 1-4 : Constructors under Inheritance A derived class is a specialized version of a base class Basically, an object of a derived class contains members from the base class It also contains members that are specific to derived class itself Thus, a base class constructor also needs to be invoked when a derived class object is created The base class constructor handles initialization and other matters for the from the base class part of the object And the derived class Plan constructor 9 from handles the added outer by derived space class part of the object initializes [ An object of a derived class ] Parts from the base class Base Class Constructors Parts added by the derived class initializes Derived Class Constructors
13 Practice 1-4 : Constructors under Inheritance #include<iostream> using namespace std; class Base private: int basenum; Base() : basenum(20) cout << "Base()" << endl; Base(int n) : basenum(n) cout << "Base(int n)" << endl; void ShowBaseData() cout << basenum << endl; ; class Derived :public Base private: int derivnum; Derived() : derivnum(30) cout << "Derived()" << endl; Derived(int n) :derivnum(n) cout << "Derived(int n)" << endl; Derived(int n1, int n2) :Base(n1), derivnum(n2) cout << "Derived(int n1, int n2)" << endl; void ShowDerivData() ShowBaseData(); cout << derivnum << endl; ; Plan 9 from outer space
14 Practice 1-4 : Constructors under Inheritance int main() cout << "case1..." << endl; Derived dr1; dr1.showderivdata(); cout << "*********************" << endl; cout << "case2..." << endl; Derived dr2(12); dr2.showderivdata(); cout << "*********************" << endl; cout << "case3..." << endl; Derived dr3(23, 24); dr3.showderivdata(); Plan 9 from outer space Execution Result: case1... Base() Derived() ********************* case2... Base() Derived(int n) ********************** case3... Base(int n) Derived(int n1, int n2) 23 24
15 Practice 1-5 : Constructors &Destructor #include <iostream> using namespace std; class Parent private: int test1; Parent() : test1(1) cout << " 부모생성 " << endl; ~Parent() cout << " 부모소멸 " << endl; ; class Child : public Parent private: int test2; Child() :test2(1) cout << " 자식생성 " << endl; ~Child() cout << " 자식소멸 " << endl; ; int main() Child *myobj = new Child; delete myobj; return 0; Execution Result: 부모생성자식생성자식소멸부모소멸
16 Practice 1-6 Multiple Inheritance With multiple inheritance, a derived class may have two or more base classes With only single inheritances, an inheritance hierarchy forms a tree, with multiple inheritances it may form a graph ( pp.36) Meanings of inheritance In a single inheritance hierarchy, a derived class typically represents a specialized version of its base class In a multiple inheritance hierarchy, a derived class may represents a combination of its multiple base classes BC DC Single inheritance BC1 DC BC2 Multiple inheritance For reference, Java does NOT allow multiple inheritance for classes (c.f., only allows interfaces to inherit from multiple interfaces)
17 Practice 1-6 : Multiple Inheritance #include<iostream> using namespace std; class Adder protected: int add(int a, int b) return a + b; ; class Subtractor protected: int minus(int a, int b) return a - b; ; class Calculator :public Adder, public Subtractor int calc(char op, int a, int b); ; int Calculator::calc(char op, int a, int b) int res = 0; switch (op) case '+': res = add(a, b); break; case '- : res = minus(a, b); break; return res; int main() Calculator cal; cout << "2 + 4 = " << cal.calc('+', 2, 4) << endl; cout << "100-8 = " << cal.calc('-', 100, 8) << endl;
18 Exercise Point 클래스와 Circle 클래스를작성하되 Circle 클래스는 Point 클래스로부터상속받아구현 Point 클래스의멤버변수로좌표 (int x, y) 를포함하고 move, draw 멤버함수를포함. Circle 클래스는멤버변수로중심좌표 (int x, y) 와반지름 (double radius) 을포함하고, 멤버함수로 move, draw, getarea 를포함. * 이때 move 는두클래스모두동일한역할을하며 draw( 좌표출력 ) 는두클래스가서로다른내용으로구현되어야함. * 생성자생성할것. 다음장 main 과결과값참고.
19 Exercise
20 Submit Teaching assistant: 장성수 Office: 신공학관 1216 호 ( 대학원 SCLab 연구실 ) pik1100@naver.com Title of the [2018][Practice#]_student# _ student _ name Ex) [2018][Practice02]_ _ 장성수 Create zip file. (C++ project folder) - 주의 : 메일양식이잘못될경우채점이되지않을수있음. 질문메일 : pik1100@naver.com : 장성수
21 끝
C++ Programming: Inheritance
C++ Programming: Inheritance 2018 년도 2 학기 Instructor: Young-guk Ha Dept. of Computer Science & Engineering Contents Basics on inheritance C++ syntax for inheritance protected members Constructors and destructors
More informationC++ 프로그래밍실습. Visual Studio Smart Computing Laboratory
C++ 프로그래밍실습 Visual Studio 2015 Contents Namespaces I/O Stream Exercise Practice1 -Namespaces Practice 1 : Namespaces Name conflict problem Occurs when an application tries to use more than two libraries
More informationINHERITANCE - Part 1. CSC 330 OO Software Design 1
INHERITANCE - Part 1 Introduction Basic Concepts and Syntax Protected Members Constructors and Destructors Under Inheritance Multiple Inheritance Common Programming Errors CSC 330 OO Software Design 1
More informationC How to Program, 6/e by Pearson Education, Inc. All Rights Reserved.
C How to Program, 6/e 1992-2010 by Pearson Education, Inc. All Rights Reserved. 1 Inheritance is a form of software reuse in which you create a class that absorbs an existing class s data and behaviors
More informationINHERITANCE - Part 1. CSC 330 OO Software Design 1
INHERITANCE - Part 1 Introduction Basic Concepts and Syntax Protected Members Constructors and Destructors Under Inheritance Multiple Inheritance Common Programming Errors CSC 330 OO Software Design 1
More informationObjectives. INHERITANCE - Part 1. Using inheritance to promote software reusability. OOP Major Capabilities. When using Inheritance?
INHERITANCE - Part 1 OOP Major Capabilities Introduction Basic Concepts and Syntax Protected Members Constructors and Destructors Under Inheritance Multiple Inheritance Common Programming Errors encapsulation
More informationC++ 프로그래밍실습. Visual Studio Smart Computing Laboratory
C++ 프로그래밍실습 Visual Studio 2015 Contents STL Exercise Practice1 STL Practice 1-1 : Sets The insert method of set class ensures that the set does not contain duplicate keys Without specified position s.insert(123);
More informationInheritance, and Polymorphism.
Inheritance and Polymorphism by Yukong Zhang Object-oriented programming languages are the most widely used modern programming languages. They model programming based on objects which are very close to
More informationC++ 프로그래밍실습. Visual Studio Smart Computing Laboratory
C++ 프로그래밍실습 Visual Studio 2015 Templates & STL Contents Exercise Practice1 Templates & STL Practice 1-1 Template Classes #include using namespace std; template class Point { private:
More informationFriend Functions, Inheritance
Friend Functions, Inheritance Friend Function Private data member of a class can not be accessed by an object of another class Similarly protected data member function of a class can not be accessed by
More informationThe mechanism that allows us to extend the definition of a class without making any physical changes to the existing class is called inheritance.
Class : BCA 3rd Semester Course Code: BCA-S3-03 Course Title: Object Oriented Programming Concepts in C++ Unit III Inheritance The mechanism that allows us to extend the definition of a class without making
More informationMidterm Exam 5 April 20, 2015
Midterm Exam 5 April 20, 2015 Name: Section 1: Multiple Choice Questions (24 pts total, 3 pts each) Q1: Which of the following is not a kind of inheritance in C++? a. public. b. private. c. static. d.
More informationOBJ. ORI.& MULT. PROG., M.C.Q. BANK, FOR UNIT -2, SECOND YEAR COMP. ENGG. SEM-4, 2012 PATTERN, U.O.P. UNIT-2
UNIT-2 Syllabus for Unit-2 Introduction, Need of operator overloading, overloading the assignment, binary and unary operators, overloading using friends, rules for operator overloading, type conversions
More informationSSE2034: System Software Experiment 3 Spring 2016
SSE2034: System Software Experiment 3 Spring 2016 Jinkyu Jeong ( jinkyu@skku.edu) Computer Systems Laboratory Sungkyunkwan University http://csl.skku.edu Object Initialization class Rectangle { private:
More informationClasses - 2. Data Processing Course, I. Hrivnacova, IPN Orsay
Classes - 2 Data Processing Course, I. Hrivnacova, IPN Orsay OOP, Classes Reminder Requirements for a Class Class Development Constructor Access Control Modifiers Getters, Setters Keyword this const Member
More informationExtending Classes (contd.) (Chapter 15) Questions:
Extending Classes (contd.) (Chapter 15) Questions: 1 1. The following C++ program compiles without any problems. When run, it even prints out the hello called for in line (B) of main. But subsequently
More informationHomework 6. Yuji Shimojo CMSC 330. Instructor: Prof. Reginald Y. Haseltine
Homework 6 Yuji Shimojo CMSC 330 Instructor: Prof. Reginald Y. Haseltine July 21, 2013 Question 1 What is the output of the following C++ program? #include #include using namespace
More informationCS 117 Programming II, Spring 2018 Dr. Ghriga. Midterm Exam Estimated Time: 2 hours. March 21, DUE DATE: March 28, 2018 at 12:00 PM
CS 117 Programming II, Spring 2018 Dr. Ghriga Midterm Exam Estimated Time: 2 hours March 21, 2018 DUE DATE: March 28, 2018 at 12:00 PM INSTRUCTIONS: Do all exercises for a total of 100 points. You are
More informationClass (Inheritance) SSE2034: System Software Experiment 3, Fall 2018, Jinkyu Jeong
Class (Inheritance) Prof. Jinkyu Jeong (Jinkyu@skku.edu) TA -- Minwoo Ahn (minwoo.ahn@csl.skku.edu) TA -- Donghyun Kim (donghyun.kim@csl.skku.edu) Computer Systems Laboratory Sungkyunkwan University http://csl.skku.edu
More informationOBJECT ORIENTED PROGRAMMING USING C++
OBJECT ORIENTED PROGRAMMING USING C++ Inheritance Concept Polygon Rectangle Triangle class Polygon{ private: int numvertices; float *xcoord, *ycoord; void set(float *x, float *y, int nv); class Rectangle{
More informationGovernment Polytechnic, Muzaffarpur. Name of the Lab: OBJECT ORIENTED PROGRAMMING
Government Polytechnic, Muzaffarpur. Name of the Lab: OBJECT ORIENTED PROGRAMMING THROUGH C++ Practical: OOPS THROUGH C++ Subject Code: 1618407 PROGRAM NO.1 Programming exercise on executing a Basic C++
More informationData type of a pointer must be same as the data type of the variable to which the pointer variable is pointing. Here are a few examples:
Unit IV Pointers and Polymorphism in C++ Concepts of Pointer: A pointer is a variable that holds a memory address of another variable where a value lives. A pointer is declared using the * operator before
More informationChapter 14 Abstract Classes and Interfaces
Chapter 14 Abstract Classes and Interfaces 1 What is abstract class? Abstract class is just like other class, but it marks with abstract keyword. In abstract class, methods that we want to be overridden
More informationPolymorphism Part 1 1
Polymorphism Part 1 1 What is Polymorphism? Polymorphism refers to a programming language s ability to process objects differently depending on their data type or class. Number person real complex kid
More informationExtending Classes (contd.) (Chapter 15) Questions:
Extending Classes (contd.) (Chapter 15) Questions: 1 Virtual Functions in C++ Employee /\ / \ ---- Manager 2 Case 1: class Employee { string firstname, lastname; //... Employee( string fnam, string lnam
More informationPaytm Programming Sample paper: 1) A copy constructor is called. a. when an object is returned by value
Paytm Programming Sample paper: 1) A copy constructor is called a. when an object is returned by value b. when an object is passed by value as an argument c. when compiler generates a temporary object
More informationLecture 5: Inheritance
McGill University Computer Science Department COMP 322 : Introduction to C++ Winter 2009 Lecture 5: Inheritance Sami Zhioua March 11 th, 2009 1 Inheritance Inheritance is a form of software reusability
More informationC++ Memory Map. A pointer is a variable that holds a memory address, usually the location of another variable in memory.
Pointer C++ Memory Map Once a program is compiled, C++ creates four logically distinct regions of memory: Code Area : Area to hold the compiled program code Data Area : Area to hold global variables Stack
More informationDistributed Real-Time Control Systems. Lecture 14 Intro to C++ Part III
Distributed Real-Time Control Systems Lecture 14 Intro to C++ Part III 1 Class Hierarchies The human brain is very efficient in finding common properties to different entities and classify them according
More informationConstructor - example
Constructors A constructor is a special member function whose task is to initialize the objects of its class. It is special because its name is same as the class name. The constructor is invoked whenever
More informationPolymorphism CSCI 201 Principles of Software Development
Polymorphism CSCI 201 Principles of Software Development Jeffrey Miller, Ph.D. jeffrey.miller@usc.edu Program Outline USC CSCI 201L Polymorphism Based on the inheritance hierarchy, an object with a compile-time
More informationInheritance
Inheritance 23-01-2016 Inheritance Inheritance is the capability of one class to acquire properties and characteristics from another class. For using Inheritance concept in our program we must use at least
More informationINHERITANCE IN OBJECT ORIENTED PROGRAMMING EASIEST WAY TO TEACH AND LEARN INHERITANCE IN C++ TWINKLE PATEL
International Journal of Computer Science Engineering and Information Technology Research (IJCSEITR) ISSN(P): 2249-6831; ISSN(E): 2249-7943 Vol. 7, Issue 1, Feb 2017, 21-34 TJPRC Pvt. Ltd. INHERITANCE
More informationJava Object Oriented Design. CSC207 Fall 2014
Java Object Oriented Design CSC207 Fall 2014 Design Problem Design an application where the user can draw different shapes Lines Circles Rectangles Just high level design, don t write any detailed code
More informationDistributed Real-Time Control Systems. Chapter 13 C++ Class Hierarchies
Distributed Real-Time Control Systems Chapter 13 C++ Class Hierarchies 1 Class Hierarchies The human brain is very efficient in finding common properties to different entities and classify them according
More informationECE 462 Midterm Exam 1. 10:30-11:20AM, September 21, 2007
ECE 462 Midterm Exam 1 10:30-11:20AM, September 21, 2007 1 Template Classes and the STL Library 1.1 Container Classes Which statement is correct? Answer: B A. An element can be inserted anywhere in a stack.
More informationComp 249 Programming Methodology
Comp 249 Programming Methodology Chapter 7 - Inheritance Part A Dr. Aiman Hanna Department of Computer Science & Software Engineering Concordia University, Montreal, Canada These slides has been extracted,
More informationKapil Sehgal PGT Computer. Science Ankleshwar Gujarat Chapter 6 Inheritance Extending a Class
Chapter 6 Inheritance Extending a Class Introduction; Need for Inheritance; Different form of Inheritance; Derived and Base Classes; Inheritance and Access control; Multiple Inheritance Revisited; Multilevel
More informationCMSC 132: Object-Oriented Programming II
CMSC 132: Object-Oriented Programming II Java Support for OOP Department of Computer Science University of Maryland, College Park Object Oriented Programming (OOP) OO Principles Abstraction Encapsulation
More informationProgramming in Java, 2e Sachin Malhotra Saurabh Choudhary
Programming in Java, 2e Sachin Malhotra Saurabh Choudhary Chapter 5 Inheritance Objectives Know the difference between Inheritance and aggregation Understand how inheritance is done in Java Learn polymorphism
More informationBasic Principles of OO. Example: Ice/Water Dispenser. Systems Thinking. Interfaces: Describing Behavior. People's Roles wrt Systems
Basics of OO Programming with Java/C# Basic Principles of OO Abstraction Encapsulation Modularity Breaking up something into smaller, more manageable pieces Hierarchy Refining through levels of abstraction
More informationComputer Programming Inheritance 10 th Lecture
Computer Programming Inheritance 10 th Lecture 엄현상 (Eom, Hyeonsang) School of Computer Science and Engineering Seoul National University Copyrights 2015 Eom, Hyeonsang All Rights Reserved 순서 Inheritance
More informationINHERITANCE PART 2. Constructors and Destructors under. Multiple Inheritance. Common Programming Errors. CSC 330 OO Software Design 1
INHERITANCE PART 2 Constructors and Destructors under Inheritance Multiple Inheritance private and protected Inheritance Common Programming Errors CSC 330 OO Software Design 1 What cannot be inherited?
More informationVIRTUAL FUNCTIONS Chapter 10
1 VIRTUAL FUNCTIONS Chapter 10 OBJECTIVES Polymorphism in C++ Pointers to derived classes Important point on inheritance Introduction to virtual functions Virtual destructors More about virtual functions
More informationInstance Members and Static Members
Instance Members and Static Members You may notice that all the members are declared w/o static. These members belong to some specific object. They are called instance members. This implies that these
More informationG Programming Languages - Fall 2012
G22.2110-003 Programming Languages - Fall 2012 Lecture 12 Thomas Wies New York University Review Last lecture Modules Outline Classes Encapsulation and Inheritance Initialization and Finalization Dynamic
More informationData Structures (INE2011)
Data Structures (INE2011) Electronics and Communication Engineering Hanyang University Haewoon Nam ( hnam@hanyang.ac.kr ) Lecture 1 1 Data Structures Data? Songs in a smartphone Photos in a camera Files
More informationECE 3574: Dynamic Polymorphism using Inheritance
1 ECE 3574: Dynamic Polymorphism using Inheritance Changwoo Min 2 Administrivia Survey on class will be out tonight or tomorrow night Please, let me share your idea to improve the class! 3 Meeting 10:
More informationOverview. C++ Tutorial. Arrays. Pointers. Strings. Parameter Passing. Rob Jagnow
Overview C++ Tutorial Rob Jagnow Pointers Arrays and strings Parameter passing Class basics Constructors & destructors Class Hierarchy Virtual Functions Coding tips Advanced topics Pointers Arrays int
More informationOutline 2017/03/17. (sections from
Outline 2017/03/17 clarifications I/O basic namespaces and structures (recall) Object Oriented programming (8.1) Classes (8.2 8.6) public, protected and private Constructors and destructors Getters and
More informationCREATED BY: Muhammad Bilal Arslan Ahmad Shaad. JAVA Chapter No 5. Instructor: Muhammad Naveed
CREATED BY: Muhammad Bilal Arslan Ahmad Shaad JAVA Chapter No 5 Instructor: Muhammad Naveed Muhammad Bilal Arslan Ahmad Shaad Chapter No 5 Object Oriented Programming Q: Explain subclass and inheritance?
More informationProgramming in C# Inheritance and Polymorphism
Programming in C# Inheritance and Polymorphism C# Classes Classes are used to accomplish: Modularity: Scope for global (static) methods Blueprints for generating objects or instances: Per instance data
More informationCMSC 132: Object-Oriented Programming II
CMSC 132: Object-Oriented Programming II Java Support for OOP Department of Computer Science University of Maryland, College Park Object Oriented Programming (OOP) OO Principles Abstraction Encapsulation
More informationCSE 303 Lecture 23. Inheritance in C++ slides created by Marty Stepp
CSE 303 Lecture 23 Inheritance in C++ slides created by Marty Stepp http://www.cs.washington.edu/303/ 1 Case study exercise Represent a portfolio of a person's financial investments. Every asset has a
More informationProgramming Language Concepts Object-Oriented Programming. Janyl Jumadinova 28 February, 2017
Programming Language Concepts Object-Oriented Programming Janyl Jumadinova 28 February, 2017 Three Properties of Object-Oriented Languages: Encapsulation Inheritance Dynamic method binding (polymorphism)
More information1. the base class s (default) constructor is executed first, 2. followed by the derived class s constructor
Inheritance & Polymorphism Week 7 Gaddis: Chapter 15 CS 5301 Spring 2017 Inheritance A way to create a new class from an existing class The new class is a specialized version of the existing class Base
More informationUse the template below and fill in the areas in Red to complete it.
C++ with Inheritance Pproblem involving inheritance. You have to finish completing code that creates a class called shape, from which 3 classes are derived that are called square and triangle. I am giving
More informationCSCI 3155: Principles of Programming Languages Exercise sheet #12 26 June 2007
CSCI 3155: Principles of Programming Languages Exercise sheet #12 26 June 2007 Group name: Object-Oriented Programming I Exercise 1. The two most central aspects of object-oriented programming are dynamic
More informationCS 162, Lecture 25: Exam II Review. 30 May 2018
CS 162, Lecture 25: Exam II Review 30 May 2018 True or False Pointers to a base class may be assigned the address of a derived class object. In C++ polymorphism is very difficult to achieve unless you
More informationCSC1322 Object-Oriented Programming Concepts
CSC1322 Object-Oriented Programming Concepts Instructor: Yukong Zhang February 18, 2016 Fundamental Concepts: The following is a summary of the fundamental concepts of object-oriented programming in C++.
More informationUNIVERSITI TEKNIKAL MALAYSIA MELAKA FACULTY INFORMATION TECHNOLOGY AND COMMUNICATION (FTMK) BITE 1513 GAME PROGRAMMING I.
y UNIVERSITI TEKNIKAL MALAYSIA MELAKA FACULTY INFORMATION TECHNOLOGY AND COMMUNICATION (FTMK) BITE 1513 GAME PROGRAMMING I Lab Module 7 CLASSES, INHERITANCE AND POLYMORPHISM Department of Media Interactive
More informationCMSC 202 Section 010x Spring Justin Martineau, Tuesday 11:30am
CMSC 202 Section 010x Spring 2007 Computer Science II Final Exam Name: Username: Score Max Section: (check one) 0101 - Justin Martineau, Tuesday 11:30am 0102 - Sandeep Balijepalli, Thursday 11:30am 0103
More informationC C C C++ 2 ( ) C C++ 4 C C
# 7 11 13 C 4 8 11 20 C 9 11 27 C++ 1 10 12 4 C++ 2 11 12 11 C++ 3 12 12 18 C++ 4 C++ 5 13 1 8 ( ) 14 1 15 C++ 15 1 22 2 (D) ( ) C++ 3 7 new delete 4 5 1. 0 99 1000 0 99. 0 hist[ r ]++; (*(hist + r ))++;
More informationChapter 15: Inheritance, Polymorphism, and Virtual Functions
Chapter 15: Inheritance, Polymorphism, and Virtual Functions 15.1 What Is Inheritance? What Is Inheritance? Provides a way to create a new class from an existing class The new class is a specialized version
More informationComp151. Inheritance: Initialization & Substitution Principle
Comp151 Inheritance: Initialization & Substitution Principle Initializing Base Class Objects If class C is derived from class B which is in turn derived from class A, then C will contain data members of
More informationProgramming in C++: Assignment Week 6
Programming in C++: Assignment Week 6 Total Marks : 20 August 26, 2017 Question 1 class A { virtual void f(int) { virtual void g(double) { virtual void d(char) { int h(a *) { class B: public A { void f(int)
More informationBase class or Super class. Subclass or Derived class
INHERITANCE is the capability of one class to inherit the properties from another class. generates a model that is closer to the real world. NEED FOR INHERITANCE 1 Closeness with the real world model 3
More informationVII. POLYMORPHISM AND VIRTUAL FUNCTIONS
VII. POLYMORPHISM AND VIRTUAL FUNCTIONS VII.1 Early binding and late binding The concept of polymorphism enables different types of objects (in the same hierarchy) to use their own realization of the same
More informationIUE Faculty of Engineering and Computer Sciences Spring Semester
IUE Faculty of Engineering and Computer Sciences 2010-2011 Spring Semester CS116 Introduction to Programming II Midterm Exam II (May 11 th, 2011) This exam document has 5 pages and 4 questions. The exam
More informationHAS-A Relationship. Association is a relationship where all objects have their own lifecycle and there is no owner.
HAS-A Relationship Association is a relationship where all objects have their own lifecycle and there is no owner. For example, teacher student Aggregation is a specialized form of association where all
More informationB.Sc. (Hons.) Computer Science I B.Sc. (Hons.) Electronics. (i) Runtime polymorphism and compile time polymorphism
[This question paper contains 6 printed pages.] Sr. No. of Question Paper 6065 D Your Roll No.... Unique Paper Code 2341011251305 N arne of the Course Name of the Paper Semester B.Sc. (Hons.) Computer
More informationModern C++ for Computer Vision and Image Processing. Igor Bogoslavskyi
Modern C++ for Computer Vision and Image Processing Igor Bogoslavskyi Outline Move semantics Classes Operator overloading Making your class copyable Making your class movable Rule of all or nothing Inheritance
More informationInheritance and Overloading. Week 11
Inheritance and Overloading Week 11 1 Inheritance Objects are often defined in terms of hierarchical classes with a base class and one or more levels of classes that inherit from the classes that are above
More informationModule 7 b. -Namespaces -Exceptions handling
Module 7 b -Namespaces -Exceptions handling C++ Namespace Often, a solution to a problem will have groups of related classes and other declarations, such as functions, types, and constants. C++provides
More informationMore Tutorial on C++:
More Tutorial on C++: OBJECT POINTERS Accessing members of an object by using the dot operator. class D { int j; void set_j(int n); int mul(); ; D ob; ob.set_j(4); cout
More informationCOSC 320 Exam 2 Key Spring Part 1: Hash Functions
COSC 320 Exam 2 Key Spring 2011 Part 1: Hash s 1. (5 Points) Create the templated function object lessthan, you may assume that the templated data type T has overloaded the < operator. template
More informationWhat s Conformance? Conformance. Conformance and Class Invariants Question: Conformance and Overriding
Conformance Conformance and Class Invariants Same or Better Principle Access Conformance Contract Conformance Signature Conformance Co-, Contra- and No-Variance Overloading and Overriding Inheritance as
More information1- Write a single C++ statement that: A. Calculates the sum of the two integrates 11 and 12 and outputs the sum to the consol.
1- Write a single C++ statement that: A. Calculates the sum of the two integrates 11 and 12 and outputs the sum to the consol. B. Outputs to the console a floating point number f1 in scientific format
More informationThe Notion of a Class and Some Other Key Ideas (contd.) Questions:
The Notion of a Class and Some Other Key Ideas (contd.) Questions: 1 1. WHO IS BIGGER? MR. BIGGER OR MR. BIGGER S LITTLE BABY? Which is bigger? A class or a class s little baby (meaning its subclass)?
More informationWhat is Polymorphism? Quotes from Deitel & Deitel s. Why polymorphism? How? How? Polymorphism Part 1
Polymorphism Part 1 What is Polymorphism? Polymorphism refers to a programming language s ability to process objects differently depending on their data type or class. Number person real complex kid adult
More informationEngineering Problem Solving with C++, 3e Chapter 2 Test Bank
1. Match each of the following data types with literal constants of that data type. A data type can be used more than once. A. integer B 1.427E3 B. double D "Oct" C. character B -63.29 D. string F #Hashtag
More informationObject-Oriented Programming Concepts
Object-Oriented Programming Concepts Real world objects include things like your car, TV etc. These objects share two characteristics: they all have state and they all have behavior. Software objects are
More informationObject Oriented Design Final Exam (From 3:30 pm to 4:45 pm) Name:
Object Oriented Design Final Exam (From 3:30 pm to 4:45 pm) Name: Section 1 Multiple Choice Questions (40 pts total, 2 pts each): Q1: Employee is a base class and HourlyWorker is a derived class, with
More informationChapter 1: Object-Oriented Programming Using C++
Chapter 1: Object-Oriented Programming Using C++ Objectives Looking ahead in this chapter, we ll consider: Abstract Data Types Encapsulation Inheritance Pointers Polymorphism Data Structures and Algorithms
More informationG52CPP C++ Programming Lecture 16
G52CPP C++ Programming Lecture 16 Dr Jason Atkin http://www.cs.nott.ac.uk/~jaa/cpp/ g52cpp.html 1 Last Lecture Casting static cast dynamic cast const cast reinterpret cast Implicit type conversion 2 How
More informationG52CPP C++ Programming Lecture 13
G52CPP C++ Programming Lecture 13 Dr Jason Atkin http://www.cs.nott.ac.uk/~jaa/cpp/ g52cpp.html 1 Last lecture Function pointers Arrays of function pointers Virtual and non-virtual functions vtable and
More informationObject-oriented Programming. Object-oriented Programming
2014-06-13 Object-oriented Programming Object-oriented Programming 2014-06-13 Object-oriented Programming 1 Object-oriented Languages object-based: language that supports objects class-based: language
More informationObject Oriented Features. Inheritance. Inheritance. CS257 Computer Science I Kevin Sahr, PhD. Lecture 10: Inheritance
CS257 Computer Science I Kevin Sahr, PhD Lecture 10: Inheritance 1 Object Oriented Features For a programming language to be called object oriented it should support the following features: 1. objects:
More informationSDV4001 Object Oriented Programming with C++ and UI Midterm 2013
Name : ID: Group: SDV4001 Object Oriented Programming with C++ and UI Midterm 2013 Marks : 30 Answer all questions. Time: 60 mins Section 1: MCQs (Circle the correct choice clearly) -12 marks (12 x 1)
More informationCIS3023: Programming Fundamentals for CIS Majors II Summer 2010
CIS3023: Programming Fundamentals for CIS Majors II Summer 2010 Objects and Classes (contd.) Course Lecture Slides 19 May 2010 Ganesh Viswanathan Objects and Classes Credits: Adapted from CIS3023 lecture
More informationAgenda. The main body and cout. Fundamental data types. Declarations and definitions. Control structures
The main body and cout Agenda 1 Fundamental data types Declarations and definitions Control structures References, pass-by-value vs pass-by-references The main body and cout 2 C++ IS AN OO EXTENSION OF
More informationProgramming using C# LECTURE 07. Inheritance IS-A and HAS-A Relationships Overloading and Overriding Polymorphism
Programming using C# LECTURE 07 Inheritance IS-A and HAS-A Relationships Overloading and Overriding Polymorphism What is Inheritance? A relationship between a more general class, called the base class
More informationPOLYMORPHISM. Phone : (02668) , URL :
POLYMORPHISM POLYMORPHISM Polymorphism is the property of the same object to behave differently in different context given the same message Compile Time and Runtime Polymorphism Compile time - Function
More informationCSE 143. "Class Relationships" Class Relationships and Inheritance. A Different Relationship. Has-a vs. Is-a. Hierarchies of Organization
Class Relationships and Inheritance [Chapter 8, pp.343-354] "Class Relationships" is the title of Chapter 8 One class may include another as a member variable Date" used inside "Performance" Called a "has-a"
More informationStudent Name and ID CS 32, WINTER 2015, PRACTICE MIDTERM I.
UCLA Computer Science Department TA: Kung-Hua Chang Student Name and ID CS 32, WINTER 2015, PRACTICE MIDTERM I. Problem # Maximal Possible Points Received 1.1 3 1.2 5 1.3 5 1.4 5 1.5 5 2 3 3.1 4 3.2 5
More informationObject Oriented Programming. Assistant Lecture Omar Al Khayat 2 nd Year
Object Oriented Programming Assistant Lecture Omar Al Khayat 2 nd Year Syllabus Overview of C++ Program Principles of object oriented programming including classes Introduction to Object-Oriented Paradigm:Structures
More informationOBJECT ORIENTED PROGRAMMING
OBJECT ORIENTED PROGRAMMING OBJECT ORIENTED PROGRAMMING Design principles for organizing code into user-defined types Principles include: Encapsulation Inheritance Polymorphism http://en.wikipedia.org/wiki/encapsulation_(object-oriented_programming)
More informationDue Date: See Blackboard
Source File: ~/2315/45/lab45.(C CPP cpp c++ cc cxx cp) Input: under control of main function Output: under control of main function Value: 4 Integer data is usually represented in a single word on a computer.
More informationCS11 Introduction to C++ Fall Lecture 7
CS11 Introduction to C++ Fall 2012-2013 Lecture 7 Computer Strategy Game n Want to write a turn-based strategy game for the computer n Need different kinds of units for the game Different capabilities,
More informationProgramming in C++: Assignment Week 6
Programming in C++: Assignment Week 6 Total Marks : 20 Partha Pratim Das Department of Computer Science and Engineering Indian Institute of Technology Kharagpur 721302 partha.p.das@gmail.com April 6, 2017
More information