QUESTION BANK UNIT III

Size: px
Start display at page:

Download "QUESTION BANK UNIT III"

Transcription

1 QUESTION BANK UNIT III DEPARTMENT: CSE SUB NAME: OBJECT ORIENTED PROGRAMMING SEMESTER III SUB CODE: CS2203 PART A (2 MARKS) 1. What are templates? (AUC DEC 2009) Template is one of the features added to C++. It is a new concept which enable us to define generic classes and functions and thus provides support for generic programming. A template can be used to create a family of classes or functions. 2. Illustrate the exception handling mechanism. (AUC DEC 2009) C++ exception handling mechanism is basically upon three keywords, namely, try, throw, and catch. try is used to preface a block of statements which may generate exceptions. throw - When an exception is detected, it is thrown using a throw statement in the try block. Catch- A catch block defined by the keyword catch catches the exception thrown by the thrown statement in the try block and handles its appropriately. 3. What happens when a raised exception is not caught by catch block? (AUC MAY 2010) If the type of object thrown matches the arg type in the catch statement, then catch block is executed for handling the exception. If they do not match the program is aborted with the help of abort() function which is invoked by default. When no exception is detected and thrown, the control goes to the statement immediately after the catch block. That is the catch block is skipped. 4. Give the syntax of a pointer to a function which returns an integer and takes arguments one of integer type and 2 of float type. What is the difference between a class and a structure? int (X_fun) (int, float); (AUC MAY 2010) 5. What is a template? What are their advantages (AUC DEC 2010/JUN 2012/DEC 2012) A template can be used to create a family of classes or functions. A template is defined with a parameter that would be replaced by a specified data type at the time of actual use of the class or functions. Supporting different data types in a single framework. The template are sometimes called parameterized classes or functions.

2 6. How is an exception handled in C++? (AUC DEC 2010) Exceptions are run time anomalies or unusual conditions that a program may encounter while executing. 1. Find the problem (Hit the exception) 2. Inform that an error has occurred.( Throw the exception) 3. Receive the error information. ( Catch the exception) 4. Take corrective actions.( Handle the exception) 7. What is function template? Explain. (AUC MAY 2011) Like class template, we can also define function templates that could be used to create a family of functions with different argument types. The general format of a function template is: template <class T> returntype functionname ( arguments of type T) // //.Body of function with type T wherever appropriate //.. 8. List five common examples of exceptions. (AUC MAY 2011) Division by zero Access to an array outside of its bounds Running out of memory or disk space. 9. What is class template? (AUC DEC 2011) Templates allows to define generic classes. It is a simple process to create a generic class using a template with an anonymous type. The general format of class template is: template <class T> class classname // class member specification. //. with anonymous type T wherever appropriate //, What are 3 basic keywords of exception handling mechanism? (AUC DEC 2011) C++ exception handling mechanism is basically built upon three keywords try throw catch 11. What is an exception? (AUC JUN 2012)

3 Exception is defined as unusual error condition occur in a program. 12. What is throw()? What is its use? (AUC DEC 2012) The keyword throw is used to raise an exception when an error is generated in the computation. The throw() expression initializes a temporary object of the type T used in throw ( T arg). throw T 13. Write a function template that swaps the values of the two variable with which it is called? template<class T> T* c; *C = *a; *a = *b; *b = c; (AUC JUN 2013) 14. What functions does terminate and unexpected handlers call? (AUC JUN 2013) The function terminate() is invoked when an exception is raised and the handler not found. The exception unexcepted() is called when a function throws an exception not listed in its exception specification. 15. What is the role of throw and catch blocks? block. throw - When an exception is detected, it is thrown using a throw statement in the try Catch- A catch block defined by the keyword catch catches the exception thrown by the thrown statement in the try block and handles its appropriately. 16. Write a program to exchange values of two variables. Use template variable as function arguments. #include < iostream.h> Using namespace std; Template<class T> Void swap(t &x, T &y) T temp= x; x=y; y= temp; void fun( int m, int n) cout<< m and n before swap: <<m<<n; swap(m,n); cout<< m and n after swap: <<m<<n;

4 int main() fun(100,200); return 0; Output m and n before swap: m and n after swap: Distinguish between overloaded functions and function templates overloaded functions A template function may be overloaded either by template functions or ordinary functions of its name. function templates Used to create a family of functions with different argument types. No automatic conversions are applied to arguments on the template functions. Template functions can be overloaded. Use multiple parameters in both the class and function templates. A function generated from a function template is called a template function. 18. When do we need multiple catch Handlers? Due to mismatch, if an exception is not caught, abnormal program termination will occur. It is important to note that the catch block is simply skipped if the catch statement does not catch an exception. It is possible that a program segment has more than one condition to throw an exception. In such cases, we can associate more than one catch statement with a try 19. Write a program to demonstrate the concept of rethrowing an exception. #include <iostream.h> Using namespace std; Void divide(double x, double y) cout<< Inside function ; try if(y==0.0) throw y; else cout<< Division= <<x/y; catch(double) cout<< Caught double inside function ; throw; cout<< end of function ; Int main() cout<< Inside main ; try divide(10.5, 2.0); divide(20.0, 0.0) // throwing double // Rethrowing double

5 catch(double) cout<< Caught double inside main ; cout<< end of main ; return 0; 20. What is the need for template function in c++? What are the advantages? C++ supports a mechanism known as template to implement the concepts of generic programming. Templates allows us to generate a family of classes or functions to handle different data types. Templates are very helpful in achieving software reusability. 21. Distinguish between generic and non-generic arguments to function templates. Generic arguments Use more than one generic data type in the template statement, using a comma- separated list. template<class T1,class T2, > returntype functionname (arg of types T1,T2, )..(body of function) Non-generic arguments Use non-type arguments such as strings, function names, constant expressions and built-in-types. template< class T, int size) class array T a[size];//automatic array initialization; 22. Give few examples of multi arguments templates Use more than one generic data type in the template statement,using a commaseparated list. template<class T1,class T2, > returntype functionname (arg of types T1,T2, ).. (body of function) 23. What is terminate() function? Why is it need? The function to call when the exception handling mechanism does not get any proper handler for a thrown exception. If the type of object thrown matches the arg type in the catch statement, then catch block is executed for handling the exception. If they do not match the program is terminated with the help of terminate() function which is invoked by default. 24. What are exception specifications? It is possible to specify what kind of exceptions can be thrown by functions, using a specific syntax. We can append the function definition header with throw keyword and possible type of expressions to be thrown in the parenthesis. It is known as exception specification. Example: void ExGen() throw(int, char) Exception specification is used for throwing outside the function.

