S.E Computer (First Semester) Examination 2016 OBJECT ORIENTED PROGRAMMING (2015 Pattern) Nov / Dec 2016 Time : 2 Hours Maximum Marks : 50

Size: px
Start display at page:

Download "S.E Computer (First Semester) Examination 2016 OBJECT ORIENTED PROGRAMMING (2015 Pattern) Nov / Dec 2016 Time : 2 Hours Maximum Marks : 50"

Transcription

1 S.E Computer (First Semester) Examination 2016 OBJECT ORIENTED PROGRAMMING (2015 Pattern) Nov / Dec 2016 Time : 2 Hours Maximum Marks : 50 Q.1 a) Difference Between Procedure Oriented Programming (POP) & Object Oriented Programming (OOP) 4M Divided Into Importance Procedure Oriented Programming In POP, program is divided into small parts called functions. In POP,Importance is not given to data but to functions as well as sequence of actions to be done. Object Oriented Programming In OOP, program is divided into parts called objects. In OOP, Importance is given to the data rather than procedures or functions because it works as a real world. Approach POP follows Top Down approach. OOP follows Bottom Up approach. Access Specifiers Data Moving Expansion Data Access Data Hiding POP does not have any access specifier. In POP, Data can move freely from function to function in the system. To add new data and function in POP is not so easy. In POP, Most function uses Global data for sharing that can be accessed freely from function to function in the system. POP does not have any proper way for hiding data so it is less secure. Overloading In POP, Overloading is not possible. Examples Example of POP are : C, VB, FORTRAN, Pascal. OOP has access specifiers named Public, Private, Protected, etc. In OOP, objects can move and communicate with each other through member functions. OOP provides an easy way to add new data and function. In OOP, data can not move easily from function to function,it can be kept public or private so we can control the access of data. OOP provides Data Hiding so provides more security. In OOP, overloading is possible in the form of Function Overloading and Operator Overloading. Example of OOP are : C++, JAVA, VB.NET, C#.NET. Q.1 b) What is friend function? 2M Ans. A friend function of a class is defined outside that class' scope but it has the right to access all private and protected members of the class. Even though the prototypes for friend functions appear in the class definition, friends are not member functions.

2 To declare a function as a friend of a class, precede the function prototype in the class definition with keyword friend as follows: class Box double width; double length; friend void printwidth( Box box ); void setwidth( double wid ); ; Q.1 c) Define class number which has inline function mult() and cube( ) for calculating the multiplication of two double numbers given and cube of the integer number given? 4M Ans c) #include<iostream.h> #include<conio.h> class number inline float mul(double x,double y) return(x*y); inline float cube(int x) return(x*x*x); ; void main() number obj; double val1,val2; int val3; clrscr(); cout<<"enter two double values and one integer value:"; cin>>val1>>val2>>val3; cout<<"\multiplication value is:"<<obj.mul(val1,val2);

3 cout<<"\n\ncube value is :"<<obj.cube(val3); getch(); Output: Enter two values: Multiplication Value is: Cube Value is : 64 Q.1 d) What is use of this pointer? 2M Ans. i. The this pointer is passed as a hidden argument to all nonstatic member function calls and is available as a local variable within the body of all nonstatic functions. ii. this pointer is a constant pointer that holds the memory address of the current object. Use : 1) When local variable s name is same as member s name class Test private: int x; void setx (int x) // The 'this' pointer is used to retrieve the object's x hidden by the local //variable 'x' this->x = x; void print() cout << "x = " << x << endl; ; 2) To return reference to the calling object Test& Test::func () // Some processing return *this; Or

4 Q.2 a) Discuss the various ways in which inheritance promotes software reuse, saves time during program development and helps prevent errors. [4] 1) Inheritance allows developers to create subclasses that reuse code declared already in a superclass. 2) Avoiding the duplication of common functionality between several classes by building a class inheritance hierarchy can save developers a considerable amount of time. 3) Similarly, placing common functionality in a single superclass, rather than duplicating the code in multiple unrelated classes, helps prevent the same errors from appearing in multiple source-code files. If errors occur in the common functionality of the superclass, the software developer needs to modify only the superclass s. Q.2 b) Define a class string. use overloaded == operator to compare two strings 5M Ans. #include<conio.h> #include<iostream.h> #include<string.h> class string char *s; void getstring(char *str) strcpy(s,str); void operator==(comp); ; void comp::operator==(comp ob) if(strcmp(s,ob.s)==0) cout<<"\nstrings are Equal"; else cout<<"\nstrings are not Equal"; void main() comp ob, ob1; char *string1, *string2;

5 clrscr(); cout<<"enter First String:"; cin>>string1; ob.getstring(string1); cout<<"\nenter Second String:"; cin>>string2; ob1.getstring(string2); //Call Equality Operator ob==ob1; getch(); Q.2 c) Explain abstract class with an example 3M Ans. Abstract class in C++ programming is a class that contains at least one pure virtual function. (Pure virtual function in C++ is a virtual functions with no implementation). It may also contain non-virtual functions and member variables. Pure virtual functions in abstract class is implemented by its derived classes. Main important point of an abstract class is that we cannot create an object of it, but we create a pointer. And, in this pointer, we assign the object of derived classes. /Abstract base class class AbstractBase virtual void Display() = 0; //Pure Virtual Function declaration ; //Derived class that will inherit the abstract base class // and implement pure virtual function. class Derived:public AbstractBase void Display() cout << "pure virtual function implementation";

6 ; // TEST-Abstract Class int main() AbstractBase *basepointer = new Derived(); basepointer->display(); // OR AbstractBase * bptr; Derived dobj; bptr = &dobj; bptr->display(); //Abstract base class object can't be created. //AbstractBase obj; // Compiler will flash an error. Q.3 a) How smart pointers avoid the problem of memory leak? 4M Ans. 1. Smart pointers are an improved, more reliable way to manage resources such as dynamically allocated memory and file handles. 2. A smart pointer is a "wrapper" that contains a pointer within it but also performs other special actions. This data type causes an internal reference count to be kept for the associated memory object. The count is equal to the total number of pointers that refer to the object. When the count reaches zero, the object is destroyed, and the memory is released. For Eg. #include<iostream> using namespace std; class SmartPtr int *ptr; // Actual pointer // Constructor explicit SmartPtr(int *p = NULL) ptr = p;

