PESIT Bangalore South Campus
|
|
- Shon Wood
- 6 years ago
- Views:
Transcription
1 USN 1 P E PESIT Bangalore South Campus Hosur road, 1km before Electronic City, Bengaluru -100 Department of ECE INTERNAL ASSESSMENT TEST 2 Date : 03/10/2017 Marks: 40 Subject & Code : Object Oriented Programming using C++ - Sem & Sec: 5 th A & B 15EC562 Name of faculty : Shwetha S Bhat Time : 11:30am -1:00pm Note: Answer FIVE full questions, selecting any ONE full question from each part Marks PART 1 1 a Define c++ features: a) Polymorphism b) Multiple Inheritance c) String handling d) Multiple level Inheritance 8 OR 2 a Define destructor and explain the use of destructor with example 4 b Write the characteristics of constructors 4 PART 2 3 a Define this pointer. Give example of accessing and returning of object using this pointer b What is Operator Overloading function? Write a program to add two complex numbers using overloading the operator + function OR 4 a Explain private, public and protected inheritance of a derived class from base class with an example for each PART 3 5 a Write a program to overload both prefix and postfix increment operator using 8 operator function and display the output before and after the operation OR 6 a What are the types of constructors and explain each with an example 8 PART 4 7 a What are the rules followed for operator overloading if the function is declared as member function and as friend function for unary and binary operators 8
2 OR 8 a Explain the difference between Virtual function and Pure Virtual function with example b Write the methods to access the data member or member function using pointer to objects 6 2 PART 5 9 a Write a program to add two integer numbers. Use numbers as base class, readnums, printnums and caladdn as derived class and incorporate inheritance OR 10 a Write a program to get a square and cube of a number using hierarchical inheritance 8 8
3 P.E.S. Institute of Technology( Bangalore South Campus) Hosur Road, ( 1Km Before Electronic City), Bangalore Department of Electronics and Communication SCHEME AND SOLUTION _II INTERNAL TEST Faculty: Shwetha S Bhat Semester: 5 th A & B Subject: Object Oriented Programming using C++ Sub. Code: 15EC562 Q.No. Questions and its answers Marks 1. a.) Define C++ features (8 marks) a) Polymorphism Property by which objects belonging to different classes are able to respond to name/work in different forms It is supported by C++ both at compile time and at run time. Compile-time polymorphism is achieved by overloading functions and operators. Run-time polymorphism is accomplished by using inheritance and virtual functions. b) Multiple Inheritance It is possible for a derived class to inherit two or more base classes. Deriving directly from more than one class is usually called multiple inheritance. c) String handling Class by name string is available to perform any operations like merging of strings, conditional checks on strings etc. The class can be used best with new operator to allocate memory for each string and a pointer variable to point to the string array. d) Multiple level Inheritance A child class is derived from a base class and again a new child class is derived from this 1 st child class and so on. Hence the property of base class and the property of the 1 st child class can be accessed by the 2 nd child class. 2.) a.) Define destructor and explain the use of destructor with example (4 marks) A destructor is a special member function of a class that is executed whenever an object of it's class goes out of scope or whenever the delete expression is applied to a pointer to the object of that class. A destructor will have exact same name as the class prefixed with a tilde (~) and it can neither return a value nor can it take any parameters. Destructor can be very useful for releasing resources before coming out of the program like closing files, releasing memories etc. Syntax ~sample() // Destructor for the constructor sample()
4 #include <iostream> class Line void setlength( double len ); double getlength( void ); Line(); ~Line(); private: double length; ; Line::Line(void) cout << "Object is being created"; Line::~Line(void) cout << "Object is being deleted"; void Line::setLength( double len ) length = len; double Line::getLength( void ) return length; int main( ) Line line; line.setlength(6.0); // set line length cout << "Length of line : " << line.getlength(); return 0; b.) Write the characteristics of constructors (4 marks) It must be declared in the public section Constructor has the same of a class to which it belongs Does not have a return type, not even void Every object of the class containing a constructor is initialized A constructor cannot be inherited although a derived class can call the base class constructor. A constructor can have default arguments. Address of constructor cannot be referred to. A constructor cannot be virtual. An object with a constructor must not be used as a member of a union 3.) a.) Define this pointer. Give example of accessing and returning of object using this pointer (4 marks)
5 Every object in C++ has access to its own address through an important pointer called this pointer. The this pointer is an implicit parameter to all member functions. Therefore, inside a member function, this may be used to refer to the invoking object. This pointer are not modifiable. This pointer is a pointer to the class type. Therefore it can be used to access the data members of the object. Accessing : #include<iostream> class where private: int alpha; void tester() this->alpha=11; //same as alpha=11 cout<<this->alpha; //same as cout<<alpha; int main() where w; w.tester(); return 0; Returning : The expression *this is commonly used to return the current object from a member function as in return *this; The special property of the this pointer is that, it points to the invoking object. When the method requires reference to the invoking object as a whole, it uses the expression *this; However, when you want to return an object this cannot be used since it is the address of the object. Therefore to return the object itself return *this; is used applying deference operator * to a pointer,gives the value to which the pointer is pointing b.) What is Operator Overloading function? Write a program to add two complex numbers using overloading the operator + function (4 marks)
6 Operator overloading function is a special function which provides the relation of an operator to the class it belongs to. Overloaded operators are functions with special names the keyword operator followed by the symbol for the operator being defined. Like any other function, an overloaded operator has a return type and a parameter list. Syntax return-type classname ::operator op (argument list) //statements return-type datatype of the value returned by operator function. Mostly it s the classtype for which it is defined. operator is the keyword op is the operator which is overloaded and operator op is the function name argument list list of arguments to be passed #include <iostream.h> using namespace std class complex float x,y; complex() //constructor 1 complex(float r, float i) // constructor 2 x = r ; y=i ; void display(void); complex operator +(complex); ; complex complex::operator +(complex c) complex temp; temp.x = x+c.x; temp.y = y+c.y; return(temp); void complex :: display(void) cout <<x<< +j <<y<<endl; void main() complex c1, c2, c3; //invoke constructor1 c1 = complex (1.1, 2.1); //invoke constructor2 c2 = complex (3.5, 4.2); //invoke constructor 2 c3 = c1 + c2; //activates operator+( ) function // c3 = c1.operator+(c2) cout << c1.display(); //c1 = j2.1 cout << c2.display(); //c2 = j4.2 cout << c3.display(); //c3 = j6.3 return 0;
7 4.) a.) Explain private, public and protected inheritance of a derived class from base class with an example for each (8 Marks) PUBLIC Inheritance: If a child class is inherited as Public from the base then: A private member of a base class is not accessible by other parts of your program, including any derived class. Protected members behave differently. If the base class is inherited as public, then the base class' protected members become protected members of the derived class and also accessible by the derived class #include <iostream> using namespace std; class base protected: int i, j; // private to base until a child class is created void set(int a, int b) i=a; j=b; void show() cout << i << " " << j ; ; class derived : public base int k; // derived may access base's i and j void setk() k= i * j; void showk() cout << k << "\n"; ; // which can access protected members
8 int main() derived ob; ob.set(2, 3); ob.show(); ob.setk(); ob.showk(); return 0; // OK, known to derived // OK, known to derived Protected Inheritance: If a child class is inherited as Protected from the base then: It is possible to inherit a base class as protected. When this is done, all public and protected members of the base class become protected members of the derived class. #include <iostream> using namespace std; class base protected: int i, j; // private to base until a child class is // created and can access void setij(int a, int b) i=a; j=b; void showij() cout << i << " " << j << "\n"; ; // Inherit base as protected. class derived : protected base int k; // derived may access base's i and j and setij(). void setk() setij(10, 12); k = i*j; // may access showij() here void showall() cout << k << " "; showij(); ; int main()
9 derived ob; // ob.setij(2, 3); // illegal, setij() isprotected member of derived ob.setk(); // OK, public member of derived ob.showall(); // OK, public member of derived // ob.showij(); // illegal, showij() is protected // member of derived return 0; Private Inheritance : When the base class is inherited by using the private access specifier, all public and protected members of the base class become private members of the derived class. But they are still accessible by members of the derived class but cannot be accessed by parts of your program that are not members of either the base or derived class. #include <iostream> using namespace std; class base int i, j; void set(int a, int b) i=a; j=b; void show() cout << i << " " << j << "\n"; ; // Public elements of base are private in derived. class derived : private base int k; derived(int x) k=x; void showk() cout << k << "\n"; ; int main() derived ob(3); ob.set(1, 2); // error, can't access set()
10 ob.show(); // error, can't access show() return 0; 5.) a.) Write a program to overload both prefix and postfix increment operator using operator function and display the output before and after the operation (8 marks) #include<iostream.h> class increment private: int val; increment() val=0; increment(int a) val=a; void operator ++(); void operator ++(int); void show(); ; void increment :: operator ++() ++ val ; void increment :: operator ++(int) val ++; void show () cout<<val; void main() increment d1(5); cout<< Before Incrementing: ; d1.show(); cout<< after overloading prefix++ : ; ++d1; d1.show(); d1++; cout<< After overloading postfix++ : ; d1.show();
11 Output : Before Incrementing: 5 After overloading prefix++ : 6 After overloading postfix++ : 7 6.) a.) What are the types of constructors and explain each with an example (8 marks) Default Constructor Default constructor is the constructor which doesn't take any argument. It has no parameter. Syntax classs class_name () Constructor Definition ; Ex: class Cube int side; Cube() side=10; ; int main() Cube c; cout << c.side; Parametrized Constructor These are the constructors with parameter. Using this Constructor you can provide different values to data members of different objects, by passing the appropriate values as argument. Ex: class Cube int side; Cube(int x) side=x; ; int main() Cube c1(10); Cube c2(20); Cube c3(30); cout << c1.side;
12 cout << c2.side; cout << c3.side; Copy Constructor The copy constructor is a constructor which creates an object by initializing it with an object of the same class, which has been created previously. The copy constructor is used to: Initialize one object from another of the same type. Copy an object to pass it as an argument to a function. Copy an object to return it from a function. Ex: class sample private: int m,n; sample() // sample s0; // default constructor sample (int a, int b) // sample s1(100,200); // initializes s1 using constructor1 m=a; n=b; sample() // sample s2; // initializes s0 as a default constructor m=0; n=0; // with initializing the members to zero sample(sample &s1) m=s1.m; n=s1.n; // sample s3(s1); // copy constructor, copies s1 to s3 sample s4= s3; // copy constructor,copies s3 to s4 s3=s1;// does not invoke copy constructor Multiple Constructor (overloading constructor) Class containing more than one constructor All constructor defined with the same name as the class they belong to. All constructors contain different number of arguments. Depending upon the number of arguments, the compiler executes appropriate constructor. Ex: class num private: int a; float b; char c; num (int m, float j, char k);
13 num (int m, float j); num ( ); ; main() class num x (2, 1.2); class num y (2, 1.1, S ); class num z; Dynamic Constructor Dynamic constructor is used to allocate the memory to the objects at the run time. Memory is allocated at run time with the help of 'new' operator. By using this constructor, we can dynamically initialize the objects. #include <iostream.h> #include <conio.h> class dyncons int * p; dyncons() p=new int; *p=10; dyncons(int v) p=new int; *p=v; int dis() return(*p); ; void main() clrscr(); dyncons o, o1(9); cout<<"the value of object o's p is:"; cout<<o.dis(); cout<<"\nthe value of object 01's p is:"<<o1.dis(); getch(); Output: The value of object o's p is:10 The value of object 01's p is:9
14 7.) a.) What are the rules followed for operator overloading if the function is declared as member function and as friend function for unary and binary operators (8 marks) a.) If a friend function : For Unary operator : only 1 argument Syntax :- object_name op or op object_name => Interpreted as operator op (object_name) Binary operator (syntax) : 2 arguments Syntax :- obj_1 op obj_2 => Interpreted as operator op (obj_1,obj_2) b.) If member function : (As object is passed implicitly and easily available) For unary operator : No arguments For binary operator : Only 1 argument => Interpreted as x.operator op (y) 8.) a.) Explain the difference between Virtual function and Pure Virtual function with example (6 marks) Pure Virtual function: A pure virtual function is one with the expression =0 added to the declaration. Derived class must either define function or redeclare it as pure virtual functions again The syntax =0 tells the compiler that a virtual function will be pure. No definition is needed for base class show() only declaration is enough In main() if u attempt to create objects of class base, the compiler will complain that you are trying to initiate an object of an abstract class After placing pure virtual function, in base class you must override it in all the derived classes If a class doesn t override the pure virtual function, it will remain as a pure virtual function in an abstract class can t initiate objects from it in the main(). #include <iostream> using namespace std class base virtual void show()=0; // pure virtual fun ; class derv1:public base void show() cout<< derv1 ; ; class derv2:public base void show() cout<< derv2 ; ; int main()
15 //base bad // can t make objects from abstract class base* arr[2]; //arrays of pointers to base class derv1 dv1; // objects of derived class1 derv2 dv2; // objects of derived class2 arr[0]=&dv1; //put address of dv1 in array arr[1]=&dv2; // put address of dv2 in array arr[0] -> show(); arr[1] -> show(); return 0; OUTPUT: derv1 derv2 Virtual function : A virtual function is a member function that is declared within a base class and redefined by a derived class. To create a virtual function, precede the function's declaration in the base class with the keyword virtual. They can also be empty functions i.e only declared. If the function had not been declared virtual, then the base class function would have been called all the times. Because, the function address would have been statically bound during compile time. But now, as the function is declared virtual it is a candidate for run-time linking and the derived class function is being invoked. Choosing of the function is done at run-time based on the type of object pointed by the base pointer. #include<iostream.h> #include<conio.h> class base virtual void show() cout<<"\n Base class show:"; void display() cout<<"\n Base class display:" ; ; class derived : public base void display() cout<<"\n Derived class display:"; void show() cout<<"\n Derived class show:"; ;
16 void main() clrscr(); base obj1; base *p; cout<<"\n\t P points to base:\n" ; p=&obj1; p->display(); p->show(); cout<<"\n\t P points to derived:\n"; derived obj2; p=&obj2; p->display(); p->show(); getch(); Output: P points to Base Base class display Base class show P points to derived Base class Display Derived class Show b.) Write the methods to access the data member or member function using pointer to objects (2 marks) Any type that can be used to declare a variable/object can also have a pointer type. Useful in creating objects at run time. Object pointers helps in accessing the public members of an object. Consider the following class: class Rational private: int numerator; int denominator; Rational(int n, int d); void Display(); ; Rational *rp = NULL; Rational r(3,4); rp = &r; r.display() // same as rp->display() // same as (*rp).display() If rp is a pointer to an object, then two notations can be used to reference the instance/object rp points to.
17 Using the de-referencing operator * (*rp).display(); Using the member access operator -> rp -> Display(); 9.) a.) Write a program to add two integer numbers. Use numbers as base class, readnums, printnums and caladdn as derived class and incorporate inheritance (8 marks) #include <iostream> using namespace std; //class definition class Numbers private: int a; int b; //member function declaration void readnumbers(void); void printnumbers(void); int caladdition(void); ; //member function definitions void Numbers::readNumbers(void) cout<<"enter first number: "; cin>>a; cout<<"enter second number: "; cin>>b; void Numbers::printNumbers(void) cout<<"a= "<<a<<",b= "<<b<<endl; int Numbers::calAddition(void) return (a+b); //main function int main() //declaring object
18 Numbers num; int add; //variable to store addition //take input num.readnumbers(); //find addition add=num.caladdition(); //print numbers num.printnumbers(); //print addition cout<<"addition/sum= "<<add<<endl; return 0; Output Enter first number: 100 Enter second number: 200 a= 100,b= 200 Addition/sum= ) a.) Write a program to get a square and cube of a number using hierarchical inheritance (8 marks) /*C++ program to demonstrate example of hierarchical inheritance to get */ /* square and cube of a number.*/ #include <iostream> using namespace std; class Number private: int num; void getnumber(void) ; cout << "Enter an integer number: "; cin >> num; //to return num int returnnumber(void) return num; //Base Class 1, to calculate square of a number class Square:public Number int getsquare(void)
19 ; int num,sqr; num=returnnumber(); //get number from class Number sqr=num*num; return sqr; //Base Class 2, to calculate cube of a number class Cube:public Number private: int getcube(void) int num,cube; num=returnnumber(); //get number from class Number cube=num*num*num; return cube; ; int main() Square objs; Cube objc; int sqr,cube; objs.getnumber(); sqr =objs.getsquare(); cout << "Square of "<< objs.returnnumber() << " is: " << sqr << endl; objc.getnumber(); cube=objc.getcube(); cout << "Cube of "<< objs.returnnumber() << " is: " << cube << endl; return 0; Enter an integer number: 10 Square of 10 is: 100 Enter an integer number: 20 Cube of 10 is: 8000
mywbut.com Inheritance
Inheritance 1 Inheritance is one of the cornerstones of OOP because it allows the creation of hierarchical classifications. Using inheritance, you can create a general class that defines traits common
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 informationDHANALAKSHMI COLLEGE OF ENGINEERING, CHENNAI DEPARTMENT OF COMPUTER SCIENCE AND ENGINEERING REWRAP TEST I CS6301 PROGRAMMING DATA STRUCTURES II
DHANALAKSHMI COLLEGE OF ENGINEERING, CHENNAI DEPARTMENT OF COMPUTER SCIENCE AND ENGINEERING REWRAP TEST I CS6301 PROGRAMMING DATA STRUCTURES II Year / Semester: III / V Date: 08.7.17 Duration: 45 Mins
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 informationOBJECT ORIENTED PROGRAMMING USING C++ CSCI Object Oriented Analysis and Design By Manali Torpe
OBJECT ORIENTED PROGRAMMING USING C++ CSCI 5448- Object Oriented Analysis and Design By Manali Torpe Fundamentals of OOP Class Object Encapsulation Abstraction Inheritance Polymorphism Reusability C++
More informationOBJECT ORIENTED PROGRAMMING. Ms. Ajeta Nandal C.R.Polytechnic,Rohtak
OBJECT ORIENTED PROGRAMMING Ms. Ajeta Nandal C.R.Polytechnic,Rohtak OBJECT ORIENTED PARADIGM Object 2 Object 1 Data Data Function Function Object 3 Data Function 2 WHAT IS A MODEL? A model is an abstraction
More informationModule Operator Overloading and Type Conversion. Table of Contents
1 Module - 33 Operator Overloading and Type Conversion Table of Contents 1. Introduction 2. Operator Overloading 3. this pointer 4. Overloading Unary Operators 5. Overloading Binary Operators 6. Overloading
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 informationC++ 8. Constructors and Destructors
8. Constructors and Destructors C++ 1. When an instance of a class comes into scope, the function that executed is. a) Destructors b) Constructors c) Inline d) Friend 2. When a class object goes out of
More informationRecharge (int, int, int); //constructor declared void disply();
Constructor and destructors in C++ Constructor Constructor is a special member function of the class which is invoked automatically when new object is created. The purpose of constructor is to initialize
More information3.Constructors and Destructors. Develop cpp program to implement constructor and destructor.
3.Constructors and Destructors Develop cpp program to implement constructor and destructor. Constructors A constructor is a special member function whose task is to initialize the objects of its class.
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 informationpublic : int min, hour ; T( ) //here constructor is defined inside the class definition, as line function. { sec = min = hour = 0 ; }
. CONSTRUCTOR If the name of the member function of a class and the name of class are same, then the member function is called constructor. Constructors are used to initialize the object of that class
More informationDownloaded from
Unit I Chapter -1 PROGRAMMING IN C++ Review: C++ covered in C++ Q1. What are the limitations of Procedural Programming? Ans. Limitation of Procedural Programming Paradigm 1. Emphasis on algorithm rather
More informationData Structures using OOP C++ Lecture 3
References: th 1. E Balagurusamy, Object Oriented Programming with C++, 4 edition, McGraw-Hill 2008. 2. Robert L. Kruse and Alexander J. Ryba, Data Structures and Program Design in C++, Prentice-Hall 2000.
More informationOBJECT ORIENTED PROGRAMMING AND DATA STRUCTURES
Polymorphism: It allows a single name/operator to be associated with different operations depending on the type of data passed to it. An operation may exhibit different behaviors in different instances.
More informationUNIT POLYMORPHISM
UNIT 3 ---- POLYMORPHISM CONTENTS 3.1. ADT Conversions 3.2. Overloading 3.3. Overloading Operators 3.4. Unary Operator Overloading 3.5. Binary Operator Overloading 3.6. Function Selection 3.7. Pointer
More informationTHE NAME OF THE CONSTRUCTOR AND DESTRUCTOR(HAVING (~) BEFORE ITS NAME) FUNCTION MUST BE SAME AS THE NAME OF THE CLASS IN WHICH THEY ARE DECLARED.
Constructor and Destructor Member Functions Constructor: - Constructor function gets invoked automatically when an object of a class is constructed (declared). Destructor:- A destructor is a automatically
More informationCHAPTER 4 FUNCTIONS. 4.1 Introduction
CHAPTER 4 FUNCTIONS 4.1 Introduction Functions are the building blocks of C++ programs. Functions are also the executable segments in a program. The starting point for the execution of a program is main
More informationUnit III Virtual Functions. Developed By Ms. K.M.Sanghavi
Unit III Virtual Functions Developed By Ms. K.M.Sanghavi Topics Pointers- indirection Operators Memory Management: new and delete : Slide 23-24 / (Covered In Unit I Too) Accessing Arrays using pointers
More informationDarshan Institute of Engineering & Technology for Diploma Studies
1. Explain Call by Value vs. Call by Reference Or Write a program to interchange (swap) value of two variables. Call By Value In call by value pass value, when we call the function. And copy this value
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 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 informationCONSTRUCTORS AND DESTRUCTORS
UNIT-II CONSTRUCTORS AND DESTRUCTORS Contents: Constructors Default constructors Parameterized constructors Constructor with dynamic allocation Copy constructor Destructors Operator overloading Overloading
More informationObject-Oriented Programming (OOP) Fundamental Principles of OOP
Object-Oriented Programming (OOP) O b j e c t O r i e n t e d P r o g r a m m i n g 1 Object-oriented programming is the successor of procedural programming. The problem with procedural programming is
More informationOOP THROUGH C++(R16) int *x; float *f; char *c;
What is pointer and how to declare it? Write the features of pointers? A pointer is a memory variable that stores the address of another variable. Pointer can have any name that is legal for other variables,
More informationMAHALAKSHMI ENGINEERING COLLEGE B TIRUCHIRAPALLI
MAHALAKSHMI ENGINEERING COLLEGE B TIRUCHIRAPALLI 621213 DEPARTMENT OF COMPUTER SCIENCE AND ENGINEERING Sub code: CS2203 SEM: III Sub Name: Object Oriented Programming Year: II UNIT-I PART-A 1. What is
More informationKOM3191 Object Oriented Programming Dr Muharrem Mercimek OPERATOR OVERLOADING. KOM3191 Object-Oriented Programming
KOM3191 Object Oriented Programming Dr Muharrem Mercimek 1 OPERATOR OVERLOADING KOM3191 Object-Oriented Programming KOM3191 Object Oriented Programming Dr Muharrem Mercimek 2 Dynamic Memory Management
More informationDE122/DC106 Object Oriented Programming with C++ DEC 2014
Q.2 a. Distinguish between Procedure-oriented programming and Object- Oriented Programming. Procedure-oriented Programming basically consists of writing a list of instructions for the computer to follow
More informationSome important concept in oops are 1) Classes 2) Objects 3) Data abstraction & Encapsulation. 4) Inheritance 5) Dynamic binding. 6) Message passing
Classes and Objects Some important concept in oops are 1) Classes 2) Objects 3) Data abstraction & Encapsulation. 4) Inheritance 5) Dynamic binding. 6) Message passing Classes i)theentiresetofdataandcodeofanobjectcanbemadeauserdefineddatatypewiththehelpofaclass.
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 informationOverloading operators
Overloading functions Overloading operators In C++ we can have several functions in one program with the same name. The compiler decides which function has to be called depending on the number and type
More informationChapter-11 POINTERS. Important 3 Marks. Introduction: Memory Utilization of Pointer: Pointer:
Chapter-11 POINTERS Introduction: Pointers are a powerful concept in C++ and have the following advantages. i. It is possible to write efficient programs. ii. Memory is utilized properly. iii. Dynamically
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 informationSRM ARTS AND SCIENCE COLLEGE SRM NAGAR, KATTANKULATHUR
SRM ARTS AND SCIENCE COLLEGE SRM NAGAR, KATTANKULATHUR 603203 DEPARTMENT OF COMPUTER SCIENCE & APPLICATIONS QUESTION BANK (2017-2018) Course / Branch : M.Sc CST Semester / Year : EVEN / II Subject Name
More informationKapil Sehgal PGT Computer. Science Ankleshwar Gujarat
Classes Chapter 4 Classes and Objects Data Hiding and Encapsulation Function in a Class Using Objects Static Class members Classes Class represents a group of Similar objects A class is a way to bind the
More informationReference Parameters A reference parameter is an alias for its corresponding argument in the function call. Use the ampersand (&) to indicate that
Reference Parameters There are two ways to pass arguments to functions: pass-by-value and pass-by-reference. pass-by-value A copy of the argument s value is made and passed to the called function. Changes
More informationPointers and Dynamic Memory Allocation
Pointers and Dynamic Memory Allocation ALGORITHMS & DATA STRUCTURES 9 TH SEPTEMBER 2014 Last week Introduction This is not a course about programming: It s is about puzzling. well.. Donald Knuth Science
More informationIntroduction Of Classes ( OOPS )
Introduction Of Classes ( OOPS ) Classes (I) A class is an expanded concept of a data structure: instead of holding only data, it can hold both data and functions. An object is an instantiation of a class.
More informationObject Oriented Programming. Solved MCQs - Part 2
Object Oriented Programming Solved MCQs - Part 2 Object Oriented Programming Solved MCQs - Part 2 It is possible to declare as a friend A member function A global function A class All of the above What
More informationObject Oriented Programming
F.Y. B.Sc.(IT) : Sem. II Object Oriented Programming Time : 2½ Hrs.] Prelim Question Paper Solution [Marks : 75 Q.1 Attempt the following (any THREE) [15] Q.1(a) Explain encapsulation? [5] (A) The wrapping
More informationPESIT Bangalore South Campus Hosur road, 1km before Electronic City, Bengaluru -100 Department of Electronics and Communication
USN 1 P E PESIT Bangalore South Campus Hosur road, 1km before Electronic City, Bengaluru -0 Department of Electronics and Communication INTERNAL ASSESSMENT TEST 1 Date : 30/8/2017 Marks: 0 Subject & Code
More informationOperator overloading: extra examples
Operator overloading: extra examples CS319: Scientific Computing (with C++) Niall Madden Week 8: some extra examples, to supplement what was covered in class 1 Eg 1: Points in the (x, y)-plane Overloading
More informationDepartment of Computer science and Engineering Sub. Name: Object oriented programming and data structures Sub. Code: EC6301 Sem/Class: III/II-ECE Staff name: M.Kavipriya Two Mark Questions UNIT-1 1. List
More informationcout<< \n Enter values for a and b... ; cin>>a>>b;
CHAPTER 8 CONSTRUCTORS AND DESTRUCTORS 8.1 Introduction When an instance of a class comes into scope, a special function called the constructor gets executed. The constructor function initializes the class
More informationNote 12/1/ Review of Inheritance Practice: Please write down 10 most important facts you know about inheritance...
CISC 2000 Computer Science II Fall, 2014 Note 12/1/2014 1 Review of Inheritance Practice: Please write down 10 most important facts you know about inheritance... (a) What s the purpose of inheritance?
More informationInstantiation of Template class
Class Templates Templates are like advanced macros. They are useful for building new classes that depend on already existing user defined classes or built-in types. Example: stack of int or stack of double
More informationPOLYMORPHISM 2 PART. Shared Interface. Discussions. Abstract Base Classes. Abstract Base Classes and Pure Virtual Methods EXAMPLE
Abstract Base Classes POLYMORPHISM 2 PART Abstract Classes Static and Dynamic Casting Common Programming Errors class B { // base class virtual void m( ) =0; // pure virtual function class D1 : public
More informationPOLYMORPHISM 2 PART Abstract Classes Static and Dynamic Casting Common Programming Errors
POLYMORPHISM 2 PART Abstract Classes Static and Dynamic Casting Common Programming Errors CSC 330 OO Software Design 1 Abstract Base Classes class B { // base class virtual void m( ) =0; // pure virtual
More informationPESIT Bangalore South Campus Hosur road, 1km before Electronic City, Bengaluru -100 Department of Electronics and Communication
USN 1 P E PESIT Bangalore South Campus Hosur road, 1km before Electronic City, Bengaluru -0 Department of Electronics and Communication INTERNAL ASSESSMENT TEST 2 Date : 4//2017 Marks: 50 Subject & Code
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 informationPOINTERS - Pointer is a variable that holds a memory address of another variable of same type. - It supports dynamic allocation routines. - It can improve the efficiency of certain routines. C++ Memory
More informationDeveloped By Strawberry
Experiment No. 9 PART A (PART A: TO BE REFFERED BY STUDENTS) A.1 Aim: To study virtual functions and Polymorphism P1: Create a base class called 'SHAPE' having - two data members of type double - member
More informationOverloading Operators in C++
Overloading Operators in C++ C++ allows the programmer to redefine the function of most built-in operators on a class-by-class basis the operator keyword is used to declare a function that specifies what
More informationOperator overloading
1 Introduction 2 The copy constructor 3 Operator Overloading 4 Eg 1: Adding two vectors 5 The -> operator 6 The this pointer 7 Overloading = 8 Unary operators 9 Overloading for the matrix class 10 The
More informationIII. Classes (Chap. 3)
III. Classes III-1 III. Classes (Chap. 3) As we have seen, C++ data types can be classified as: Fundamental (or simple or scalar): A data object of one of these types is a single object. int, double, char,
More informationCS35 - Object Oriented Programming
Syllabus CS 35 OBJECT-ORIENTED PROGRAMMING 3 0 0 3 (Common to CSE & IT) Aim: To understand the concepts of object-oriented programming and master OOP using C++. UNIT I 9 Object oriented programming concepts
More informationOOP. Unit:3.3 Inheritance
Unit:3.3 Inheritance Inheritance is like a child inheriting the features of its parents. It is a technique of organizing information in a hierarchical (tree) form. Inheritance allows new classes to be
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 informationBangalore South Campus
INTERNAL ASSESSMENT TEST 1(Solutions) Date :01/03/2017 Max Marks: 40 Subject& Code: Object Oriented Concepts (15CS45) Sem:VII ISE Name of the faculty: Miss Pragyaa Time: 90 minutes Note: Answer to all
More informationIntroduction to C++ Systems Programming
Introduction to C++ Systems Programming Introduction to C++ Syntax differences between C and C++ A Simple C++ Example C++ Input/Output C++ Libraries C++ Header Files Another Simple C++ Example Inline Functions
More informationMAHARASHTRA STATE BOARD OF TECHNICAL EDUCATION (Autonomous) (ISO/IEC Certified) Subject Name: Object Oriented Programming
Important Instructions to examiners: 1) The answers should be examined by key words and not as word-to-word as given in themodel answer scheme. 2) The model answer and the answer written by candidate may
More informationDELHI PUBLIC SCHOOL TAPI
Loops Chapter-1 There may be a situation, when you need to execute a block of code several number of times. In general, statements are executed sequentially: The first statement in a function is executed
More informationW3101: Programming Languages C++ Ramana Isukapalli
Lecture-6 Operator overloading Namespaces Standard template library vector List Map Set Casting in C++ Operator Overloading Operator overloading On two objects of the same class, can we perform typical
More informationWelcome Back. CSCI 262 Data Structures. Hello, Let s Review. Hello, Let s Review. How to Review 8/19/ Review. Here s a simple C++ program:
Welcome Back CSCI 262 Data Structures 2 - Review What you learned in CSCI 261 (or equivalent): Variables Types Arrays Expressions Conditionals Branches & Loops Functions Recursion Classes & Objects Streams
More informationCS201 - Introduction to Programming Glossary By
CS201 - Introduction to Programming Glossary By #include : The #include directive instructs the preprocessor to read and include a file into a source code file. The file name is typically enclosed with
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 informationExample : class Student { int rollno; float marks; public: student( ) //Constructor { rollno=0; marks=0.0; } //other public members };
Constructors A Member function with the same name as its classis called Constructor and it is used to initilize the objects of that class type with a legal value. A Constructor is a special member function
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 informationConstructors and Destructors. OOC 4 th Sem, B Div Prof. Mouna M. Naravani
Constructors and Destructors OOC 4 th Sem, B Div 2016-17 Prof. Mouna M. Naravani A constructor guarantees that an object created by the class will be initialized automatically. Ex: create an object integer
More informationPage. No. 1/15 CS201 Introduction to Programmming Solved Subjective Questions From spring 2010 Final Term Papers By vuzs Team
Page. No. 1/15 CS201 Introduction to Programmming Solved Subjective Questions From spring 2010 Final Term Papers By vuzs Team Question No: 1 ( Marks: 2 ) Write a declaration statement for an array of 10
More informationProgramming in C++: Assignment Week 4
Programming in C++: Assignment Week 4 Total Marks : 20 March 22, 2017 Question 1 Using friend operator function, which set of operators can be overloaded? Mark 1 a.,, , ==, = b. +, -, /, * c. =,
More information2. Distinguish between a unary, a binary and a ternary operator. Give examples of C++ operators for each one of them.
1. Why do you think C++ was not named ++C? C++ is a super set of language C. All the basic features of C are used in C++ in their original form C++ can be described as C+ some additional features. Therefore,
More informationThe Address-of Operator &: The & operator can find address occupied by a variable. If var is a variable then, &vargives the address of that variable.
VIRTUAL FUNCITONS Pointers: Some C++ tasks are performed more easily with pointers, and other C++ tasks, such as dynamic memory allocation, cannot be performed without them. As you know every variable
More informationInterview Questions of C++
Interview Questions of C++ Q-1 What is the full form of OOPS? Ans: Object Oriented Programming System. Q-2 What is a class? Ans: Class is a blue print which reflects the entities attributes and actions.
More informationData Structures using OOP C++ Lecture 6
Inheritance Inheritance is the process of creating new classes, called derived classes, from existing or base classes. The derived class inherits all the capabilities of the base class but can add embellishments
More informationCS304 Object Oriented Programming
1 CS304 Object Oriented Programming 1. Which of the following is the way to extract common behaviour and attributes from the given classes and make a separate class of those common behaviours and attributes?
More informationShort Notes of CS201
#includes: Short Notes of CS201 The #include directive instructs the preprocessor to read and include a file into a source code file. The file name is typically enclosed with < and > if the file is a system
More informationINTRODUCTION TO PROGRAMMING
FIRST SEMESTER INTRODUCTION TO PROGRAMMING COMPUTER SIMULATION LAB DEPARTMENT OF ELECTRICAL ENGINEERING Prepared By: Checked By: Approved By Engr. Najeeb Saif Engr. M.Nasim Kha Dr.Noman Jafri Lecturer
More informationUNIT III- INHERITANCE AND POLYMORPHISM
UNIT III- INHERITANCE AND POLYMORPHISM Objectives: To introduce Inheritance in C++ and to explain its importance. To make understand the different types of inheritance. To define typing conversion and
More informationAN OVERVIEW OF C++ 1
AN OVERVIEW OF C++ 1 OBJECTIVES Introduction What is object-oriented programming? Two versions of C++ C++ console I/O C++ comments Classes: A first look Some differences between C and C++ Introducing function
More informationObject oriented programming
Exercises 12 Version 1.0, 9 May, 2017 Table of Contents 1. Virtual destructor and example problems...................................... 1 1.1. Virtual destructor.......................................................
More informationExercise1. // classes first example. #include <iostream> using namespace std; class Rectangle. int width, height; public: void set_values (int,int);
Exercise1 // classes first example class Rectangle int width, height; void set_values (int,int); int area() return width*height; ; void Rectangle::set_values (int x, int y) width = x; height = y; int main
More information+2 Volume II OBJECT TECHNOLOGY OBJECTIVE QUESTIONS R.Sreenivasan SanThome HSS, Chennai-4. Chapter -1
Chapter -1 1. Object Oriented programming is a way of problem solving by combining data and operation 2.The group of data and operation are termed as object. 3.An object is a group of related function
More informationAdvanced Systems Programming
Advanced Systems Programming Introduction to C++ Martin Küttler September 19, 2017 1 / 18 About this presentation This presentation is not about learning programming or every C++ feature. It is a short
More informationProgramming in C++: Assignment Week 4
Programming in C++: Assignment Week 4 Total Marks : 20 August 12, 2017 Question 1 Which of the following operators can use friend functions for overloading? Mark 1 a. == b. [ ] c. -> d. ( ) Answer: a As
More informationBasic memory model Using functions Writing functions. Basics Prototypes Parameters Return types Functions and memory Names and namespaces
Basic memory model Using functions Writing functions Basics Prototypes Parameters Return types Functions and memory Names and namespaces When a program runs it requires main memory (RAM) space for Program
More information- HALF YEARLY EXAM ANSWER KEY DEC-2016 COMPUTER SCIENCE ENGLISH MEDIUM
www.padasalai.net - HALF YEARLY EXAM ANSWER KEY DEC-2016 COMPUTER SCIENCE ENGLISH MEDIUM 1 A 26 D 51 C 2 C 27 D 52 D 3 C 28 C 53 B 4 A 29 B 54 D 5 B 30 B 55 B 6 A 31 C 56 A 7 B 32 C 57 D 8 C 33 B 58 C
More informationChapter 10 Introduction to Classes
C++ for Engineers and Scientists Third Edition Chapter 10 Introduction to Classes CSc 10200! Introduction to Computing Lecture 20-21 Edgardo Molina Fall 2013 City College of New York 2 Objectives In this
More informationSTRUCTURING OF PROGRAM
Unit III MULTIPLE CHOICE QUESTIONS 1. Which of the following is the functionality of Data Abstraction? (a) Reduce Complexity (c) Parallelism Unit III 3.1 (b) Binds together code and data (d) None of the
More informationFunction Overloading
Function Overloading C++ supports writing more than one function with the same name but different argument lists How does the compiler know which one the programmer is calling? They have different signatures
More informationC++ Important Questions with Answers
1. Name the operators that cannot be overloaded. sizeof,.,.*,.->, ::,? 2. What is inheritance? Inheritance is property such that a parent (or super) class passes the characteristics of itself to children
More informationCS304 Object Oriented Programming Final Term
1. Which of the following is the way to extract common behaviour and attributes from the given classes and make a separate class of those common behaviours and attributes? Generalization (pg 29) Sub-typing
More informationPESIT Bangalore South Campus Hosur road, 1km before Electronic City, Bengaluru -100 Department of MCA
INTERNAL ASSESSMENT Scheme and Solution -T2 Date : 30/3/2015 Max Marks : 50 Subject & Code : Object Oriented Programming with C++(13MCA22 ) Name of faculty : R.Jayanthi Time : 11.30 am -1.00 Pm Answer
More informationEL2310 Scientific Programming
(pronobis@kth.se) Overview Overview Wrap Up Introduction to Object Oriented Paradigm More on and Members Operator Overloading Last time Intro to C++ Differences between C and C++ Intro to OOP Today Object
More informationFORM 1 (Please put your name and section number (001/10am or 002/2pm) on the scantron!!!!) CS 161 Exam II: True (A)/False(B) (2 pts each):
FORM 1 (Please put your name and section number (001/10am or 002/2pm) on the scantron!!!!) CS 161 Exam II: True (A)/False(B) (2 pts each): 1. If a function has default arguments, they can be located anywhere
More informationObject Oriented Programming
Object Oriented Programming in C++ CHAPTER 01 Introduction to OOP & C++ Difference between Procedure Oriented and Object Oriented Programming Procedure Oriented Programming Object Oriented Programming
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 informationObjectives. Chapter 2: Basic Elements of C++ Introduction. Objectives (cont d.) A C++ Program (cont d.) A C++ Program
Objectives Chapter 2: Basic Elements of C++ In this chapter, you will: Become familiar with functions, special symbols, and identifiers in C++ Explore simple data types Discover how a program evaluates
More informationChapter 2: Basic Elements of C++
Chapter 2: Basic Elements of C++ Objectives In this chapter, you will: Become familiar with functions, special symbols, and identifiers in C++ Explore simple data types Discover how a program evaluates
More information