6 25. What is unexpected() function?give an example. Like terminate() function, we have our own Unexpected() function. It is possible to check if the exception is already thrown when we are about to throw using Uncaught_exception. This is important as throwing a new exception when one is already thrown call terminate(). 26.What is uncaught_exception() function? And why do we need it? The function to call when we want to check before throwing any exception if some other exception is already on. 27.What is the disadvantage of exception handling function? It adds to runtime overhead. Demands different style of programming than conventional programming. It is not the tool to replace normal error handling. 28. What is the object destroy problem? And how can exception handling help here? The objects which are created just before the error has occurred must be destroyed properly. This is known as the object destroy problem. 29. What is typename? The keyword typename indicates that the expression following the keyword is the name of a type. Used within the body of the template function<> Writing typename before, the compiler makes the program more portable. 30.Give an example explaining the need for overloading a template with another template. The template function definition forces the compiler to overload the function as many times as it is used with different types in the program. A template function may be overloaded either by template functions or ordinary functions of its name. 31. What is the importance of catch all? It is possible for us to catch all types of exceptions in a single catch section. We can use catch( )( three dots as argument) for the same. Catch all section is very useful in debugging and is as useful as a default statement in switch. 32. What is the difference between manually overloaded functions and template instantiation? manually overloaded functions Automatically overloadable functions have different types of arguments but same body. Usually have different code. template instantiation The process of creating a specific class from a class template is called instantiation. The template function requires an exact match of arguments. 33. Give an example where using the default arguments are useful in class template. Example: template<typename Type= int, int Size=10>

7 PART B (16 MARKS) 1. (i) Write the syntax for member function template. (4) (AUC DEC 2009) The member function of the template classes themselves are parameterized by the type argument and therefore these functions must be defined by the function templates. It takes the following general form: Template<class T> returntype classname <T> :: functionname(arglist) //. // Function body //.. (ii) Write a C++ program using class template for finding the scalar product for int type vector and float type vector. (12) (AUC DEC 2009) #include<iostream.h> Using namespace std; Const size = 3; Template<class T> Class vector T *v; public: vector() v=new T[size]; for(int i=0;i<size;i++) v[i]=0; Vector(T* a) // create a vector from an array. for(int i=0;i<size;i++) v[i]=a[i]; T operator* (vector &y) // scalar product T sum = 0; for(int i=0;i<size;i++) sum += this -> v[i] * y.v[i]; return sum; Void display(void) for(int i=0;i<size;i++) cout<<v[i]<< \t ; ; int main() int x[3] = 1,2,3; int y[3] = 4,5,6; float a[3] = 1.1,2.2,3.3; float b[3] = 4.4,5.5,6.6; vector <int> v1; vector <int> v2; vector <float> v3; vector <float> v4; v1 = x; v2 = y; v3 = a; v4 = b; cout<< v1= ; v1.display(); cout<< v2= ; v2.display(); cout<< v3= ; v3.display(); cout<< v4= ; v4.display(); cout<< v1 x v2 = << v1*v2;

8 cout<< v3 x v4 = <<v3 x v4; return 0; SAMPLE OUTPUT v1 = v2 = v3 = v4 = v1 x v2 = 32 v3 x v4 = (i) Explain how rethrowing of an exception is done. (4) (AUC DEC 2009) A handler may decide to rethrow the exception caught without processing it. In such situations, we may simply invoke throw without any arguments as shown below : throw; This causes the current exception to be thrown to the next enclosing try/catch sequence and is caught by a catch statement listed after that enclosing try block. When an exception is rethrown, it will not be caught by the same catch statement or any other catch in that group. Rather, it will be caught by an appropriate catch in the outer try/catch sequence only. A catch handler itself may detect and throw an exception. The exception thrown will be caught by any catch statements in that group. It will be passed on to the next outer try/catch sequence of processing. (ii) Write a C++ program that illustrates multiple catch statements. (12) (AUC DEC 2009) It is possible that a program segment has more than one condition to throw an exception. In such cases, we can associate more than one catch statement with a try(like switch statement). Program: #include<iostream.h> Using namespace std; Void test(int x) try If( x == 1) throw x; // int else if( x==0) throw x ; // char else if(x == -1) throw 1.0; // double cout<< End of try-block ; catch(char c) // catch 1 Cout<< Caught a character ; catch(int m) //catch 2 Cout<< Caught an integer ; catch(double d) // catch 3 Cout<< Caught a double ; cout<< End of try-catch system \n ; int main() cout<< Testing Multiple catches ; cout<< X == 1 \n ;

9 test(1); cout<< x == 0 \n ; test(0); cout<< x == -1 \n ; test(-1); cout<< x == 2 \n ; test(2); return 0; SAMPLE OUTPUT Testing Multiple Catches X ==1 Caught an integer End of try-catch system X == 0 Caught a character End of try-catch system X == -1 Caught a double End of try-catch system X == 2 End of try-block End of try-catch system 3. Write a C++ program to create a base class called house. There are two classes called door and window available. The house class has members which provide information related to the area of construction, doors and windows details. It delegates responsibility of computing the cost of doors and window construction to door and window classes respectively. Write a C++ program to model the above relationship and find the cost of constructing the house. (16) (AUC MAY 2010) #include<stdio.h> class house int size, c; public: void read() cin>>size; int cost() c=size * 1000; return(c); ; class window :: public house