7 // Destructor ~SmartPtr() delete(ptr); // Overloading dereferencing operator int &operator *() return *ptr; int *operator ->() //Overloading Access operator return ptr; ; int main() SmartPtr ptr(new int()); *ptr = 20; cout << *ptr; // We don't need to call delete ptr: when the object // ptr goes out of scope, destructor for it is automatically // called and destructor does delete ptr. return 0; Q.3 b) Differentiate compile time and run-time polymorphism? 4M Ans. Compile time Polymorphism In Compile time Polymorphism, call is resolved by the compiler. It is also known as Static binding, Early binding and overloading as well. Overloading is compile time polymorphism where more than one methods share the same name with different parameters or Run time Polymorphism In Run time Polymorphism, call is not resolved by the compiler. It is also known as Dynamic binding, Late binding and overriding as well. Overriding is run time polymorphism having same method with same parameters or signature, but associated in a class & its

8 signature and different return type. subclass. It is achieved by function overloading and operator overloading. It provides fast execution because known early at compile time. Compile time polymorphism is less flexible as all things execute at compile time. It is achieved by virtual functions and pointers. It provides slow execution as compare to early binding because it is known at runtime. Run time polymorphism is more flexible as all things execute at run time. Q.3 c) Explain virtual base class and virtual function with example. 4M Ans Virtual Base Class An ambiguity can arise when several paths exist to a class from the same base class. This means that a child class could have duplicate sets of members inherited from a single base class. C++ solves this issue by introducing a virtual base class. When a class is made virtual, necessary care is taken so that the duplication is avoided regardless of the number of paths that exist to the child class. When two or more objects are derived from a common base class, we can prevent multiple copies of the base class being present in an object derived from those objects by declaring the base class as virtual when it is being inherited. Such a base class is known as virtual base class. This can be achieved by preceding the base class name with the word virtual. Consider the following example : class A int i; ; class B : virtual public A int j; ; class C: virtual public A

9 int k; ; class D: public B, public C int sum; ; int main() D ob; ob.i = 10; //unambiguous since only one copy of i is inherited. ob.j = 20; ob.k = 30; ob.sum = ob.i + ob.j + ob.k; cout << Value of i is : << ob.i<< \n ; cout << Value of j is : << ob.j<< \n ; cout << Value of k is : << ob.k<< \n ; cout << Sum is : << ob.sum << \n ; return 0; Virtual Functions : A virtual function is a member function that is declared within a base class and redefined by a derived class. To create virtual function, precede the function s declaration in the base class with the keyword virtual. When a class containing virtual function is inherited, the derived class redefines the virtual function to suit its own needs. Base class pointer can point to derived class object. In this case, using base class pointer if we call some function which is in both classes, then base class function is invoked. But if we want to invoke derived class function using base class pointer, it can be achieved by defining the function as virtual in base class, this is how virtual functions support runtime polymorphism. Consider the following program code : Class A

10 int a; A() a = 1; virtual void show() cout <<a; ; Class B: public A int b; B() b = 2; virtual void show() cout <<b; ; int main() A *pa; B ob; pa = &ob; pa show(); return 0; - Output is 2 since pa points to object of B and show() is virtual in base class A. Or

11 Q.4 a) Why we need templates in C++? 2M Ans. Templates are a feature of the C++ programming language that allows functions and classes to operate with generic types. This allows a function or class to work on many different data types without being rewritten for each one. Q.4 b) Explain exception handling mechanism in C++ Write a program in C++ to handle divide by zero exception? 6M Ans. An exception is a problem that arises during the execution of a program. A C++ exception is a response to an exceptional circumstance that arises while a program is running, such as an attempt to divide by zero. Exceptions provide a way to transfer control from one part of a program to another. C++ exception handling is built upon three keywords: try, catch, and throw. throw: A program throws an exception when a problem shows up. This is done using a throw keyword. catch: A program catches an exception with an exception handler at the place in a program where you want to handle the problem. The catch keyword indicates the catching of an exception. try: A try block identifies a block of code for which particular exceptions will be activated. It's followed by one or more catch blocks. Assuming a block will raise an exception, a method catches an exception using a combination of the try and catch keywords. A try/catch block is placed around the code that might generate an exception. Code within a try/catch block is referred to as protected code, and the syntax for using try/catch looks like the following: try // protected code catch( ExceptionName e1 ) // catch block catch( ExceptionName e2 ) // catch block catch( ExceptionName en ) // catch block

12 Multiple catch statements can be used to catch different type of exceptions in case the try block raises more than one exception in different situations. Program : void main() int no1, no2; try cout << Enter two nos: ; cin >> no1 >> no2; if (no2 == 0) throw Divide by zero ; else throw no1/no2; catch (char *s) cout << s; catch (int ans) cout << ans; - We know that divide by zero is an exception. If user enters second no as zero, the program throws an exception, which is caught and an error message is printed else the answer is printed. Q.4 c) Explain class template and function template with an example? 4M Ans 1. Templates are the foundation of generic programming, which involves writing code in a way that is independent of any particular type. 2. A template is a blueprint or formula for creating a generic class or a function. unction Template The general form of a template function definition is shown here: template <class type> ret-type func-name(parameter list)

13 // body of function Here, type is a placeholder name for a data type used by the function. This name can be used within the function definition. The following is the example of a function template that returns the maximum of two values: #include <iostream> #include <string> using namespace std; template <typename T> inline T const& Max (T const& a, T const& b) return a < b? b:a; int main () int i = 39; int j = 20; cout << "Max(i, j): " << Max(i, j) << endl; double f1 = 13.5; double f2 = 20.7; cout << "Max(f1, f2): " << Max(f1, f2) << endl; string s1 = "Hello"; string s2 = "World"; cout << "Max(s1, s2): " << Max(s1, s2) << endl; return 0; If we compile and run above code, this would produce the following result: Max(i, j): 39 Max(f1, f2): 20.7

14 Max(s1, s2): World Class Template Just as we can define function templates, we can also define class templates. The general form of a generic class declaration is shown here: template <class type> class class-name... Here, type is the placeholder type name, which will be specified when a class is instantiated. You can define more than one generic data type by using a comma-separated list. Following is the example to define class Stack<> and implement generic methods to push and pop the elements from the stack: #include <iostream> #include <vector> #include <cstdlib> #include <string> #include <stdexcept> using namespace std; template <class T> class Stack private: vector<t> elems; // elements void push(t const&); // push element void pop(); // pop element T top() const; // return top element bool empty() const // return true if empty. return elems.empty();

