0% found this document useful (0 votes)
132 views22 pages

Oop Practical 13 To 15

Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF or read online on Scribd
0% found this document useful (0 votes)
132 views22 pages

Oop Practical 13 To 15

Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF or read online on Scribd
You are on page 1/ 22
Object Oriented Programming Using C ++ (22316) eb IV VI vi 13: Program to Implement Concept Multiple Inheritance Practical Practical Significance: i Multiple Inheritances is a feature of C++ where a class can inherit from more than one classes. Relevant Program Outcomes (POs) © Basic knowledge: Apply knowledge of basic mathematics, sciences and basic engineering to solve the broad-based Computer engineering problem. © Discipline knowledge: Apply Computer engineering discipline - specific knowledge to solve core computer engincering related problems. © Experiments and practice: Plan to perform experiments and practices to use the results to solve broad-based Computer engineering problems. o Engineering tools: Apply relevant Computer technologies and tools with an understanding of the limitations. © Communication: Communicate effectively in oral and written form. Competency and Practical skills This practical is expected to develop the following skills in you Develop C+ programs to solve broad-based problems 1, Apply multiple inheritances to real life problems. 2. Compile the program. 3. Debug and execute the program. Relevant Course Outcome(s) Implement Inheritance in C++ program Practical Outcome (POs) Write/ Compile/ debug / Execute simple C++ program using multiple inheritance. Relevant Affective domain related Outcome(s) 1. Select proper programming environment in C++. 2. Follow safety measures 3. Follow ethical practices. Minimum Theoretical Background 1, Inheritance :-It is the process of inheriting properties of objects of one class by objects of another class. The class which inherits the properties of another class is called Derived or Child or Sub class and The class whose properties are inherited is called Base or Parent or Super class. 2. Multiple Inheritance :-When a class is derived from two or more base classes, such inheritance is called Multiple Inheritance. It allow us to combine the features of several existing classes into a single class. Maharashira state Board of Technical Education @ Object Oriented Programming Using C ++ (22316) IX Precautions 1. Handle computer system and peripherals with care. 2. Follow safety practices X Resources used S.No] Name of Resource Specification 1 [Computer System : RAM> Dy) with broad specifications | "S Ith Gen .8aB, 5I2GR Rae. 2 Software Tusboctr 3 | Any other resource used XI Result (Output of the Program) oe : -PIQQra-m-. ee BBE CU EEA A ET. 4 USING, Paiva Cece rote ate XII__ Practical Related Questions Note: Below given are few sample questions for reference. Teacher must design ‘more such questions so as to ensure the achievement of identified CO. (Note: Use Point VIII to X and XIII to XV for all relevant programming exercise use blank pages provided or attach more pages if needed.) 1. What is the difference between multiple and multilevel inheritance in C++? 2. State output of the following code: #include #include class liquid ( float specific gravity: public: void input () ( cout<<"Specific gravity: "; cin>>specific gravity; ) void output () ( cout<<"Specific gravity <>rate; ) void output () ( cout<<"Rate(per liter): §"< class Base ( public: virtual void print() const = 1 class Derivedone : ‘ public Base public: void print() const ‘ cout << "Derivedone\n"; } M class DerivedTwo : public Base { public: void print () const { cout << “DerivedTwo\n"; ) ip class Multiple : Derivedtwo { public DerivedOne, public public: void print() const ‘ DerivedTwo print(); , int main() int i; Multiple both; DerivedOne one; Derivedtwo two: Base *array[ 3 J+ array{ 0] = éboth; array{ 1 ] = Gone; array[ 2] = &two; array[ i] -> print(); return 0; Evror:- Base’ v5 an ambigious base of HO ultip le So it produces an exsor & This Progam "Sof Visual clags,| Object Oriented Programming Using © ++ 22316) b) Vinelude : struct a Output*- { Ant county ‘ : Inherited struct b | ints value, ye struct @ + public a, public b i Me int main() ( ct p= new povalue = "0; Sout << "Inherited"; return 07 (Space for answers) LN eee oman ett inctuidle Class Are pubic aloes tho void meCraa es Hoat b) Cout>? length >> breadthy = ‘he ineiucle _ class Cricketer me —__——_—|_-4 - Char cname £207; 2 } mt ec sores a | “ce cname, | Couts<’ \n_ cricketer’s Score i” << Void getre— = Cout<<’’ \n Enter bow less name and no: of — “Maichets tencena’)) ee ______ Cin» bo_ nome >> Uoickets; Gout <2 "ND Bocoler’s Names!’ << b-mame 5 ___Coute<™\ No- OF wickets taken i” << Wickets + cout> br mame >> auns: — an pe ~ yey fas eens | = — ——s _ | a id_disptiayaQ a __ cout*\n_Batsmoan name:"<< btname; a cout \q So -of buns Made’! << wuns } —' Object Oriented Programming Using © ++ 22016) m Iv vi vil Maharashtra state Board of Technical Education Practical No. 14: Program to Implement Pointer to Object Practical Significance; ‘The pointer to objects helps to improve the efficiency of the program and access the objects dynamically. Relevant Program Outcomes (POs) ic knowledge: Apply knowledge of basic mathematics, sciences and basic ‘engineering to solve the broad-based Computer engineering problem. ‘© Discipline knowledge: Apply Computer engineering discipline ~ specific knowledge to solve core computer engineering related problems o Experiments and practice: Plan to perform experiments and practices to use the results to solve broad-based Computer engineering problems © Engineering tools: Apply relevant Computer technologies and tools with an understanding of the limitations © Communication: Communicate eff tively in oral and written form. Competency and Practical skills This practical is expected to develop the following skills in you Develop C+ programs to solve broad-based problems 1. Define real life problems using pointer to objects, 2.Compile the program, 3. Debug and execute the program, Relevant Course Outcome(s) Implement Inheritance in C+ program Use Polymorphism in C++ program, Practical Outcome (POs) Write/ Compile/ debug / Execute simple C++ program using pointer to object Relevant Affective domain related Outcome(s) 1. Select proper programming environment in C++ 2. Follow safety measures 3. Follow ethical practices. Minimum Theoretical Background Pointers to objects: C+ allows you to have pointers to objects. The pointers pointing to objects are referred to as Object Pointers. ‘Syntax:- class-name * object-pointer ; where class-name is the name of an alread! is the pointer to an object of this class type. For example, to declare optr as an object pointer of Sampl shall write Sample *optr ;where Sample is already defined be es we When accessing members of a class using an object poi (C>) is used instead of dot operator, ect pointer, the arrow operator ly defined class and object-pointer Object Oriented Programming Using C++ (22316) VIII Resources required Sr. | Ni if Nel |” Rasoarse Specification Quantity Remarks 1 | Hardware: Computer (13-15 | Computer preferable), RAM System minimum 2 GB and onwards, HDD 40GB and — 40GB and’ | As per batch For all | _ size Experiments 2 | Operating ‘Windows /LINUX system 3 | Software Turbo C+ Version 3.0 or any | other IX ___ Precautions 1. Handle computer system and peripherals with care. 2. Follow safety practices. X Resources used S.No. | Name of Resource Specification T | Computer System : with broad 15, 84B RAM | windovas 4 specifications - 2__| Software Turbo ctt 3 | Any other resource used XI__Result (Output of the Program) We... SUcessfully. pointer...10.... Object: PIOGTarn...Using XII Practical Related Questions Note: Below given are few sample questions for reference. Teacher must design more such questions so as to ensure the achievement of identified CO. (Note: Use Point VIII to X and XIII to XV for all relevant programming exercise use blank pages provided or attach more pages if needed.) 1. State output of the following code: #include #include glass myciass int 4; public: void read(int 3) ( cH int getint() ( return i; ‘Maharashtra state Board of Technical Education a Object Oriented Programming Using C ++ (22316) } void main() ( elrser(); myclass ob, *objectPointer; objectPointer = sob; objectPointer->read(10); cout<getint (); getch(); ) 2. Which is the pointer which denotes the object calling the member function? a) Variable pointer b) This pointer c) Null pointer 4) Zero pointer 3. A pointer can be initialized with . a) null b) zero ©) Address of an object of same type 4) All of them (Space for answers) Re TINS. PORNO. A @MALE. SG. th @....OBjECK.. SA mg... Calling.....the...... ne mbea.... function. Fra stale Board of Technical Education XIII Exercise: Attempt Q1 or Q2 or Q3 and Q.4.a or b from the following: (Note: Use Point VIII to X and XIII to XV for all relevant programming exercise use blank pages provided or attach more pages if needed.) A” Write a C++ program to declare a class “Book” containing data members book_name, auther_name, and price .Accept this information for one object of the class using pointer to that object. 2 Write a C++ program to declare a class “Box” having data members height, width and breadth. Accept this information for one object using pointer to that object -Display the area and volume of that object. 3. Write a C++ program to declare a class birthday having data members day, month, year. Accept this information for five objects using pointer to the array of objects. Maharashtra state Board of Technical Education 38 is Programming Using C++ (22316) 4, Complete the given table: Write & justify Program Code Gakial a) Output: Hinclude a #include nitializg class Tine dato members short int hh, mm, ss: using object ery, with value ( hh = mm = ss = 0; egciie G ) oo void getdata(int i, int J, int k) | PBINEING net member mn = 3; using object ss =k: time (2,234) void prndata (void) ( prmtmg coutcer\ntine 1s "eenhce"s ereesscc"\n"s | Wag mew ds using point void main() a i is time - elrser(); Time T1, *tptr; 16:00; 00 cout<<"Initializing data members using the object, with values 12, 22, 11\n"; T1.getdata (12, 22,11); cout<<"Printing members using the object T1.prndata(); tptr = 6Tl; cout<<"Printing members using the object pointer "; tptr->prndata(); cout<<"\nInitializing data members using the object poiny4r, with values 15, 10, 16\n"; ta(15, 10, 16)7 jting members using the object T1.prndata (); cout<<"Priqting members using the object pointer ";|tptr->prndata(); getch(); ) Maharashtra state Board of Technical Education = Object Oriented Programming Using C++ (22316) b) Finclude #include using namespace std; class student ay " Convert Chat private: . int_rolino; 2) deciavation string name; public: student () :r0l1no (0) ,name ("") Suntay error a student (int x, string a): erroy roLino (#) ;name.(n) pares oy expecte void get () ie ( ‘get’: coutccventer roll now; | 4) 9 is, cin>>rolino; cout<<"enter name"; not Member , cin>>name of student void print () Hl 5)unabie to cout<<"roll no is *< Qut.norne >> prices —— ———_____— Ni outs<“*\n Bo ateeb name <<" \n Author _ oe << out yore <<*\0_ price?” ¢¢ prices. Void yoind: : a ere RS Ps &by = P—> getO : P> Put, Be getcho;s ao ae ae q coeee Object Oriented Programming Using C++ (22316) Iv VI vo Practical No. 15: Program to Implement Pointer Derived Class Practical Significance: The key feature of class inheritance is that a pointer to a derived class is type- compatible with a pointer to its base class. Relevant Program Outcomes (POs) © Basic knowledge: Apply knowledge of basic mathematics, sciences and basic engineering to solve the broad-based Computer engineering problem. © Discipline knowledge: Apply Computer engineering discipline - specific knowledge to solve core computer engineering related problems. © Experiments and practice: Plan to perform experiments and practices to use the results to solve broad-based Computer engineering problems. © Engineering tools: Apply relevant Computer technologies and tools with an understanding of the limitations. © Communication: Communicate effectively in oral and written form. Competency and Practical skills ‘This practical is expected to develop the following skills in you Develop C++ programs to solve broad-based problems 1. Define pointer to derived class. 2. Compile the program. 3. Debug and execute the program. Relevant Course Outcome(s) Implement Inheritance in C++ program, Use Polymorphism in C++ program. Practical Outcome (POs) Write/ Compile/ debug / Execute simple C++ program using pointers to derived class. Relevant Affective domain related Outcome(s) 1. Select proper programming environment in C++. 2. Follow safety measures 3. Follow ethical practices. Minimum Theoretical Background Pointers to derived class 1, C++ allows base class pointers to point to derived class objects. 2. Let we have ~ class base { ... }; class derived : public base { ... }; ‘Then we can write — base *p]; derived Maharashtra state Board of Technical Education Dijecs Oriewies Programming Vising C# FEIN ne 4 hy, pl ~ 1A hy base *yl~ new derived; 3. Using a base class pointer (pointing tw « derived cass dbjed) we cam aocees only thove members of the derived chject that were inherited from the base Ih is different from the behavior that Lava shows, b. We can get Javalike behavior using virtual functions, 4. This is because the base pointer has knowledge only of the tase class 5. Itknows nothing abot the members added by the derived class (Sr Name a | Remarks |[No._| Resource | Specification | Quantity [ 1 | | Computer (3-15 | Computer | preferable), RAM | | System | minimum 2 GB and | | | onwards, HDD Band It woe | As perbatch | Windows LINUX | | | | Turbo C74 Version 3.0 oF any | ones 1 1. Handle computer system and peripherals with care. 2. Follow safety practices. ‘Specification 13, 8@B RAM, Win dovoslO Turbo c++ Maharashtra vate Board oh Technical Eawcation 100 au Ga a_i ee) ~~ Object Oriented Programming Using C++ (22316) XII__ Practical Related Questions Note: Below given are few sample questions for reference. Teacher must design more such questions so as to ensure the achievement of identified CO. (Note: Use Point VIII to X and XIII to XV for all relevant programming exercise use blank pages provided or attach more pages if needed.) 1. State output of the following code: #include class base ( public: void show() cout << “base\n”; ) class derived : public base ( public: void show() ( cout << “derived\n"; ) Me void main() ( base bl: bl.show() derived di; al. show(); base “pb — ébl; pb->show () pb = dl; pb->show () ) 2. A pointer to the base class can hold address of A) only base class object B) only derived class object C) base class object as well as derived class object. D) None of the above 3. Which variable stores the memory address of another variable? A)Reference _B) Pointer ©) Array D) None of the above (Space for answers) eonen A AA.¥ .F. IASS... OBj.0ch....OS.... RUS. vo TMC. MASS... OBOCL: Pointey.”..Work. ORIG... SHOES. th, an B. POLMEE. on the... Maharashtra state Board of Technical Education Object Oriented Programming Using C++ 22316) 2._Complete the given table: Write & justify Program Code Output #include class base output :- public: int nl; pointey void show() ( ‘ : of base cout<<"\nnl = “< 66 { cout<<*\nnl = “<show() ; derive d cout<<”\n bptresd; pptr->nl=66; bptr->show () 7 return 0; ) by) Finclude : class BaseClass ( output int x7 : public! Base object void setx(int 4) ( x10 ) Base. object int getx() ( return x; x1 4q ) x M Devived class DerivedClass ; public BaseClass ( Object xs 4q. int yi public: void sety(int i) ( yo is ‘Maharashtra state Board of Technical Education 10s Odject Oriented Programming Using C ++ (22316) , int gety() { return y? derivedobject: Pp = sbaseobject; po>setx(10)7 cout << "Base object x: " << p->getx() << Nee P = Sderivedobject: po>setx (33) 7 derivedobject .sety (88); cout << "Derived object x: * << p->getx() << ‘\ate ‘cout << "Derived object y: * << derivedObject.gety() << "\n's return 07 } ~ Cout<< \n bo "Ze b3 O98 ck getch 0d}

You might also like