10 int no_of_window,c; public: void get() cin>>no_of_window; int wincost() c=no_of_window x 500; ; class door :: public window int no_of_door,d; public: void getdata() cin>>no_of_door; int doorcost() d=no_of_door * 600; ; int main() door d1; int c; d1.read(); d1.wincost(); d1.doorcost(); c=cost()+wincost()+doorcost(); cout<<c; 4. Write a C++ program to compute the square root of a number. The input value must be tested for validity. If it is negative, the user defined function mysqrt() should raise an exception. (AUC MAY 2010) #include<iostream.h> #includte<math.h>

11 main() int a; float n; cin>>a; try n=mysqrt(a); catch float(negative) cout<< the no.of negative is: ; float mysqr(int a) float n; if(a>0) throws n; else return n=sqrt(a); 5. (i) Explain the overloading of template function with suitable example. (8) (AUC DEC 2010) A template function may be overloaded either by template functions or ordinary functions of its name. In such cases, the overloading accomplishes as follows: 1. Call an ordinary function that has an exact match. 2. Call a template function that could be created with an exact match. 3. Try normal overloading resolution to ordinary functions and call the one that matches. An error is generated if no match is found. No automatic conversions are applied to arguments on the template functions. Program: Template function with Explicit function #include<iostream.h> #include<string.h> Using namespace std; Template<class T> void display(t x) // Overloaded template function display cout<< Overloaded Template Display 1 : <<x<< \n ;

12 cout<< Overloaded Template Display 2 : <<x<<,<<y<< \n ; void display(int x) // Overloaded generic display function cout<< Explicit Display: <<x<< \n ; int main() display(100); display(12.34); display(100,12.34); display( C ); return 0; SAMPLE OUTPUT Explicit Display: 100 Overloaded template Display 1: Overloaded template Display 2: 100, Overloaded template Display 1: C ii) Write a function template for finding the minimum value contained in an array. (8) (AUC DEC 2010) Program: Template< Class T> T minimum ( T A, T n) T a[]; T min = 1; for(int i=0; i<n; i++) if(a[i]<=min) min=a[i]; return min; void main() int a[10], n ; min; cin>>n; for(int i=0;i<n;i++) cin>>a[i]; min=minimum (a,n); cout<<min; 6. (i) List the advantages of exception handling mechanisms. (4) (AUC DEC 2010)

13 C++ exception provides a type-safe, integrated approach, for coping with the unusual predictable problems that arise while executing a program. Exception handling mechanism is to provide means to detect and report an exceptional circumstances. The mechanism suggests a separate error handling code. Easily we can detect errors and throw exceptions. (ii) Write a C++ program for the following.(12) (AUC DEC 2010) (1) A function to read two double type numbers from keyboard. (2) A function to calculate the division of these two numbers. (3)A try block to throw an exception when a wrong type of data is keyed in. (4) A try block to detect and throw an exception if the condition divide by zero occurs. (5)Appropriate catch block to handle the exceptions thrown. Ans: // Divide operation validation ( divide-by-zero) #include<iostream.h> class number int num; public: void read() cin>>num; class DIVIDE ; //abstract class used in exceptions int div(number num2) if(num2.num == 0) throw DIVIDE(); else return num/num2.num; ; int main() number num1,num2; int result; num1.read(); num2.read(); try cout<< trying division operator ; result=num1.div(num2); cout<< Succeeded ; catch(number:: DIVIDE) //actions taken in response to exception cout<< failed ; cout<< Exception divide-by-zero ; return1; //no exceptions; display result; cout<< num1/num2 = <<result; result 0; 7. Explain with an example, how exception handling is carried out in C++. (8) (AUC MAY 2011)

14 C++ exception handling mechanism is basically upon three keywords, namely, try, throw, and catch. try is used to preface a block of statements which may generate exceptions. throw - When an exception is detected, it is thrown using a throw statement in the try block. Catch- A catch block defined by the keyword catch catches the exception thrown by the thrown statement in the try block and handles its appropriately. The block throwing exception The catch block that catches an exception must immediately follow the try block that throws the exception. The general form of these two blocks are as follows: try.. throw exception;. catch (type arg).. //Block of statements detects and throws an exception // catches exception // block of statement that handle the exception When the try block throws an exception, the program control leaves the try block and enters the catch statement of the catch block. If the type of object thrown matches the arg type in the catch statement, then catch block is executed for handling the exception.

15 If they do not match the program is aborted with the help of abort() function which is invoked by default. When no exception is detected and thrown, the control goes to the statement immediately after the catch block. That is the catch block is skipped. 8. (i)write a class template to implement a stack. (10) (AUC MAY 2011) #include<iostream.h> using namesace std; template <typename ElementType> class Stack private: int Stackpointer; ElementType StackArray[10]; public: Stack() Stackpointer = 0; void push(elementtype value) if(stackpointer == 9) cout<< Stack Overflow! can t insert! ; else StackArray[Stackpointer] = value; Stackpointer++; ElementType pop() if(stackpointer == 0) cout<< Stack Underflow, can t pop ; else Stackpointer--; return StackArray[Stackpointer]; ;

16 void main() Stack < int> MyStack; MyStack.push(1); MyStack.push(2); cout<<mystack.pop()<< \n ; cout<<mystack.pop()<< \n ; Stack <char> YourStack; YourStack.pop( n ); YourStack.pop( o ); cout<<yourstack.pop()<< \n ; cout<<yourstack.pop()<< \n ; (ii) What is a user defined exception? Explain with an example. (6) (AUC MAY 2011) Answer: //Uncaught exception invokes abort() #include<iostream.h> class except1 ; class except2 ; void main() try cout<< Throwing uncaught exception <<endl; throw except2(); catch(except1) //true if throw except is executed in city scope cout<< Exception1 ; // except2 is not caught hence, program aborts //here without proceeding further cout<< Not displayed ; 9. (i)define a DivideBy Zero definition and use it to throw exceptions on attempts to divide by zero (8) (AUC MAY 2011) Program detects and catches a division-by-zero problem. The output of the first run shows a successful execution. When no exception is thrown, the catch block is skipped and execution resumes with the first line after the catch. In the second run, the denominator x becomes zero and therefore a division-by-zero situation occurs. Program: #include<iostream.h> using namespace std; int main() int a,b; cout<< Enter values of a and b ; cin>>a; cin>>b; int x = a-b;