15 ; template <class T> void Stack<T>::push (T const& elem) // append copy of passed element elems.push_back(elem); template <class T> void Stack<T>::pop () if (elems.empty()) throw out_of_range("stack<>::pop(): empty stack"); // remove last element elems.pop_back(); template <class T> T Stack<T>::top () const if (elems.empty()) throw out_of_range("stack<>::top(): empty stack"); // return copy of last element return elems.back(); int main() try Stack<int> intstack; // stack of ints Stack<string> stringstack; // stack of strings // manipulate int stack intstack.push(7); cout << intstack.top() <<endl; // manipulate string stack stringstack.push("hello"); cout << stringstack.top() << std::endl;

16 stringstack.pop(); stringstack.pop(); catch (exception const& ex) cerr << "Exception: " << ex.what() <<endl; return -1; If we compile and run above code, this would produce the following result: 7 hello Exception: Stack<>::pop(): empty stack Q.5 a) What is a stream? Explain types of streams available in C++ 6M Ans A 'stream' is internally nothing but a series of characters. The characters may be either normal characters (char) or wide characters (wchar_t). Streams provide you with a universal character-based interface to any type of storage medium (for example, a file), without requiring you to know the details of how to write to the storage medium. Types of Streams in C++ : 1. Input Stream An input stream is a sequence of characters coming from an input source. When a program needs input, it extracts characters from an input stream. 2. Output Stream An output stream is a sequence of characters heading for an output sink. When a program wants to perform output, it inserts characters into an output stream. Stream Description cin cout cerr clog Standard input stream Standard output stream Standard error stream Buffered version of cerr

17 Output Streams Output streams are instances of the class ostream, which is defined in <iostream>. Eg. cout.put('b'); cout << 42; Output File Streams Writing to a file is easy. Simply declare an instance of the ofstream class. Eg. ofstream fs("data"); fs << "Here are some odd numbers:\n"; Input Streams Input streams are instances of the istream class. Eg. char c = cin.get(); cin >> x; Input File Streams We can construct an input file stream from a file name: Eg. ifstream ifs("data.txt"); double avg(const string& source) double num, total = 0; int count = 0; ifstream ifs( data.txt ); // won't work with C++ strings! if (!ifs) error("can't open file"); while (ifs >> num) total += num; count++; return total/count; Q.5 b) Write a program using open(), eof() and getline( ) member functions to open and read a file content line by line. [7] Ans.

18 // using open(), eof() and getline() member functions #include <iostream> #include <fstream> using namespace std; void main(void) char filename[70]; ifstream inputfile; char FirstLine[70]; char SecondLine[70]; char ThirdLine[70]; // prompt user for file name to be opened cout<<"enter the filename to be opened: "; // read and store the file name cin>>filename; // test open file for reading inputfile.open(filename); // if not the end of file if(!inputfile.eof()) cout<<"\nthe first line of text is: \n"; inputfile.getline(firstline, 70); cout<<firstline<<'\n'; cout<<"the second line of text is: \n"; inputfile.getline(secondline, 70); cout<<secondline<<endl; cout<<"the third line of text is: \n"; inputfile.getline(thirdline, 70); cout<<thirdline<<endl; // we leave the other line of text Output example: Enter the filename to be opened: C:\readfile.txt The first line of text is: This is readfile.txt file content. Just sample text, opening

19 The second line of text is: for reading by using getline() member function. The third line of text is: There are four lines of text to be read from. Press any key to continue... Or Q.6 a) Write a program that returns the size in bytes of a program entered on the command line : 7M $filesize program.txt. Ans. #include <iostream> #include <fstream> using namespace std; int main ( int argc, char** argv ) long begin,end; if( argc < 2 ) cout << "No file was passed. Usage: filesize program.txt"; return 1; ifstream myfile ( argv[1] ); begin = myfile.tellg(); myfile.seekg (0, ios::end); end = myfile.tellg(); myfile.close(); cout << "size is: " << (end-begin) << " bytes.\n"; return 0; Q.6 a) What are cin and cout? Explain iostream? [6] Ans 1. C++ I/O occurs in streams, which are sequences of bytes. If bytes flow from a device like a keyboard, a disk drive, or a network connection etc. to main memory, this is called input operation and if bytes flow from main memory to a device like a display screen, a printer, a disk drive, or a network connection, etc, this is called output operation.

20 The standard output stream (cout) 1. The predefined object cout is an instance of ostream class. 2. The cout object is said to be "connected to" the standard output device, which usually is the display screen. 3. The cout is used in conjunction with the stream insertion operator, which is written as << which are two less than signs as shown in the following example. The standard input stream (cin) The predefined object cin is an instance of istream class. The cin object is said to be attached to the standard input device, which usually is the keyboard. The cin is used in conjunction with the stream extraction operator, which is written as >> which are two greater than signs as shown in the following example. #include <iostream> using namespace std; int main( ) char name[50]; cout << "Please enter your name: "; cin >> name; cout << "Your name is: " << name << endl; When the above code is compiled and executed, it will prompt you to enter a name. You enter a value and then hit enter to see the result something as follows: Please enter your name: cplusplus Your name is: cplusplus Iostream 1. <iostream> to C++ is basically what <stdio.h> is to C. 2. iostream - header is used to access the input output built in functions of the language as it is the the Standard input/output streams library. 3. Here input-output refers to the fact of taking input command and showing output result in the program. 4. cin>>, cout<< - these are the member objects of the <iostream> header.

21 Q.7 a) What is the purpose of the iterator? Elaborate forward, bi-directional and random access iterators with suitable examples. [7] Ans 1. The concept of an iterator is fundamental to understanding the C++ Standard Template Library (STL) because iterators provide a means for accessing data stored in container classes such a vector, map, list, etc. Forward iterators 1. These have all the functionality of input iterators and -if they are not constant iterators- also the functionality of output iterators, 2. They are limited to one direction in which to iterate through a range (forward). 3. All standard containers support at least forward iterator types. 4. Forward iterators allow both reading and writing 5. For example, in the following code instances of the value 7 are replaced with the value 11 in a vector of integers: std::replace(avec.begin(), avec.end(), 7, 11); template <class ForwardIterator, class T> void replace(forwarditerator first, ForwardIterator last, const T& old_value, const T& new_value) while (first!= last) if (*first == old_value) *first = new_value; ++first; Bidirectional iterators 1. Bidirectional iterators are like forward iterators but can also be iterated through backwards. 2. A Bidirectional Iterator is an iterator that can be both incremented and decremented. 3. For example, we can use bidirectional iterators in a function that reverses the values of a container, placing the results into a new container: template <class BidirectionalIterator, class OutputIterator> OutputIterator reverse_copy(bidirectionaliterator first, BidirectionalIterator last, OutputIterator result)

