Inheritance Examples. Example Of Multiple Inheritance class personnel { protected: char name[30]; char addr[30]; char email[30]; char birth_date[30];

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.
Recursion Prog #include <stdio.h> #include<conio.h> main()
Inheritance (2).
Contents o Introduction o Characteristics of Constructor. o Types of constructor. - Default Constructor - Parameterized Constructor - Copy Constructor.
Review of Inheritance. 2 Several Levels of Inheritance Base Class B Derived class D Derived class D1.
Templated Functions. Overloading vs Templating  Overloaded functions allow multiple functions with the same name.
Chapter 8. Operator Overloading Operator overloading gives the opportunity to redefine C++ Operator overloading refers to redefine C++ operators such.
Sort the given string, without using string handling functions.
1 Class Vehicle #include #define N 10../.. 2 Class Vehicle class vehicle { public: float speed; char colour[N+1]; char make[N+1];
ARRAY BASED STACK DATED: 30 TH AUG 2012 CLASS - XII.
A program example is given below to input date and display on the screen by write a class ‘ date ‘ # include Class date { Private: Int y, m, d ; Publice.
INHERITANCE By: Er. Gurpreet Singh Assistant Professor Department of Information Technology, Department of Information Technology, MIMIT Malout 1.
DATA FILE HANDLING. Contents to be covered in class  Concept of files & streams  Stream class hierarchy  File handling functions  Text V/S Binary.
Pointers Example Use int main() { int *x; int y; int z; y = 10; x = &y; y = 11; *x = 12; z = 15; x = &z; *x = 5; z = 8; printf(“%d %d %d\n”, *x, y, z);
Operator Overloading. 2 C++ has the ability to assign special meaning to an operator, called operator overloading one operator can be used to carry out.
Presentation on Structure. Structure Structure - It is a collection of variables referenced under one name. The keyword struct tells the compiler that.
Selection Statements in C++ If Statement in C++ Semantics: These statements have the same meaning as in the algorithmic language. 2- Two way selection:
C++ Programming: From Problem Analysis to Program Design, Fourth Edition Objectives: In this chapter, you will: Know the different between struct and array.
Unit IV Unit IV: Virtual functions concepts, Abstracts classes & pure virtual functions. Virtual base classes, Friend functions, Static functions, Assignment.
CONSTRUCTORS AND THEIR TYPES. Prepared by. MURLI MANOHAR. PGT (COMP
Session Objectives Define Static data member Static member functions in a class Object as Function Argument Friend Function Friend Class.
Spring 2008 Mark Fontenot CSE Honors Principles of Computer Science I Note Set 6 1.
Welcome to Classes and Objects Prepared By Prepared By : VINAY ALEXANDER ( विनय अलेक्जेण्डर )TGT(CS) KV JHAGRAKHAND.
Protectedly Inherited Base Class  When the access specifier of the base class in the derived class definition is protected, the base class is protectedly.
CSC241 Object-Oriented Programming (OOP) Lecture No. 4.
Inheritance - Multilevel MEENA RAWAT PGT (COMP) KV ONGC Chandkheda 1.
Passing Structure to function.  structure to function structure to function  Passing structure to function in C Passing structure to function in C 
Computer Science Department CPS 235 Object Oriented Programming Paradigm Lecturer Aisha Khalid Khan Inheritance.
Inheritance: Base and Derived Classes. Introduction In dictionary inheritance is defined as the action of inheriting; the transfer of property; to receive.
Lecture 4 Function example. Example1 int max (int a, int b) { int c; if (a > b) c = a; else c = b; return (c); } void main ( ) {int x, y; cin>>x>>y; cout.
Operator overloading: Overloading a unary operator is similar to overloading a binary operator except that there is one Operand to deal with. When you.
Statements
Introduction to Programming Lecture 40. Class Class is a user defined data type.
Int fact (int n) { If (n == 0) return 1; else return n * fact (n – 1); } 5 void main () { Int Sum; : Sum = fact (5); : } Factorial Program Using Recursion.
Spring 2008 Mark Fontenot CSE Honors Principles of Computer Science I Note Set 8 1.
FLOW OF CONTROL In C++ the program execution starts with the first statement in the main() and ends with the last statement of main(). This is called.
 Virtual Function Concepts: Abstract Classes & Pure Virtual Functions, Virtual Base classes, Friend functions, Static Functions, Assignment & copy initialization,
Asif Nawaz University Institute of Information Technology, PMAS-AAUR Lecture 07: Object Oriented Programming:2014 Object-Oriented Programming in C++ Operator.
C++ CODES PART#04 1 COPY ENGR.SABA MUGHAL FROM COMPUTER SYSTEMS DEPARTMENT.
LESSON 5 Loop Control Structure. Loop Control Structure  Operation made over and over again.  Iterate statement.
Object-Oriented Programming (OOP) Lecture No. 15
Inheritance.
Institute of Business & Technology (BIZTEK)
Concepts and Basics of C++ Programming
Presented By: Nazia Hossain Lecturer, Stamford University
Inheritance C++ strongly support the reusability, that is one class has been written and tested already it can be adapted or used to create a new class.
Concepts and Basics of C++ Programming
Lecture 8 – 9 Arrays with in a class
Ambiguity Resolution in Inheritance
Stack and Queues Stack implementation using Array
OBJECTIVE QUESTIONS.
Introduction to Programming
COPY ENGR.SABA MUGHAL FROM COMPUTER SYSTEMS DEPARTMENT
COPY ENGR.SABA MUGHAL FROM COMPUTER SYSTEMS DEPARTMENT
Structure As Function Arguments
5th Chapter Pointers in C++.
Introduction to Programming
C++ Inheritance.
Merge Sort.
Inheritance C++ strongly support the reusability, that is one class has been written and tested already it can be adapted or used to create a new class.
Abstract Data Type Abstract Data Type as a design tool
Function Overloading.
Institute of Petroloeum Technology, Gandhinagar
B.FathimaMary Dept. of Commerce CA SJC Trichy-02
The Stack.
ENGR.SABA MUGHAL FROM COMPUTER SYSTEM DEPARTMENT
Object-Oriented Programming (OOP) Lecture No. 23
Introduction to Algorithms and Programming COMP151
Inheritance in c++ Introduction
Presentation transcript:

Inheritance Examples

Example Of Multiple Inheritance class personnel { protected: char name[30]; char addr[30]; char [30]; char birth_date[30]; }; class Academic { protected: int marks_tenth; int marks_twelth; char class_ob; }; class bio_data:public personnel,public Academic { public: void getdata() { cout >name; cout >addr; cout > ; cout >birth_date; cout >marks_tenth; cout >marks_twelth; cout >class_ob; } void putdata() { cout<<"\n Name : "<<name; cout<<"\n Address : "<<addr; cout<<"\n "<< ; cout<<"\n Birth date : "<<birth_date; cout<<"\n Marks in tenth : "<<marks_tenth; cout<<"\n Marks in twelth : "<<marks_twelth; cout<<"\n Class obtained : "<<class_ob; } };

Example Of Hybrid Inheritance Student Roll No Name Test Mark1 mark2 Sports Score Result Tot_marks grade

class student { Protected: int roll_no; char name[20]; }; class test:virtual public student { protected: int mark1,mark2; }; class sports:virtual public student { protected: int score; }; class result:public test,public sports { private: int tot_marks; char grade; public: void getdata() { cout >roll_no; cout >name; cout >mark1; cout >mark2; cout >score; } void putdata() { cout<<"\n Student Info\n"; cout<<"roll no :"<<roll_no; cout<<"\n name :"<<name; cout<<"\n mark1:"<<mark1; cout<<"\n mark2: "<<mark2; cout<<"\nScore is: "<<score; cout<<"\n Total marks : "<<tot_marks; cout<<"\n Grade :"<<grade; } void calculate() { tot_marks = mark1+mark2; int r = tot_marks /2 ; if(r > 70) grade = 'A'; else if(r>60 && r<70) grade = 'B'; else grade = 'C'; } }; int main() { clrscr(); result obj; obj.getdata(); obj.calculate(); obj.putdata(); getch(); return 0; } Example Of Hybrid Inheritance

class student { int roll_no; char name[20]; public: void getdata() { cout >roll_no; cout >name; } void putdata() { cout<<"\n Student Info\n"; cout<<"roll no :"<<roll_no<<"\n name :"<<name; } }; class test:public student { protected: int mark1,mark2; public: void getdata() { student::getdata(); cout<<"\n Enter marks: "; cout >mark1; cout >mark2; } void putdata() { student::putdata(); cout<<"\n Marks: "; cout<<"\nmark1: "<<mark1<<"\n mark2: "<<mark2; } }; class sports:public student { protected: int score; public: void getdata() { cout<<"\n Enter Score: "; cin>>score; } void putdata(){ cout<<"\nScore is: "<<score;} }; class result:public test,public sports { int tot_marks; char grade; public: void getdata() { test::getdata(); sports::getdata(); } void putdata() { test::putdata(); sports::putdata(); cout<<"\n Total marks : "<<tot_marks; cout<<"\n Grade :"<<grade; } void calculate() { tot_marks = mark1+mark2; int r = tot_marks /2 ; if(r > 70) grade = 'A'; else if(r>60 && r<70) grade = 'B'; else grade = 'C'; } }; int main() { clrscr(); result obj; obj.getdata(); obj.calculate(); obj.putdata(); getch(); return 0; } Example Of Hybrid Inheritance

class student { Protected: int roll_no; char name[20]; }; class test:public student { protected: int mark1,mark2; }; class sports:public student { protected: int score; }; class result:public test,public sports { private: int tot_marks; char grade; public: void getdata() { cout >roll_no; cout >name; cout >mark1; cout >mark2; cout >score; } void putdata() { cout<<"\n Student Info\n"; cout<<"roll no :"<<roll_no; cout<<"\n name :"<<name; cout<<"\n mark1:"<<mark1; cout<<"\n mark2: "<<mark2; cout<<"\nScore is: "<<score; cout<<"\n Total marks : "<<tot_marks; cout<<"\n Grade :"<<grade; } void calculate() { tot_marks = mark1+mark2; int r = tot_marks /2 ; if(r > 70) grade = 'A'; else if(r>60 && r<70) grade = 'B'; else grade = 'C'; } friend sort(result obj_arr[]); }; int main() { result obj[10]; for(int i=0;i<10;i++) { obj[i].getdata(); obj[i].calculate(); obj[i].putdata(); } Sort(obj); for(i=0;i<10;i++) obj[i].putdata(); getch(); return 0; } Example Of Hybrid Inheritance