17 try if(x!=0) cout<< Result (a/x) = << a/x << \n ; else // There is an exception throw(x); //Throws int object catch(int i) // Catches the exception cout<< Exception caught: DIVIDE BY ZERO \n ; cout<< END ; return 0; SAMPLE OUTPUT First run Enter values of a and b Result (a/x) = 4 END Second run Enter values of a and b Exception caught: DIVIDE BY ZERO END (ii)write a C++ program to demonstrate function template to print array of different types. (8) (AUC DEC 2011) Answer: #include<iostream.h> template<class T> void print (T a) for(int i=0;i<10;i++) cout<<a[i]; void main() int i; int a[10]; float b[10]; char c[10]; for(i=0;i<10;i++) cin>>a[i]; print (a); for(i=0;i<10;i++)

18 cin>>b[i]; print (b); cin>>c; print(c); 10. (i)describe class template with suitable example? (AUC DEC 2011) Refer Part B question number 1(ii) and 8(i) (ii)explain exception handling in C++ with suitable example? (AUC DEC 2011) Refer Part B question number 7(i) and 9.(i) 11. Give the syntax for function template. Write template function for bubble sort. Write a test program to illustrate its use. (AUC JUN 2012) Templates support generic programming which allows to develop reusable software components such as functions, classes,etc; Supporting different data types in a single framework. A template in C++ allows the construction of a family of template functions and classes to perform the same operation on different data types. The template declared for functions are called function templates and those declared for classes are called class templates. Like class template, we can also define function templates that could be used to create a family of functions with different argument types. The general format of function template is, template<class T> returntype functionname ( arguments of type T) // Body of function with type T wherever appropriate. The function template syntax is similar to that of the class template except that we are defining functions instead of classes. Program #include<iostream.h> using namespace std; template<class T> void bubble(t a[], int n) for(int i=0;i<n-1;i++) for(int j=n-1;i<j;j--) if(a[j] < a[j-1]) swap(a[j],a[j-1]); // Calls template function template<class X>

19 void swap(x &a, X &b) X temp = a; a=b; b = temp; int main() int x[5] = 10,50,30,40,20; float y[5] = 1.1,5.5,3.3,4.4,2.2; bubble(x,5); // Calls template functions for int values bubble(y,5); // Calls template functions for float values cout<< Sorted x-array ; for(int i=0;i<5;i++) cout<< x[i]<< ; cout<< endl; cout<< Sorted y-array: ; for(int j=0;j<5;j++) cout<<y[j]<< ; cout<<endl; return 0; OUTPUT: Sorted x-array : Sorted y-array : Discuss in detail about exception handling constructs and write a program to illustrate divide by zero exception.(16) (AUC JUN 2012/ DEC 2012) Answer: Exceptions refer to unusual conditions in a program. The unusual conditions could be faults, causing an error which it turn causes the program to fail. The error handling mechanism of C++ is generally reffered to as exception handling. It provides a straightforward mechanism for adding reliable error handling mechanism in a program. Exceptions are classified into two types. (i) Synchronous (ii) Asynchronous Synchronous The exceptions which occur during the program execution, due to some fault in the input-data or technique that is not suitable to handle the current class of data, within the program, are known as synchronous exceptions. Asynchronous Errors such as out-of-range, overflow, underflow and so on belong to the class of asynchronous exception. Refer PART-B question number 7(i) and 9(i) 13. Write a program for binary search as a generic function. The function should take arguments as array name, the size and element to be searched. (AUC DEC 2012) Answer: Binary search function template<typename T, typename compare_less> static int binary_search( QList<T>* list,t target)

20 int low=0; int high= list->count() -1; while( low<=high) int middle = low+ (high low)/2; if( compare_less(*target, *list[middle])) high = middle 1; else if ( Compare_less(*list[middle],*target)) low=middle + 1; else return middle; 14. Write a class template to generate a class Matrix automatically for a matrix of any particular type. Using the class template definition, the program should handle the arithmetic operations (+, -, *, /) for any particular type.(such as int, float, double, char) (AUC JUN 2013) Answer: #include<iostream.h> #include<conio.h> template<class T> class matrix T x[3] [3]; public: void getmatrix(); void showmatrix(); void addition(matrix<t>); void subtraction(matrix<t>); viod multiplication(matrix<t>,matrix<t>); ; template<class T> void matrix<t>::getmatrix() int i,j; cout<< enter values of amatrix ; for(i=0;i<3;i++) for(j=0;j<3;j++) cin>>x[i] [j]; template<class T> void matrix<t>::showmatrix() int i,j; cout<< matrix is ; for(j=0;j<3;j++)

21 cout<< \t <<x[i][j]; template<class T> void matrix<t>::addition(matrix<t> b) int i,j; for(i=0;i<3;i++) for(j=0;j<3;j++) x[i][j]=x[i][j]+b.x[i][j]; template<class T> void matrix<t>::subtraction(matrix<t> b) int i,j; for(i=0;i<3;i++) for(j=0;j<3;j++) x[i][j]=x[i][j]-b.x[i][j]; template<class T> void matrix<t>::multiplication(matrix<t> b, matrix<t> a) int i,j,k; for(i=0;i<3;i++) for(j=0;j<3;j++) x[i][j]=0; for(i=0;i<3;i++) for(j=0;j<3;j++) for(k=0;k<3;k++) x[i][j]=x[i][j]+(a.x[i][k]*b.x[k][j]); void main() int ch; matrix<int>a1,b1,c1; matrix<float>a2,b2,c2; clrscr(); do