22 while (first!= last) *result++ = *--last; return result; As always, the value initially denoted by the last argument is not considered part of the collection. The reverse_copy() function could be used, for example, to reverse the values of a linked list, and place the result into a vector: std::list<int> alist;... std::vector<int> avec (alist.size()); std::reverse_copy(alist.begin(), alist.end(), avec.begin() ); Random Access Iterators 1. Random-access iterators are iterators that can be used to access elements at an arbitrary offset position relative to the element they point to, offering the same functionality as pointers. 2. It provides both increment and decrement (just like a Bidirectional Iterator) 3. Random Access Iterators provide essentially all of the operations of ordinary C pointer arithmetic. 4. For example, the following algorithm randomly shuffles the elements of a container. This is similar to, although simpler than, the function std::random_shuffle() provided by the C++ Standard Library. template <class RandomAccessIterator> void mixup(randomaccessiterator first, RandomAccessIterator last) while (first < last) std::iter_swap(first, first + randominteger(last - first)); ++first; Q.7 b) What is a stack? How is it implemented using STL? [7] Ans

23 A stack is an adaptor that provides a restricted subset of Container functionality: it provides insertion, removal, and inspection of the element at the top of the stack. Stack is a "last in first out" (LIFO) data structure: the element at the top of a stack is the one that was most recently added. Stack does not allow iteration through its elements. Stack is a container adaptor, meaning that it is implemented on top of some underlying container type. By default that underlying type is deque, but a different type may be selected explicitly. Implementation To be able to use STL stacks in a file of C++ source code or a header file add o #include <stack> at the beginning of the file. Suppose that T is any type or class - say an int, a float, a struct, or a class, then o stack<t> s; declares a new and empty stack called s. Given s you can: test to see if it is empty: s.empty() Find how many items are in it: s.size() Push a t of type T onto the top: s.push(t) Pop the top off s: s.pop() Get the top item of s : s.top() Change the top item: s.top() = expression. Q.8 a) Elaborate advantages and disadvantages of the following Basic Sequence containers : [6] i) Vector ii) List. Ans Vector : Advantages i. Vectors have low memory usage ii. Vectors allow the user to denote an initial capacity for the container iii. Vectors allow random access : that is, an element of a vector may be referenced in the same manner as elements of arrays iv. inserting and removing elements from the end of the vector is generally fast. Disadvantages i. Erasing elements from a vector or even clearing the vector entirely does not necessarily free any of the memory associated with that element.

24 ii. The reallocation of memory that can be necessary with vectors when new elements are inserted into the list. List Advantages i. Inserting elements into a list is very fast if you already know where you want to insert them ii. Data is stored non-contiguously in memory which allows the list data structure to avoid the reallocation of memory iii. The list data structure allocates and deallocates memory as needed; therefore, it does not allocate memory that it is not currently using Disadvantages i. Lists only provide access to the start and end of the list -- there is no random access provided ii. With small data types (such as ints) the memory overhead is much more significant than that of a vector Q.8 b) What is STL? Why should programmer be interested in STL. What is the design philosopy of the STL?What are the major components of STL?[6] Ans The C++ STL (Standard Template Library) is a powerful set of C++ template classes to provides general-purpose templatized classes and functions that implement many popular and commonly used algorithms and data structures like vectors, lists, queues, and stacks. Programmers must be interested in STL because a) it is well tested and optimized. b) it is a really big time saver c) STL provides a set of common classes for C++, such as containers and associative arrays, that can be used with any built-in type and with any user-defined type that supports some elementary operations (such as copying and assignment). Design Philosophy of STL Generic containers that take the element type as a parameter. - know (almost) nothing about the element type - exception: ordered containers expect elements to have operator< - operations are (mostly) limited to add, remove, and retrieve - define their own iterators Useful, efficient, generic algorithms that:

25 - know nothing about the data structures they operate on - know (almost) nothing about the elements in the structures - operate on range of elements accessed via iterators STL algorithms are designed so that (almost) any algorithm can be used with any STL container, or any other data structure that supports iterators. Element type must support copy constructor/assignment. For ordered containers, the element type must support operator< or you can provide a special functor (function-object) of your own. The STL assumes value semantics for its contained elements: elements are copied to/from containers more than you might realize. The container methods and algorithms are highly efficient; it is unlikely that you could do better. Core of the C++ Standard Template Library are following three well-structured components: Containers Algorithms Iterators Component Description Containers are used to manage collections of objects of a certain kind. There are several different types of containers like deque, list, vector, map etc. Algorithms act on containers. They provide the means by which you will perform initialization, sorting, searching, and transforming of the contents of containers. Iterators are used to step through the elements of collections of objects. These collections may be containers or subsets of containers.

C++ Exception Handling 1

C++ Exception Handling 1 C++ Exception Handling 1 An exception is a problem that arises during the execution of a program. A C++ exception is a response to an exceptional circumstance that arises while a program is running, such

More information

C++ TEMPLATES. Templates are the foundation of generic programming, which involves writing code in a way that is independent of any particular type.

C++ TEMPLATES. Templates are the foundation of generic programming, which involves writing code in a way that is independent of any particular type. C++ TEMPLATES http://www.tutorialspoint.com/cplusplus/cpp_templates.htm Copyright tutorialspoint.com Templates are the foundation of generic programming, which involves writing code in a way that is independent

More information

DE70/DC56/DE122/DC106 OBJECT ORIENTED PROGRAMMING WITH C++ DEC 2015

DE70/DC56/DE122/DC106 OBJECT ORIENTED PROGRAMMING WITH C++ DEC 2015 Q.2 a. Define Object-oriented programming. List and explain various features of Object-oriented programming paradigm. (8) 1. Inheritance: Inheritance as the name suggests is the concept of inheriting or

More information

Data 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:

Data 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 information

CS201 - Introduction to Programming Glossary By

CS201 - 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 information

Short Notes of CS201

Short 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 information

I BSc(IT) [ Batch] Semester II Core: Object Oriented Programming With C plus plus - 212A Multiple Choice Questions.

I BSc(IT) [ Batch] Semester II Core: Object Oriented Programming With C plus plus - 212A Multiple Choice Questions. Dr.G.R.Damodaran College of Science (Autonomous, affiliated to the Bharathiar University, recognized by the UGC)Reaccredited at the 'A' Grade Level by the NAAC and ISO 9001:2008 Certified CRISL rated 'A'

More information

Object-Oriented Programming (OOP) Fundamental Principles of OOP