22 cout<< \n\t 1> Addition (int) ; cout<< \n\t 2> Subtraction (int) ; cout<< \n\t 3> Multiplication(int) ; cout<< \n\t 4> Addition (float) ; cout<< \n\t 5> Subtraction (float) ; cout<< \n\t 6> Multiplication(float) ; cout<< \n\t enter your choice ; cin>>ch; switch(ch); case 1: a1.getmatrix(); a1.showmatrix(); b1.getmatrix(); b1.showmatrix(); a1.addition(b1); a1.showmatrix(); break; case 2: a1.getmatrix(); a1.showmatrix(); b1.getmatrix(); b1.showmatrix(); a1.subtraction(b1); a1.showmatrix(); break; case 3: a1.getmatrix(); a1.showmatrix(); b1.getmatrix(); b1.showmatrix(); a1.multiplication(b1,a1); a1.showmatrix(); break; case 4: a2.getmatrix(); a2.showmatrix(); b2.getmatrix(); b2.showmatrix(); a2.addition(b2); a2.showmatrix(); break; case 5: a2.getmatrix(); a2.showmatrix(); b2.getmatrix(); b2.showmatrix(); a2.subtraction(b2); a2.showmatrix(); break;

23 case 6: a2.getmatrix(); a2.showmatrix(); b2.getmatrix(); b2.showmatrix();c2.multiplication(b2,a2); c2.showmatrix(); break; while(ch!=7); getch(); 15. Explain the following concepts with example. (AUC JUN 2013) (i) try-catch-throw paradigm (ii) Exception Specification Refer Part-B question number 6(i), 7(i) and 9(i), Part-A question number Write a program 1. to show how to restrict the types of exceptions that can be thrown by a function. Refer Part-B question number 9.(i) 2. to show how to rethrow an exception. Refer Part A question number 15 and Part B question number 2(i).

TEMPLATES AND EXCEPTION HANDLING

TEMPLATES AND EXCEPTION HANDLING CONTENTS: Function template Class template Exception handling Try-Catch-Throw paradigm Exception specification Terminate functions Unexcepted functions Uncaught exception UNIT-III TEMPLATES AND EXCEPTION

More information

Templates and Exception Handling. Difference between Function template and class template

Templates and Exception Handling. Difference between Function template and class template 1 P a g e Templates and Exception Handling Introduction to function templates and class templates: Templates are the foundation of generic programming, which involves writing code in a way that is independent

More information

Sahaj Computer Solutions OOPS WITH C++

Sahaj Computer Solutions OOPS WITH C++ Chapter 8 1 Contents Introduction Class Template Class Templates with Multiple Paramters Function Templates Function Template with Multiple Parameters Overloading of Template Function Member Function Templates

More information

Functions. Introduction :

Functions. Introduction : Functions Introduction : To develop a large program effectively, it is divided into smaller pieces or modules called as functions. A function is defined by one or more statements to perform a task. In

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

Darshan Institute of Engineering & Technology for Diploma Studies

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

Programming in C++: Assignment Week 8

Programming in C++: Assignment Week 8 Programming in C++: Assignment Week 8 Total Marks : 20 September 9, 2017 Question 1 Consider the following code segment. Mark 2 void myfunction(int test) { try { if (test) throw test; else throw "Value

More information

Exceptions, Templates, and the STL

Exceptions, Templates, and the STL Exceptions, Templates, and the STL CSE100 Principles of Programming with C++, Fall 2018 (based off Chapter 16 slides by Pearson) Ryan Dougherty Arizona State University http://www.public.asu.edu/~redoughe/

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

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

Exceptions, Case Study-Exception handling in C++.

Exceptions, Case Study-Exception handling in C++. PART III: Structuring of Computations- Structuring the computation, Expressions and statements, Conditional execution and iteration, Routines, Style issues: side effects and aliasing, Exceptions, Case

More information

CHAPTER 4 FUNCTIONS. 4.1 Introduction

CHAPTER 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 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

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

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

! Errors can be dealt with at place error occurs

! Errors can be dealt with at place error occurs UCLA Stat 1D Statistical Computing and Visualization in C++ Instructor: Ivo Dinov, Asst. Prof. in Statistics / Neurology University of California, Los Angeles, Winter 200 http://www.stat.ucla.edu/~dinov/courses_students.html

More information

Exception with arguments

Exception with arguments Exception Handling Introduction : Fundamental Syntax for Exception Handling code : try catch throw Multiple exceptions Exception with arguments Introduction Exception: An abnormal condition that arises

More information

CSC 330 Object-Oriented Programming. Exception Handling CSC 330

CSC 330 Object-Oriented Programming. Exception Handling CSC 330 Object-Oriented Programming Exception Handling 1 C++ Exception Handling Topics Exception Handling C++ Exception Handling Basics Throwing and Catching Exceptions Constructors, Destructors and Exceptions

More information

CHRIST THE KING BOYS MATRIC HR. SEC. SCHOOL, KUMBAKONAM CHAPTER 9 C++

CHRIST THE KING BOYS MATRIC HR. SEC. SCHOOL, KUMBAKONAM CHAPTER 9 C++ CHAPTER 9 C++ 1. WRITE ABOUT THE BINARY OPERATORS USED IN C++? ARITHMETIC OPERATORS: Arithmetic operators perform simple arithmetic operations like addition, subtraction, multiplication, division etc.,

More information

Sample Paper Class XI Subject Computer Sience UNIT TEST II

Sample Paper Class XI Subject Computer Sience UNIT TEST II Sample Paper Class XI Subject Computer Sience UNIT TEST II (General OOP concept, Getting Started With C++, Data Handling and Programming Paradigm) TIME: 1.30 Hrs Max Marks: 40 ALL QUESTIONS ARE COMPULSURY.

More information

The format for declaring function templates with type parameters

The format for declaring function templates with type parameters UNIT 3 Function and class templates - Exception handling try-catch-throw paradigm exception specification terminate and Unexpected functions Uncaught exception. Templates Function templates Function templates

More information

Downloaded from

Downloaded 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 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

CS201 Some Important Definitions

CS201 Some Important Definitions CS201 Some Important Definitions For Viva Preparation 1. What is a program? A program is a precise sequence of steps to solve a particular problem. 2. What is a class? We write a C++ program using 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

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

1. Answer the following : a) What do you mean by Open Source Software. Give an example. (2)

1. Answer the following : a) What do you mean by Open Source Software. Give an example. (2) THE AIR FORCE SCHOOL Class XI First Terminal Examination 2017-18 Computer Science (083) Time: 3 hrs. M. Marks : 70 General Instructions : (i) All the questions are compulsory. (ii) Programming Language