Object-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 information

Chapter 1: Object-Oriented Programming Using C++

Chapter 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 information

Solution Set. 1. Attempt any three of the following: 15 a. What is object oriented programming? State its applications.

Solution Set. 1. Attempt any three of the following: 15 a. What is object oriented programming? State its applications. (2½ Hours) [Total Marks: 75] Subject: OOPs with C++ Solution Set 1. Attempt any three of the following: 15 a. What is object oriented programming? State its applications. Ans: Object-oriented programming

More information

Chapter 15 - C++ As A "Better C"

Chapter 15 - C++ As A Better C Chapter 15 - C++ As A "Better C" Outline 15.1 Introduction 15.2 C++ 15.3 A Simple Program: Adding Two Integers 15.4 C++ Standard Library 15.5 Header Files 15.6 Inline Functions 15.7 References and Reference

More information

VALLIAMMAI ENGINEERING COLLEGE

VALLIAMMAI ENGINEERING COLLEGE VALLIAMMAI ENGINEERING COLLEGE SRM Nagar, Kattankulathur 603 203 DEPARTMENT OF COMPUTER SCIENCE AND ENGINEERING QUESTION BANK B.E. - Electrical and Electronics Engineering IV SEMESTER CS6456 - OBJECT ORIENTED

More information

OOPS Viva Questions. Object is termed as an instance of a class, and it has its own state, behavior and identity.

OOPS Viva Questions. Object is termed as an instance of a class, and it has its own state, behavior and identity. OOPS Viva Questions 1. What is OOPS? OOPS is abbreviated as Object Oriented Programming system in which programs are considered as a collection of objects. Each object is nothing but an instance of a class.

More information

Absolute C++ Walter Savitch

Absolute C++ Walter Savitch Absolute C++ sixth edition Walter Savitch Global edition This page intentionally left blank Absolute C++, Global Edition Cover Title Page Copyright Page Preface Acknowledgments Brief Contents Contents

More information

Introduction to C++ Systems Programming

Introduction 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 information

Interview Questions of C++

Interview 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 information

VIRTUAL FUNCTIONS Chapter 10

VIRTUAL 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 information

Object Oriented Programming with c++ Question Bank

Object Oriented Programming with c++ Question Bank Object Oriented Programming with c++ Question Bank UNIT-1: Introduction to C++ 1. Describe the following characteristics of OOP. i Encapsulation ii Polymorphism, iii Inheritance 2. Discuss function prototyping,

More information

OBJECT ORIENTED PROGRAMMING USING C++ CSCI Object Oriented Analysis and Design By Manali Torpe

OBJECT 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 information

Object Oriented Programming

Object 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 information

Object Oriented Pragramming (22316)

Object Oriented Pragramming (22316) Chapter 1 Principles of Object Oriented Programming (14 Marks) Q1. Give Characteristics of object oriented programming? Or Give features of object oriented programming? Ans: 1. Emphasis (focus) is on data

More information

CS 240 Data Structure Spring 2018 Exam III 04/25/2018

CS 240 Data Structure Spring 2018 Exam III 04/25/2018 CS 240 Data Structure Spring 2018 Exam III 04/25/2018 This exam contains BST, Stack, Quicksort and an arbitrary sorting algorithm. That is 4 sections. A) Stack a. Trace the code to predict the output of

More information

I BCS-031 BACHELOR OF COMPUTER APPLICATIONS (BCA) (Revised) Term-End Examination. June, 2015 BCS-031 : PROGRAMMING IN C ++

I BCS-031 BACHELOR OF COMPUTER APPLICATIONS (BCA) (Revised) Term-End Examination. June, 2015 BCS-031 : PROGRAMMING IN C ++ No. of Printed Pages : 3 I BCS-031 BACHELOR OF COMPUTER APPLICATIONS (BCA) (Revised) Term-End Examination 05723. June, 2015 BCS-031 : PROGRAMMING IN C ++ Time : 3 hours Maximum Marks : 100 (Weightage 75%)

More information

Fast Introduction to Object Oriented Programming and C++

Fast Introduction to Object Oriented Programming and C++ Fast Introduction to Object Oriented Programming and C++ Daniel G. Aliaga Note: a compilation of slides from Jacques de Wet, Ohio State University, Chad Willwerth, and Daniel Aliaga. Outline Programming

More information

JAYARAM COLLEGE OF ENGINEERING AND TECHNOLOGY Pagalavadi, Tiruchirappalli (An approved by AICTE and Affiliated to Anna University)

JAYARAM COLLEGE OF ENGINEERING AND TECHNOLOGY Pagalavadi, Tiruchirappalli (An approved by AICTE and Affiliated to Anna University) Estd: 1994 JAYARAM COLLEGE OF ENGINEERING AND TECHNOLOGY Pagalavadi, Tiruchirappalli - 621014 (An approved by AICTE and Affiliated to Anna University) ISO 9001:2000 Certified Subject Code & Name : CS 1202

More information

CS201 Latest Solved MCQs

CS201 Latest Solved MCQs Quiz Start Time: 09:34 PM Time Left 82 sec(s) Question # 1 of 10 ( Start time: 09:34:54 PM ) Total Marks: 1 While developing a program; should we think about the user interface? //handouts main reusability

More information

COEN244: Class & function templates

COEN244: Class & function templates COEN244: Class & function templates Aishy Amer Electrical & Computer Engineering Templates Function Templates Class Templates Outline Templates and inheritance Introduction to C++ Standard Template Library

More information

CS3157: Advanced Programming. Outline

CS3157: Advanced Programming. Outline CS3157: Advanced Programming Lecture #12 Apr 3 Shlomo Hershkop shlomo@cs.columbia.edu 1 Outline Intro CPP Boring stuff: Language basics: identifiers, data types, operators, type conversions, branching

More information

C++_ MARKS 40 MIN

C++_ MARKS 40 MIN C++_16.9.2018 40 MARKS 40 MIN https://tinyurl.com/ya62ayzs 1) Declaration of a pointer more than once may cause A. Error B. Abort C. Trap D. Null 2Whice is not a correct variable type in C++? A. float

More information

Quiz Start Time: 09:34 PM Time Left 82 sec(s)

Quiz Start Time: 09:34 PM Time Left 82 sec(s) Quiz Start Time: 09:34 PM Time Left 82 sec(s) Question # 1 of 10 ( Start time: 09:34:54 PM ) Total Marks: 1 While developing a program; should we think about the user interface? //handouts main reusability

More information