More information

PART I. Part II Answer to all the questions 1. What is meant by a token? Name the token available in C++.

PART I.   Part II Answer to all the questions 1. What is meant by a token? Name the token available in C++. Unit - III CHAPTER - 9 INTRODUCTION TO C++ Choose the correct answer. PART I 1. Who developed C++? (a) Charles Babbage (b) Bjarne Stroustrup (c) Bill Gates (d) Sundar Pichai 2. What was the original name

More information

Before we start - Announcements: There will be a LAB TONIGHT from 5:30 6:30 in CAMP 172. In compensation, no class on Friday, Jan. 31.

Before we start - Announcements: There will be a LAB TONIGHT from 5:30 6:30 in CAMP 172. In compensation, no class on Friday, Jan. 31. Before we start - Announcements: There will be a LAB TONIGHT from 5:30 6:30 in CAMP 172 The lab will be on pointers In compensation, no class on Friday, Jan. 31. 1 Consider the bubble function one more

More information

Introduction to C++ Friends, Nesting, Static Members, and Templates Topic #7

Introduction to C++ Friends, Nesting, Static Members, and Templates Topic #7 Introduction to C++ Friends, Nesting, Static Members, and Templates Topic #7 CS202 7-1 Relationship of Objects Friends, Nesting Static Members Template Functions and Classes Reusing Code Template Specializations

More information

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

Chapter 16: Exceptions, Templates, and the Standard Template Library (STL)

Chapter 16: Exceptions, Templates, and the Standard Template Library (STL) Chapter 16: Exceptions, Templates, and the Standard Template Library (STL) 6.1 Exceptions Exceptions Indicate that something unexpected has occurred or been detected Allow program to deal with the problem

More information

2. Distinguish between a unary, a binary and a ternary operator. Give examples of C++ operators for each one of them.

2. 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 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

DELHI PUBLIC SCHOOL TAPI

DELHI 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 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

Basic 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 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

21. Exceptions. Advanced Concepts: // exceptions #include <iostream> using namespace std;

21. Exceptions. Advanced Concepts: // exceptions #include <iostream> using namespace std; - 147 - Advanced Concepts: 21. Exceptions Exceptions provide a way to react to exceptional circumstances (like runtime errors) in our program by transferring control to special functions called handlers.

More information

Lab Instructor : Jean Lai

Lab Instructor : Jean Lai Lab Instructor : Jean Lai Group related statements to perform a specific task. Structure the program (No duplicate codes!) Must be declared before used. Can be invoked (called) as any number of times.

More information

Bangalore South Campus

Bangalore 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 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

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

This can be thrown by dynamic_cast. This is useful device to handle unexpected exceptions in a C++ program

This can be thrown by dynamic_cast. This is useful device to handle unexpected exceptions in a C++ program Abstract class Exception handling - Standard libraries - Generic Programming - templates class template - function template STL containers iterators function adaptors allocators -Parameterizing the class

More information

Le L c e t c ur u e e 5 To T p o i p c i s c t o o b e b e co c v o e v r e ed e Exception Handling

Le L c e t c ur u e e 5 To T p o i p c i s c t o o b e b e co c v o e v r e ed e Exception Handling Course Name: Advanced Java Lecture 5 Topics to be covered Exception Handling Exception HandlingHandlingIntroduction An exception is an abnormal condition that arises in a code sequence at run time A Java

More information

Page. 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 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 information

AP COMPUTER SCIENCE JAVA CONCEPTS IV: RESERVED WORDS

AP COMPUTER SCIENCE JAVA CONCEPTS IV: RESERVED WORDS AP COMPUTER SCIENCE JAVA CONCEPTS IV: RESERVED WORDS PAUL L. BAILEY Abstract. This documents amalgamates various descriptions found on the internet, mostly from Oracle or Wikipedia. Very little of this

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

Padasalai.Net s Model Question Paper

Padasalai.Net s Model Question Paper Padasalai.Net s Model Question Paper STD: XII VOLUME - 2 MARKS: 150 SUB: COMPUTER SCIENCE TIME: 3 HRS PART I Choose the correct answer: 75 X 1 = 75 1. Which of the following is an object oriented programming

More information

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

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): 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 information

Cpt S 122 Data Structures. Templates

Cpt S 122 Data Structures. Templates Cpt S 122 Data Structures Templates Nirmalya Roy School of Electrical Engineering and Computer Science Washington State University Topics Introduction Function Template Function-template and function-template

More information

CAMBRIDGE SCHOOL, NOIDA ASSIGNMENT 1, TOPIC: C++ PROGRAMMING CLASS VIII, COMPUTER SCIENCE

CAMBRIDGE SCHOOL, NOIDA ASSIGNMENT 1, TOPIC: C++ PROGRAMMING CLASS VIII, COMPUTER SCIENCE CAMBRIDGE SCHOOL, NOIDA ASSIGNMENT 1, TOPIC: C++ PROGRAMMING CLASS VIII, COMPUTER SCIENCE a) Mention any 4 characteristic of the object car. Ans name, colour, model number, engine state, power b) What

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

SBOA SCHOOL & JUNIOR COLLEGE, CHENNAI 101 COMPUTER SCIENCE CLASS: XI HALF YEARLY EXAMINATION MAX MARKS:70 CODE - A DURATION : 3 Hours

SBOA SCHOOL & JUNIOR COLLEGE, CHENNAI 101 COMPUTER SCIENCE CLASS: XI HALF YEARLY EXAMINATION MAX MARKS:70 CODE - A DURATION : 3 Hours SBOA SCHOOL & JUNIOR COLLEGE, CHENNAI 101 COMPUTER SCIENCE CLASS: XI HALF YEARLY EXAMINATION 2016 MAX MARKS:70 CODE - A DURATION : 3 Hours All questions are compulsory. Do not change the order of the questions

More information

GE U111 Engineering Problem Solving & Computation Lecture 6 February 2, 2004

GE U111 Engineering Problem Solving & Computation Lecture 6 February 2, 2004 GE U111 Engineering Problem Solving & Computation Lecture 6 February 2, 2004 Functions and Program Structure Today we will be learning about functions. You should already have an idea of their uses. Cout

More information

EAS 230 Fall 2002 Section B

EAS 230 Fall 2002 Section B EAS 230 Fall 2002 Section B Exam #2 Name: Person Number: Instructions: ƒ Total points are 100, distributed as shown by [ ]. ƒ Duration of the Exam is 50 minutes. I ) State whether True or False [25] Indicate

More information

PESIT Bangalore South Campus Hosur road, 1km before Electronic City, Bengaluru -100 Department of Electronics and Communication

PESIT Bangalore South Campus Hosur road, 1km before Electronic City, Bengaluru -100 Department of Electronics and Communication INTERNAL ASSESSMENT TEST 1 Date : 28.2.2018 Marks: 40 Subject & Code : DataStructures Using C++ (15EC661) Sem : VI A,B,C Name of faculty : Vandana M L Time : 11:30-1:00 PM Note: Answer FIVE full questions,

More information

Chapter-13 USER DEFINED FUNCTIONS

Chapter-13 USER DEFINED FUNCTIONS Chapter-13 USER DEFINED FUNCTIONS Definition: User-defined function is a function defined by the user to solve his/her problem. Such a function can be called (or invoked) from anywhere and any number of

More information

DE122/DC106 Object Oriented Programming with C++ DEC 2014

DE122/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 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

ADARSH VIDYA KENDRA NAGERCOIL COMPUTER SCIENCE. Grade: IX C++ PROGRAMMING. Department of Computer Science 1

ADARSH VIDYA KENDRA NAGERCOIL COMPUTER SCIENCE. Grade: IX C++ PROGRAMMING. Department of Computer Science 1 NAGERCOIL COMPUTER SCIENCE Grade: IX C++ PROGRAMMING 1 C++ 1. Object Oriented Programming OOP is Object Oriented Programming. It was developed to overcome the flaws of the procedural approach to programming.

More information

CS35 - Object Oriented Programming

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

! An exception is a condition that occurs at execution time and makes normal continuation of the program impossible.

! An exception is a condition that occurs at execution time and makes normal continuation of the program impossible. Exceptions! Exceptions are used to signal error or unexpected events that occur while a program is running.! An exception is a condition that occurs at execution time and makes normal continuation of the

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

Exception Handling Pearson Education, Inc. All rights reserved.

Exception Handling Pearson Education, Inc. All rights reserved. 1 16 Exception Handling 2 16.1 Introduction Exceptions Indicate problems that occur during a program s execution Occur infrequently Exception handling Can resolve exceptions Allow a program to continue

More information

COMPUTER SCIENCE (083)

COMPUTER SCIENCE (083) Roll No. Code : 112012-083 Please check that this question paper contains 7 questions and 8 printed pages. CLASS-XI COMPUTER SCIENCE (083) Time Allowed : 3 Hrs. Maximum Marks : 70 General Instructions

More information

Programming in C++: Assignment Week 8

Programming in C++: Assignment Week 8 Programming in C++: Assignment Week 8 Total Marks : 20 Partha Pratim Das Department of Computer Science and Engineering Indian Institute of Technology Kharagpur 721302 partha.p.das@gmail.com April 12,

More information

Module Operator Overloading and Type Conversion. Table of Contents

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

Exception Handling in C++

Exception Handling in C++ Exception Handling in 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

More information

DEPT : ECE SUB CODE : EC6301

DEPT : ECE SUB CODE : EC6301 SEM/YEAR : III / II DEPT : ECE SUB CODE : EC6301 SUB NAME : ODS UNIT I- OBJECT ORIENTED PROGRAMMING and DATA STRUCTURES QUESTION BANK WITH ANSWER PART A 1. What is the output of the following program,

More information

THE 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.

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

1. FIBONACCI SERIES. Write a C++ program to generate the Fibonacci for n terms. To write a C++ program to generate the Fibonacci for n terms.

1. FIBONACCI SERIES. Write a C++ program to generate the Fibonacci for n terms. To write a C++ program to generate the Fibonacci for n terms. PROBLEM: 1. FIBONACCI SERIES Write a C++ program to generate the Fibonacci for n terms. AIM: To write a C++ program to generate the Fibonacci for n terms. PROGRAM CODING: #include #include

More information

Sample Paper - II Subject Computer Science

Sample Paper - II Subject Computer Science Sample Paper - II Subject Computer Science Max Marks 70 Duration 3 hrs Note:- All questions are compulsory Q1) a) What is significance of My Computer? 2 b) Explain different types of operating systems.

More information

TEMPLATE IN C++ Function Templates

TEMPLATE IN C++ Function Templates TEMPLATE IN C++ Templates are powerful features of C++ which allows you to write generic programs. In simple terms, you can create a single function or a class to work with different data types using templates.

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

Informatica 3. Marcello Restelli. Laurea in Ingegneria Informatica Politecnico di Milano 9/15/07 10/29/07