OBJECT ORIENTED PROGRAMMING. Ms. Ajeta Nandal C.R.Polytechnic,Rohtak

OBJECT 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 information

STRUCTURING OF PROGRAM

STRUCTURING 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 information

UNIT III. C++ Programming Advanced Features. Abstract Class

UNIT III. C++ Programming Advanced Features. Abstract Class UNIT III C++ Programming Advanced Features Abstract Class An interface describes the behavior or capabilities of a C++ class without committing to a particular implementation of that class. The C++ interfaces

More information

DHANALAKSHMI COLLEGE OF ENGINEERING, CHENNAI DEPARTMENT OF ELECTRICAL AND ELECTRONICS ENGINEERING CS6456 OBJECT ORIENTED PROGRAMMING

DHANALAKSHMI COLLEGE OF ENGINEERING, CHENNAI DEPARTMENT OF ELECTRICAL AND ELECTRONICS ENGINEERING CS6456 OBJECT ORIENTED PROGRAMMING DHANALAKSHMI COLLEGE OF ENGINEERING, CHENNAI DEPARTMENT OF ELECTRICAL AND ELECTRONICS ENGINEERING CS6456 OBJECT ORIENTED PROGRAMMING Unit I : OVERVIEW PART A (2 Marks) 1. Give some characteristics of procedure-oriented

More information

Where do we go from here?

Where do we go from here? Where do we go from here? C++ classes and objects, with all the moving parts visible operator overloading templates, STL, standards, Java components, collections, generics language and performance comparisons

More information

Introduction to C++ Professor Hugh C. Lauer CS-2303, System Programming Concepts

Introduction to C++ Professor Hugh C. Lauer CS-2303, System Programming Concepts Introduction to C++ Professor Hugh C. Lauer CS-2303, System Programming Concepts (Slides include materials from The C Programming Language, 2 nd edition, by Kernighan and Ritchie, Absolute C++, by Walter

More information

Evolution of Programming Languages

Evolution of Programming Languages Evolution of Programming Languages 40's machine level raw binary 50's assembly language names for instructions and addresses very specific to each machine 60's high-level languages: Fortran, Cobol, Algol,

More information

AN OVERVIEW OF C++ 1

AN 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 information

Pointers. Developed By Ms. K.M.Sanghavi

Pointers. Developed By Ms. K.M.Sanghavi Pointers Developed By Ms. K.M.Sanghavi Memory Management : Dynamic Pointers Linked List Example Smart Pointers Auto Pointer Unique Pointer Shared Pointer Weak Pointer Memory Management In order to create

More information

Jayaram college of Engineering and Technology, Pagalavadi. CS2203 Object Oriented Programming Question Bank Prepared By: S.Gopalakrishnan, Lecturer/IT

Jayaram college of Engineering and Technology, Pagalavadi. CS2203 Object Oriented Programming Question Bank Prepared By: S.Gopalakrishnan, Lecturer/IT CS2203 Object Oriented Programming Question Bank Prepared By: S.Gopalakrishnan, Lecturer/IT Two Mark Questions UNIT - I 1. DEFINE ENCAPSULATION. Encapsulation is the process of combining data and functions

More information

Documentation. Programming / Documentation Slide 42

Documentation.   Programming / Documentation Slide 42 Documentation http://www.math.upb.de/~robsy/lehre/programmierkurs2008/ Programming / Documentation Slide 42 Memory Management (I) There are several types of memory which a program can access: Stack Every

More information

Unit 1 : Principles of object oriented programming

Unit 1 : Principles of object oriented programming Unit 1 : Principles of object oriented programming Difference Between Procedure Oriented Programming (POP) & Object Oriented Programming (OOP) Divided Into Importance Procedure Oriented Programming In

More information

Cpt S 122 Data Structures. Course Review Midterm Exam # 2

Cpt S 122 Data Structures. Course Review Midterm Exam # 2 Cpt S 122 Data Structures Course Review Midterm Exam # 2 Nirmalya Roy School of Electrical Engineering and Computer Science Washington State University Midterm Exam 2 When: Monday (11/05) 12:10 pm -1pm

More information

Instantiation of Template class

Instantiation 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 information

cs3157: c++ lecture #2 (mon-11-apr-2005) chronology of some programming languages... C++ vs Java identifiers.

cs3157: c++ lecture #2 (mon-11-apr-2005) chronology of some programming languages... C++ vs Java identifiers. cs3157: c++ lecture #2 (mon-11-apr-2005) chronology of some programming languages... today: language basics: identifiers, data types, operators, type conversions, branching and looping, program structure

More information

SRM ARTS AND SCIENCE COLLEGE SRM NAGAR, KATTANKULATHUR

SRM 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 information

G52CPP C++ Programming Lecture 14. Dr Jason Atkin

G52CPP C++ Programming Lecture 14. Dr Jason Atkin G52CPP C++ Programming Lecture 14 Dr Jason Atkin 1 Last Lecture Automatically created methods: A default constructor so that objects can be created without defining a constructor A copy constructor used

More information

QUESTION BANK. SUBJECT CODE / Name: CS2311 OBJECT ORIENTED PROGRAMMING

QUESTION BANK. SUBJECT CODE / Name: CS2311 OBJECT ORIENTED PROGRAMMING QUESTION BANK DEPARTMENT:EEE SEMESTER: V SUBJECT CODE / Name: CS2311 OBJECT ORIENTED PROGRAMMING UNIT III PART - A (2 Marks) 1. What are the advantages of using exception handling? (AUC MAY 2013) In C++,

More information

PIC10B/1 Winter 2014 Exam I Study Guide

PIC10B/1 Winter 2014 Exam I Study Guide PIC10B/1 Winter 2014 Exam I Study Guide Suggested Study Order: 1. Lecture Notes (Lectures 1-8 inclusive) 2. Examples/Homework 3. Textbook The midterm will test 1. Your ability to read a program and understand

More information

Chapter 2. Procedural Programming

Chapter 2. Procedural Programming Chapter 2 Procedural Programming 2: Preview Basic concepts that are similar in both Java and C++, including: standard data types control structures I/O functions Dynamic memory management, and some basic

More information

C++ Important Questions with Answers

C++ 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 information

DHANALAKSHMI 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 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 information

Object-Oriented Programming

Object-Oriented Programming Object-Oriented Programming 1. What is object-oriented programming (OOP)? OOP is a technique to develop logical modules, such as classes that contain properties, methods, fields, and events. An object

More information

Unit III Virtual Functions. Developed By Ms. K.M.Sanghavi

Unit 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 information

OOP THROUGH C++(R16) int *x; float *f; char *c;

OOP 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 information

STL components. STL: C++ Standard Library Standard Template Library (STL) Main Ideas. Components. Encapsulates complex data structures and algorithms

STL components. STL: C++ Standard Library Standard Template Library (STL) Main Ideas. Components. Encapsulates complex data structures and algorithms STL: C++ Standard Library Standard Template Library (STL) Encapsulates complex data structures and algorithms is a library of generic container classes which are both efficient and functional C++ STL developed

More information

CMSC 202 Section 010x Spring Justin Martineau, Tuesday 11:30am

CMSC 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 information

CS 6456 OBJCET ORIENTED PROGRAMMING IV SEMESTER/EEE

CS 6456 OBJCET ORIENTED PROGRAMMING IV SEMESTER/EEE CS 6456 OBJCET ORIENTED PROGRAMMING IV SEMESTER/EEE PART A UNIT I 1. Differentiate object oriented programming from procedure oriented programming. 2. Define abstraction and encapsulation. 3. Differentiate

More information

AC55/AT55 OBJECT ORIENTED PROGRAMMING WITH C++ DEC 2013

AC55/AT55 OBJECT ORIENTED PROGRAMMING WITH C++ DEC 2013 Q.2 a. Discuss the fundamental features of the object oriented programming. The fundamentals features of the OOPs are the following: (i) Encapsulation: It is a mechanism that associates the code and data

More information

IS 0020 Program Design and Software Tools

IS 0020 Program Design and Software Tools 1 Introduction 2 IS 0020 Program Design and Software Tools Exception Handling Lecture 12 November 23, 200 Exceptions Indicates problem occurred in program Not common An "exception" to a program that usually

More information

Preface to the Second Edition Preface to the First Edition Brief Contents Introduction to C++ p. 1 A Review of Structures p.

Preface to the Second Edition Preface to the First Edition Brief Contents Introduction to C++ p. 1 A Review of Structures p. Preface to the Second Edition p. iii Preface to the First Edition p. vi Brief Contents p. ix Introduction to C++ p. 1 A Review of Structures p. 1 The Need for Structures p. 1 Creating a New Data Type Using

More information

Object Oriented Programming. Solved MCQs - Part 2

Object 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 information

Introduction to Programming Using Java (98-388)

Introduction to Programming Using Java (98-388) Introduction to Programming Using Java (98-388) Understand Java fundamentals Describe the use of main in a Java application Signature of main, why it is static; how to consume an instance of your own class;

More information

Object Oriented Programming

Object Oriented Programming Object Oriented Programming Course Title: Object Oriented Programming Full Marks: 60 20 20 Course No: CSC161 Pass Marks: 24 8 8 Nature of Course: Theory Lab Credit Hrs: 3 Semester: II Course Description:

More information

CPSC 427: Object-Oriented Programming

CPSC 427: Object-Oriented Programming CPSC 427: Object-Oriented Programming Michael J. Fischer Lecture 22 November 28, 2016 CPSC 427, Lecture 22 1/43 Exceptions (continued) Code Reuse Linear Containers Ordered Containers Multiple Inheritance

More information

Lecture-5. STL Containers & Iterators

Lecture-5. STL Containers & Iterators Lecture-5 STL Containers & Iterators Containers as a form of Aggregation Fixed aggregation An object is composed of a fixed set of component objects Variable aggregation An object is composed of a variable

More information

COMP 2355 Introduction to Systems Programming

COMP 2355 Introduction to Systems Programming COMP 2355 Introduction to Systems Programming Christian Grothoff christian@grothoff.org http://grothoff.org/christian/ 1 Today Class syntax, Constructors, Destructors Static methods Inheritance, Abstract

More information

Piyush Kumar. input data. both cout and cin are data objects and are defined as classes ( type istream ) class

Piyush Kumar. input data. both cout and cin are data objects and are defined as classes ( type istream ) class C++ IO C++ IO All I/O is in essence, done one character at a time For : COP 3330. Object oriented Programming (Using C++) http://www.compgeom.com/~piyush/teach/3330 Concept: I/O operations act on streams

More information

Introduction to C++ (Extensions to C)

Introduction to C++ (Extensions to C) Introduction to C++ (Extensions to C) C is purely procedural, with no objects, classes or inheritance. C++ is a hybrid of C with OOP! The most significant extensions to C are: much stronger type checking.

More information

What are the characteristics of Object Oriented programming language?

What are the characteristics of Object Oriented programming language? What are the various elements of OOP? Following are the various elements of OOP:- Class:- A class is a collection of data and the various operations that can be performed on that data. Object- This is

More information

CSE 303: Concepts and Tools for Software Development

CSE 303: Concepts and Tools for Software Development CSE 303: Concepts and Tools for Software Development Hal Perkins Autumn 2008 Lecture 24 Introduction to C++ CSE303 Autumn 2008, Lecture 24 1 C++ C++ is an enormous language: All of C Classes and objects

More information

STUDY NOTES UNIT 1 - INTRODUCTION TO OBJECT ORIENTED PROGRAMMING

STUDY NOTES UNIT 1 - INTRODUCTION TO OBJECT ORIENTED PROGRAMMING OBJECT ORIENTED PROGRAMMING STUDY NOTES UNIT 1 - INTRODUCTION TO OBJECT ORIENTED PROGRAMMING 1. Object Oriented Programming Paradigms 2. Comparison of Programming Paradigms 3. Basic Object Oriented Programming

More information

1. The term STL stands for?

1. The term STL stands for? 1. The term STL stands for? a) Simple Template Library b) Static Template Library c) Single Type Based Library d) Standard Template Library Answer : d 2. Which of the following statements regarding the

More information

CHAPTER 1 Introduction to Computers and Programming CHAPTER 2 Introduction to C++ ( Hexadecimal 0xF4 and Octal literals 031) cout Object

CHAPTER 1 Introduction to Computers and Programming CHAPTER 2 Introduction to C++ ( Hexadecimal 0xF4 and Octal literals 031) cout Object CHAPTER 1 Introduction to Computers and Programming 1 1.1 Why Program? 1 1.2 Computer Systems: Hardware and Software 2 1.3 Programs and Programming Languages 8 1.4 What is a Program Made of? 14 1.5 Input,

More information

Lecture 10. To use try, throw, and catch Constructors and destructors Standard exception hierarchy new failures

Lecture 10. To use try, throw, and catch Constructors and destructors Standard exception hierarchy new failures Lecture 10 Class string Exception Handling To use try, throw, and catch Constructors and destructors Standard exception hierarchy new failures Class template auto_ptr Lec 10 Programming in C++ 1 Class