Informatica 3. Marcello Restelli. Laurea in Ingegneria Informatica Politecnico di Milano 9/15/07 10/29/07 Informatica 3 Marcello Restelli 9/15/07 10/29/07 Laurea in Ingegneria Informatica Politecnico di Milano Structuring the Computation Control flow can be obtained through control structure at instruction

More information

POINTERS - 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 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

Exceptions. Why Exception Handling?

Exceptions. Why Exception Handling? Exceptions An exception is an object that stores information transmitted outside the normal return sequence. It is propagated back through calling stack until some function catches it. If no calling function

More information

Creating a C++ Program

Creating a C++ Program Program A computer program (also software, or just a program) is a sequence of instructions written in a sequence to perform a specified task with a computer. 1 Creating a C++ Program created using an

More information

Problem Solving with C++

Problem Solving with C++ GLOBAL EDITION Problem Solving with C++ NINTH EDITION Walter Savitch Kendrick Mock Ninth Edition PROBLEM SOLVING with C++ Problem Solving with C++, Global Edition Cover Title Copyright Contents Chapter

More information

3. Functions. Modular programming is the dividing of the entire problem into small sub problems that can be solved by writing separate programs.

3. Functions. Modular programming is the dividing of the entire problem into small sub problems that can be solved by writing separate programs. 1 3. Functions 1. What are the merits and demerits of modular programming? Modular programming is the dividing of the entire problem into small sub problems that can be solved by writing separate programs.

More information

Get Unique study materials from

Get Unique study materials from Downloaded from www.rejinpaul.com VALLIAMMAI ENGNIEERING COLLEGE SRM Nagar, Kattankulathur 603203. DEPARTMENT OF COMPUTER SCIENCE AND ENGINEERING Year & Semester : IV Section : EEE - 1 & 2 Subject Code

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

7 TEMPLATES AND STL. 7.1 Function Templates

7 TEMPLATES AND STL. 7.1 Function Templates 7 templates and STL:: Function Templates 7 TEMPLATES AND STL 7.1 Function Templates Support generic programming functions have parameterized types (can have other parameters as well) functions are instantiated

More information

Functions in C++ Problem-Solving Procedure With Modular Design C ++ Function Definition: a single

Functions in C++ Problem-Solving Procedure With Modular Design C ++ Function Definition: a single Functions in C++ Problem-Solving Procedure With Modular Design: Program development steps: Analyze the problem Develop a solution Code the solution Test/Debug the program C ++ Function Definition: A module

More information

C++ 8. Constructors and Destructors

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

6.096 Introduction to C++ January (IAP) 2009

6.096 Introduction to C++ January (IAP) 2009 MIT OpenCourseWare http://ocw.mit.edu 6.096 Introduction to C++ January (IAP) 2009 For information about citing these materials or our Terms of Use, visit: http://ocw.mit.edu/terms. Welcome to 6.096 Lecture

More information

Chapter-11 POINTERS. Important 3 Marks. Introduction: Memory Utilization of Pointer: Pointer:

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

Cpt S 122 Data Structures. Introduction to C++ Part II

Cpt S 122 Data Structures. Introduction to C++ Part II Cpt S 122 Data Structures Introduction to C++ Part II Nirmalya Roy School of Electrical Engineering and Computer Science Washington State University Topics Objectives Defining class with a member function

More information

Variables. Data Types.

Variables. Data Types. Variables. Data Types. The usefulness of the "Hello World" programs shown in the previous section is quite questionable. We had to write several lines of code, compile them, and then execute the resulting

More information

G52CPP C++ Programming Lecture 16

G52CPP C++ Programming Lecture 16 G52CPP C++ Programming Lecture 16 Dr Jason Atkin http://www.cs.nott.ac.uk/~jaa/cpp/ g52cpp.html 1 Last Lecture Casting static cast dynamic cast const cast reinterpret cast Implicit type conversion 2 How

More 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

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

Assoc. Prof. Marenglen Biba. (C) 2010 Pearson Education, Inc. All rights reserved.

Assoc. Prof. Marenglen Biba. (C) 2010 Pearson Education, Inc. All rights reserved. Assoc. Prof. Marenglen Biba Exception handling Exception an indication of a problem that occurs during a program s execution. The name exception implies that the problem occurs infrequently. With exception

More information

C++ Programming: From Problem Analysis to Program Design, Third Edition

C++ Programming: From Problem Analysis to Program Design, Third Edition C++ Programming: From Problem Analysis to Program Design, Third Edition Chapter 2: Basic Elements of C++ Objectives (continued) Become familiar with the use of increment and decrement operators Examine

More information

Programming II (CS300)

Programming II (CS300) 1 Programming II (CS300) Chapter 04: Exception Handling MOUNA KACEM mouna@cs.wisc.edu Fall 2018 Creating Classes 2 Introduction Exception Handling Common Exceptions Exceptions with Methods Assertions and

More information

Pace University. Fundamental Concepts of CS121 1

Pace University. Fundamental Concepts of CS121 1 Pace University Fundamental Concepts of CS121 1 Dr. Lixin Tao http://csis.pace.edu/~lixin Computer Science Department Pace University October 12, 2005 This document complements my tutorial Introduction

More information

2. How many runtime error messages associated with exception? a) 2 b) 4 c) 5 d) infinite

2. How many runtime error messages associated with exception? a) 2 b) 4 c) 5 d) infinite 2. How many runtime error messages associated with exception? a) 2 b) 4 c) 5 d) infinite Answer:c Explanation:There are five runtime error messages associated with exceptions.they are no handler for the

More information

Programming. C++ Basics

Programming. C++ Basics Programming C++ Basics Introduction to C++ C is a programming language developed in the 1970s with the UNIX operating system C programs are efficient and portable across different hardware platforms C++

More information

Exception Handling Pearson Education, Inc. All rights reserved.

Exception Handling Pearson Education, Inc. All rights reserved. 1 16 Exception Handling 2 I never forget a face, but in your case I ll make an exception. Groucho Marx It is common sense to take a method and try it. If it fails, admit it frankly and try another. But

More information