More information

CS 162, Lecture 25: Exam II Review. 30 May 2018

CS 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 information

IS0020 Program Design and Software Tools Summer, 2004 August 2, 2004 in Class

IS0020 Program Design and Software Tools Summer, 2004 August 2, 2004 in Class IS0020 Program Design and Software Tools Summer, 2004 August 2, 2004 in Class Name: A. Fill in the blanks in each of the following statements [Score: 20]: 1. A base class s members can be accessed only

More information

(5-1) Object-Oriented Programming (OOP) and C++ Instructor - Andrew S. O Fallon CptS 122 (February 4, 2019) Washington State University

(5-1) Object-Oriented Programming (OOP) and C++ Instructor - Andrew S. O Fallon CptS 122 (February 4, 2019) Washington State University (5-1) Object-Oriented Programming (OOP) and C++ Instructor - Andrew S. O Fallon CptS 122 (February 4, 2019) Washington State University Key Concepts 2 Object-Oriented Design Object-Oriented Programming

More information

Ch. 12: Operator Overloading

Ch. 12: Operator Overloading Ch. 12: Operator Overloading Operator overloading is just syntactic sugar, i.e. another way to make a function call: shift_left(42, 3); 42

More information

CS304 Object Oriented Programming Final Term

CS304 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 information

Paytm 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 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 information

Government Polytechnic, Muzaffarpur. Name of the Lab: OBJECT ORIENTED PROGRAMMING

Government 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 information

C++ Quick Guide. Advertisements

C++ Quick Guide. Advertisements C++ Quick Guide Advertisements Previous Page Next Page C++ is a statically typed, compiled, general purpose, case sensitive, free form programming language that supports procedural, object oriented, and

More information

Stream States. Formatted I/O

Stream States. Formatted I/O C++ Input and Output * the standard C++ library has a collection of classes that can be used for input and output * most of these classes are based on a stream abstraction, the input or output device is

More information

CS304 Object Oriented Programming

CS304 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 information

B.C.A 2017 OBJECT ORIENTED PROGRAMMING USING C++ BCA303T MODULE SPECIFICATION SHEET

B.C.A 2017 OBJECT ORIENTED PROGRAMMING USING C++ BCA303T MODULE SPECIFICATION SHEET B.C.A 2017 OBJECT ORIENTED PROGRAMMING USING C++ BCA303T MODULE SPECIFICATION SHEET Course Outline The main objective of this course is to introduce students to the basic concepts of a selected language

More information

CS304- Object Oriented Programming LATEST SOLVED MCQS FROM FINALTERM PAPERS. MC

CS304- Object Oriented Programming LATEST SOLVED MCQS FROM FINALTERM PAPERS. MC CS304- Object Oriented Programming LATEST SOLVED MCQS FROM FINALTERM PAPERS JAN 28,2011 MC100401285 Moaaz.pk@gmail.com Mc100401285@gmail.com PSMD01 FINALTERM EXAMINATION 14 Feb, 2011 CS304- Object Oriented

More information

Today. andyoucanalsoconsultchapters6amd7inthetextbook. cis15-fall2007-parsons-lectvii.1 2

Today. andyoucanalsoconsultchapters6amd7inthetextbook. cis15-fall2007-parsons-lectvii.1 2 TEMPLATES Today This lecture looks at techniques for generic programming: Generic pointers Templates The standard template library Thebestreferenceis: http://www.cppreference.com/index.html andyoucanalsoconsultchapters6amd7inthetextbook.

More information

Introduction to C++ Introduction to C++ 1

Introduction to C++ Introduction to C++ 1 1 What Is C++? (Mostly) an extension of C to include: Classes Templates Inheritance and Multiple Inheritance Function and Operator Overloading New (and better) Standard Library References and Reference

More information

Polymorphism Part 1 1

Polymorphism 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 information

calling a function - function-name(argument list); y = square ( z ); include parentheses even if parameter list is empty!

calling a function - function-name(argument list); y = square ( z ); include parentheses even if parameter list is empty! Chapter 6 - Functions return type void or a valid data type ( int, double, char, etc) name parameter list void or a list of parameters separated by commas body return keyword required if function returns

More information

UNIT POLYMORPHISM

UNIT 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 information

END TERM EXAMINATION

END TERM EXAMINATION END TERM EXAMINATION THIRD SEMESTER [BCA] DECEMBER 2007 Paper Code: BCA 209 Subject: Object Oriented Programming Time: 3 hours Maximum Marks: 75 Note: Attempt all questions. Internal choice is indicated.

More information

Objectives. 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++ 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 information

CE221 Programming in C++ Part 1 Introduction

CE221 Programming in C++ Part 1 Introduction CE221 Programming in C++ Part 1 Introduction 06/10/2017 CE221 Part 1 1 Module Schedule There are two lectures (Monday 13.00-13.50 and Tuesday 11.00-11.50) each week in the autumn term, and a 2-hour lab

More information

Chapter 2: Basic Elements of C++

Chapter 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

CSCI 171 Chapter Outlines

CSCI 171 Chapter Outlines Contents CSCI 171 Chapter 1 Overview... 2 CSCI 171 Chapter 2 Programming Components... 3 CSCI 171 Chapter 3 (Sections 1 4) Selection Structures... 5 CSCI 171 Chapter 3 (Sections 5 & 6) Iteration Structures

More information

Pointers and Arrays CS 201. This slide set covers pointers and arrays in C++. You should read Chapter 8 from your Deitel & Deitel book.

Pointers and Arrays CS 201. This slide set covers pointers and arrays in C++. You should read Chapter 8 from your Deitel & Deitel book. Pointers and Arrays CS 201 This slide set covers pointers and arrays in C++. You should read Chapter 8 from your Deitel & Deitel book. Pointers Powerful but difficult to master Used to simulate pass-by-reference

More information

KOM3191 Object Oriented Programming Dr Muharrem Mercimek OPERATOR OVERLOADING. KOM3191 Object-Oriented Programming

KOM3191 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 information

Chapter 2: Basic Elements of C++ Objectives. Objectives (cont d.) A C++ Program. Introduction

Chapter 2: Basic Elements of C++ Objectives. Objectives (cont d.) A C++ Program. Introduction Chapter 2: Basic Elements of C++ C++ Programming: From Problem Analysis to Program Design, Fifth Edition 1 Objectives In this chapter, you will: Become familiar with functions, special symbols, and identifiers

More information