DHANALAKSHMI COLLEGE OF ENGINEERING, CHENNAI

Size: px
Start display at page:

Download "DHANALAKSHMI COLLEGE OF ENGINEERING, CHENNAI"

Transcription

1 DHANALAKSHMI COLLEGE OF ENGINEERING, CHENNAI Department of Computer Science and Engineering CS6202 PROGRAMMING DATA STRUCTURES II Anna University 2 & 16 Mark Questions & Answers Year / Semester: II / III Regulation: 2013 Academic year:

2 UNIT III Part A 1. Distinguish the term template class and class template. [M/J 16] A class that has generic definition or a class with parameters which is not instantiated until the information is provided by the client. It is referred to a jargon for plain templates. Example: someclasssc; // someclass is an ordinary(non-template) class someclass<int.sc; //someclass<int>is a template class The individual construction of a class is specified by a class template which is almost similar the way how individual objects are constructed by using a class. It is referred to a jargon for plain classes. Example: template<typename t> class someclass ;//this is a template class template<typename t> intsome_function(t&).. //this is a function template 2. List out the types of containers. [M/J 16] Two basic types of containers: Sequences o User controls the order of elements. o vector, list, deque

3 Associative containers o The container controls the position of elements within it. o Elements can be accessed using a key. o set, multiset, map, multimap 3. What is an abstract class? [N/D-16] An abstract class is a class that is designed to be specifically used as a base class. An abstract class contains at least one pure virtual function. You declare a pure virtual function by using a pure specifier (= 0) in the declaration of a virtual member function in the class declaration. The following is an example of an abstract class: class AB public: virtual void f() = 0; ; Function AB::f is a pure virtual function. 4. What is a function adaptor? [N/D-16] A function adaptor is an instance of a class that adapts a namespace-scope or member function so that the function can be used as a function object. A function adaptor may also be used to alter the behavior of a function or function object. Each function adaptor defined by the C++ Standard Library provides a constructor that takes a namespace-scope or member function. The adaptor also defines a function call operator that forwards its call to that associated global or member function. 5. Give the various file stream classes needed for file manipulation. [ M/J 15] filebuf fstreambase ifstream ofstream fstream 6. Is Abstract base class, used to create objects? Justify your answer in brief. [ M/J 15] No. simply abstract class contains abstract methods(means the functions which are without the body) and we cannot give functionality to the abstract methods. And if we try to give functionality to the abstract methods then there will be no difference between abstract class and virtual class. So lastly if we create an object Of an abstrast class then there is no fun to call the

4 useless functions or abstract methods as they are without the functionality..sothats why any language doesnt allow us to create an object of an abstract class. 7. Compare overloaded functions versus function templates. [N/D-15] A function template works in a similar to a normal function, with one key difference. A single function template can work with different data types at once but, a single normal function can only work with one set of data types. Normally, if you need to perform identical operations on two or more types of data, you use function overloading to create two functions with the required function declaration. the sum function template defined above can be called with: x = sum<int>(10,20); The function sum<int> is just one of the possible instantiations of function template sum. In this case, by using int as template argument in the call, the compiler automatically instantiates a version of sum where each occurrence of SomeType is replaced by int, as if it was defined as: int sum (int a, int b) returna+b; 8. Giveanexampleonfunctiontemplate. [N/D-14] #include<iostream> usingnamespacestd; // template function template<class T> T Large(T n1, T n2) return(n1 > n2)?n1 : n2; int main() int i1, i2; float f1, f2; char c1, c2;

5 cout<<"enter two integers:\n"; cin>> i1 >> i2; cout<<large(i1, i2)<<" is larger."<<endl; cout<<"\nenter two floating-point numbers:\n"; cin>> f1 >> f2; cout<<large(f1, f2)<<" is larger."<<endl; cout<<"\nenter two characters:\n"; cin>> c1 >> c2; cout<<large(c1, c2)<<" has larger ASCII value."; return0; 9. What isthe significanceofiterators? [N/D-14] Iterators are used to step through the elements of collections of objects. These collections may be containers or subsets of containers. Functions in iterartors advance-it advances the iterator it by n element positions. distance-it returns distance between iterators. begin-it is used to begin an iterator. end-it is used to end an iterator. prev-it is used to get iterator to previous element. next-it is used to get iterator to next element.

6 Part - B 1. Write a class template to represent a queue of any possible data type(8) [M/J 16 ] #include<iostream> #include<string> using namespace std; template<typename T> voidprint_mydata(t output) cout<< "Output value: " << output <<endl; int main() int i=5; double d=5.5; string s("hello World"); bool b=true; print_mydata(i); // T is int print_mydata(d); // T is double print_mydata(s); // T is string print_mydata(b); // T is bool return 0; As we said before, templates are expanded by the compiler in as many definitions as the function calls of the different types used. Data-types are represented by a common name, which is replaced by different actual data-type by the compiler, during compilation. Data-types used by the compiler, are evaluated using the function calls made by the programmer in the program. In the example above, the compiler will create four definitions of the print_mydata function as follows (as per the function call): voidprint_mydata(int output) cout<< "The value is: " << output <<endl;

7 voidprint_mydata(double output) cout<< "The value is: " << output <<endl; voidprint_mydata(string output) cout<< "The value is: " << output <<endl; voidprint_mydata(bool output) cout<< "The value is: " << output <<endl; Note: As you can see, only the type of the parameter output is changing. For function templates, there are two options to specify the template parameters. template<typename T> voidmy_function() int main() my_function<int>(2); my_function<double>(2.1); Or we could do this (like we did in the first example print_mydata): template<typename T> voidmy_function(t value) int main()

8 //T = int my_function(2); //T = double my_function(2.1); The following points you could also do with template functions: a) One template function can use more than one generic type. We could say: template(typename T, typename T1) b) We can use specific data-types along with the generic types in the function templates. So for example: template<typename T> voidprint_mydata(t output, int a) So if we call print_mydata from main it should be something like this: int i=5; double d=5.5; print_mydata(i, 5); print_mydata(d, 5); Note: The second parameter should always be an integer. c) We can overload the function templates (by creating another overloaded template function of the same name).

9 2. Illustrate about how exceptions are handled using multiple catch handlers.(8) [M/J 16 ] 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( ExceptionNameeN ) // catch block You can list down multiple catch statements to catch different type of exceptions in case your try block raises more than one exception in different situations. #include<iostream.h> #include<conio.h>

10 void test(int x) try if(x>0) throw x; else throw 'x'; catch(int x) cout<<"catch a integer and that integer is:"<<x; catch(char x) cout<<"catch a character and that character is:"<<x; void main() clrscr(); cout<<"testing multiple catches\n:"; test(10); test(0); getch(); Output: Testing multiple catches Catch a integer and that integer is: 10 Catch a character and that character is: x

11 3. Explain the components of STL.(8) [M/J 16] (13) [N/D-16] (6) [M/J 15](8)[N/D-15] 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. At the core of the C++ Standard Template Library are following three well-structured components: Component Containers Algorithms Iterators 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. We will discuss about all the three C++ STL components in next chapter while discussing C++ Standard Library. For now, keep in mind that all the three components have a rich set of predefined functions which help us in doing complicated tasks in very easy fashion. Let us take the following program demonstrates the vector container (a C++ Standard Template) which is similar to an array with an exception that it automatically handles its own storage requirements in case it grows: #include<iostream> #include<vector> usingnamespacestd; int main() // create a vector to store int vector<int>vec; int i; // display the original size of vec cout<<"vector size = "<<vec.size()<<endl;

12 // push 5 values into the vector for(i =0; i <5; i++) vec.push_back(i); // display extended size of vec cout<<"extended vector size = "<<vec.size()<<endl; // access 5 values from the vector for(i =0; i <5; i++) cout<<"value of vec ["<< i <<"] = "<<vec[i]<<endl; // use iterator to access the values vector<int>::iterator v =vec.begin(); while( v!=vec.end()) cout<<"value of v = "<<*v <<endl; v++; return0; When the above code is compiled and executed, it produces the following result: vector size = 0 extended vector size = 5 value of vec [0] = 0 value of vec [1] = 1 value of vec [2] = 2 value of vec [3] = 3 value of vec [4] = 4 value of v = 0 value of v = 1 value of v = 2 value of v = 3 value of v = 4

13 Here are following points to be noted related to various functions we used in the above example: The push_back( ) member function inserts value at the end of the vector, expanding its size as needed. The size( ) function displays the size of the vector. The function begin( ) returns an iterator to the start of the vector. The function end( ) returns an iterator to the end of the vector. 4. Write a C++ program that reads a text file and creates another file that is identical except that every sequence of consecutive blank spaces is replaced by a single space. (8) [M/J 16 ] #include<fstream.h> #include<iostream.h> #include<process.h> #include<conio.h> void main() clrscr(); ifstream file1; ofstream file2; charsfile[13],tfile[13]; cout<<"\nenter Source file name-"; cin>>sfile; cout<<"\nenter Target file name-"; cin>>tfile; file2.open(sfile); file2<<"\nmy Name is RAHUL KUMAR"<<endl; file2.close(); file1.open(sfile); file2.open(tfile); if(!file1) cerr<<" Some Error.."; exit(1); charvarch,p=file1.get(); while(!file1.eof()) file2.put(p); varch=file1.get();

14 if(p==' ' &&varch==' ') p=varch; varch=file1.get(); p=varch; cout<<"\ncopied..."; file1.close(); file2.close(); cout<<"\ntarget File Contents...\n"; file1.open(tfile); while(!file1.eof()) file1.get(varch); cout<<varch; file1.close(); getch(); /* OUTPUT Enter Source file name-source Enter Target file name-target copied... Target File Contents... My Name is RAHUL KUMAR */

15 5. Write short notes on C++ exception handling. (7) [N/D-16] (4) [M/J 15] 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( ExceptionNameeN ) // catch block You can list down multiple catch statements to catch different type of exceptions in case your try block raises more than one exception in different situations.

16 Throwing Exceptions Exceptions can be thrown anywhere within a code block using throw statements. The operand of the throw statements determines a type for the exception and can be any expression and the type of the result of the expression determines the type of exception thrown. Following is an example of throwing an exception when dividing by zero condition occurs: double division(int a, int b) if( b == 0 ) throw "Division by zero condition!"; return (a/b); Catching Exceptions The catch block following the try block catches any exception. You can specify what type of exception you want to catch and this is determined by the exception declaration that appears in parentheses following the keyword catch. try // protected code catch( ExceptionName e ) // code to handle ExceptionName exception Above code will catch an exception of ExceptionName type. If you want to specify that a catch block should handle any type of exception that is thrown in a try block, you must put an ellipsis,..., between the parentheses enclosing the exception declaration as follows: try // protected code catch(...) // code to handle any exception The following is an example, which throws a division by zero exception and we catch it in catch block. #include <iostream> using namespace std;

17 double division(int a, int b) if( b == 0 ) throw "Division by zero condition!"; return (a/b); int main () int x = 50; int y = 0; double z = 0; try z = division(x, y); cout<< z <<endl; catch (const char* msg) cerr<<msg<<endl; return 0; Because we are raising an exception of type const char*, so while catching this exception, we have to use const char* in catch block. If we compile and run above code, this would produce the following result: Division by zero condition! C++ Standard Exceptions C++ provides a list of standard exceptions defined in <exception> which we can use in our programs. These are arranged in a parent-child class hierarchy shown below:

18 Here is the small description of each exception mentioned in the above hierarchy: Exception std::exception std::bad_alloc std::bad_cast std::bad_exception std::bad_typeid std::logic_error std::domain_error Description An exception and parent class of all the standard C++ exceptions. This can be thrown by new. This can be thrown by dynamic_cast. This is useful device to handle unexpected exceptions in a C++ program This can be thrown by typeid. An exception that theoretically can be detected by reading the code. This is an exception thrown when a mathematically invalid domain is used std::invalid_argument This is thrown due to invalid arguments. std::length_error std::out_of_range This is thrown when a too big std::string is created This can be thrown by the at method from for example a std::vector and

19 std::runtime_error std::overflow_error std::range_error std::underflow_error std::bitset<>::operator[](). An exception that theoretically can not be detected by reading the code. This is thrown if a mathematical overflow occurs. This is occured when you try to store a value which is out of range. This is thrown if a mathematical underflow occurs. Define New Exceptions You can define your own exceptions by inheriting and overriding exception class functionality. Following is the example, which shows how you can use std::exception class to implement your own exception in standard way: #include <iostream> #include <exception> using namespace std; structmyexception : public exception const char * what () const throw () return "C++ Exception"; ; int main() try throwmyexception(); catch(myexception& e) std::cout<< "MyException caught" <<std::endl; std::cout<<e.what() <<std::endl; catch(std::exception& e) //Other errors This would produce the following result: MyException caught C++ Exception Here, what() is a public method provided by exception class and it has been overridden by all the child exception classes. This returns the cause of an exception.

20 6. Write a C++ program to write a set of characters to a file. (6 )[N/D- #include <iostream> #include <fstream> usingnamespacestd; int main() ifstream fin; fin.open("my-input-file.txt", ios::in); charmy_character ; intnumber_of_lines = 0; while (!fin.eof() ) fin.get(my_character); cout<<my_character; if (my_character == '\n') ++number_of_lines; cout<<"number OF LINES: "<<number_of_lines<<endl;

21 7. Write a program to implement stack operations using class template. (8) [M/J 15] #include<iostream> using namespace std; template<class T> class stack T* arr; static int top; public: stack(int); void push(t); T pop(); bool empty(); ; template<class T> int stack<t>::top = -1; template<class T> stack<t>::stack(int x) this->arr = new T(x); template<class T> void stack<t>::push(t a) this->arr[++top] = a; template<class T> T stack<t>::pop() T a = this->arr[top--]; return a; template<class T> bool stack<t>::empty() return (top==-1); int main()

22 stack<int> s(10); int i; for(i=0;i<10;i++) s.push(i); while(!s.empty()) cout<<s.pop()<<endl; return 0; 8. Write a template function to sort the elements of an array. (4) [M/J 15] #include <iostream> #include <time.h> #include <string> #include <iomanip> usingnamespacestd; template<class Item> voidbubble_sort(item a[], size_t size); template<class Item> void swap(item& a, Item& b); template<class Item> voiddisplay_array(item randnum, size_t size); int main() int *randnum; inta,b; int size; swap(item& a, Item& b); //NOT SURE IF WORKS YET, UNTESTED srand((unsigned)time(null)); cout<<"how many integers?"<<endl; cin>> size; size = size +1; randnum = newint [size]; for (int i = 1; i < size; i++) randnum[i] = 1+ rand() % 10;

23 display_array(randnum, size); cout<<"\n \n sorted..."<<endl; bubble_sort( a[], size); //ERROR //display_array(randnum, size); system("pause"); return 0; //============================= template<class Item> voidbubble_sort(item a[], size_t size) size_tidx, pass; for (pass=1; pass<=size; ++pass) for (idx=0; idx<=size-2; ++idx) if (a[idx] > a[idx+1]) swap(a[idx], a[idx+1]); template<class Item> void swap(item& a, Item& b) Item temp; temp = a; a = b; b = temp; template<class Item> voiddisplay_array(item randnum, size_t size) for ( int j = 1; j < size; j++ ) cout<<setw(16) <<randnum[ j ];

24 9.Write a program to write the text in a file. Read the text from the file, end of the file. Display the contents of file in reverse order. Append the contents to the existing file. Writing Data to a File #include <iostream> #include <string> #include <fstream> using namespace std; int main() ofstreamofileobject; // Create Object of Ofstream OFileObject.open ("D:\\ExampleFile.txt"); // Opening a File or creating if not present OFileObject<< "I am writing to a file opened from program.\n"; // Writing data to file cout<<"data has been written to file"; OFileObject.close(); // Closing the file Appending Data to an Existing File #include <iostream> #include <string> #include <fstream> using namespace std; int main() ofstreamofileobject; // Create Object of Ofstream OFileObject.open ("D:\\ExampleFile.txt", ios::app); // Append mode OFileObject<< "I am writing to a file opened from program.\n"; // Writing data to file cout<<"data has been appended to file"; OFileObject.close(); // Closing the file Reading Data from File #include <iostream> #include <fstream> #include <string> using namespace std; int main() stringlinesread; ifstreamifileobject ("D:\\ExampleFile.txt"); (10) [M/J 15]

25 if (IFileObject.is_open()) while ( getline (IFileObject, linesread) ) cout<<linesread<<endl; IFileObject.close(); elsecout<< "File cannot be read"; Reversing a file content #include <iostream> #include <fstream> #include <cstdlib> using namespace std; int main(intargc, char *argv[]) fstreaminout("test.txt", ios::in ios::out ios::binary); if(!inout) cout<< "Cannot open input file.\n"; return 1; long e, i, j; char c1, c2; e = 5; for(i=0, j=e; i<j; i++, j--) inout.seekg(i, ios::beg); inout.get(c1); inout.seekg(j, ios::beg); inout.get(c2); inout.seekp(i, ios::beg); inout.put(c2); inout.seekp(j, ios::beg); inout.put(c1); inout.close(); return 0;

26 10. Write a function template for finding the maximum value in an array. (8) [N/D-15] #include <iostream.h> #include <conio.h> template<class T> T findmin(t arr[],int n) int i; T min; min=arr[0]; for(i=0;i<n;i++) if(min >arr[i]) min=arr[i]; return(min); void main() clrscr(); intiarr[5]; charcarr[5]; doubledarr[5]; cout<<"integer Values \n"; for(int i=0; i < 5; i++) cout<<"enter integer value "<< i+1 <<" : "; cin>>iarr[i]; cout<<"character values \n"; for(int j=0; j < 5; j++) cout<<"enter character value "<< j+1 <<" : "; cin>>carr[j];

27 cout<<"decimal values \n"; for(int k=0; k < 5; k++) cout<<"enter decimal value "<< k+1 <<" : "; cin>>darr[k]; //calling Generic function...to find minimum value. cout<<"generic Function to find Minimum from Array\n\n"; cout<<"integer Minimum is : "<<findmin(iarr,5)<<"\n"; cout<<"character Minimum is : "<<findmin(carr,5)<<"\n"; cout<<"double Minimum is : "<<findmin(darr,5)<<"\n"; getch(); 11. Write a C++ program to handle a divide by zero exception. (8 )[N/D-15] #include<iostream.h> #include<conio.h> void main() inta,b,c; float d; clrscr(); cout<<"enter the value of a:"; cin>>a; cout<<"enter the value of b:"; cin>>b; cout<<"enter the value of c:"; cin>>c; try if((a-b)!=0) d=c/(a-b); cout<<"result is:"<<d; else

28 throw(a-b); catch(int i) cout<<"answer is infinite because a-b is:"<<i; getch(); Output: Enter the value for a: 20 Enter the value for b: 20 Enter the value for c: 40 Answer is infinite because a-b is: Write a class template to represent a stack of any possible data type. (8) [N/D-15] #include<iostream> using namespace std; /* Define a generic class to perform relational operation */ template<class T> class relational T x, y; public : relational(t var1, T var2) x = var1; y = var2; T getmin() return ((x < y)? x : y); T getmax() return ((x > y)? x : y);

29 ; int main() relational<int> r1(11, 17); // object r1 with integer data members relational<double> r2(7.1, 6.9); // 'T' is replaced with 'double' type int min = r1.getmin(); // get min value of object r1 double max = r2.getmax(); // get max value of object r2 cout<< "Minimum Element of object r1 : " << min <<endl; cout<< "Maximum Element of object r2 : " << max <<endl; return 0; 13. Write a program to illustrate the concept of re-throwing an exception.(8)[n/d-14] #include <iostream> using namespace std; void MyHandler() try throw hello ; catch (const char*) cout<< Caught exception inside MyHandler\n ; throw; //rethrow char* out of function int main() cout<< Main start ; try MyHandler(); catch(const char*) cout<< Caught exception inside Main\n ;

30 cout<< Main end ; return 0; Output : Main start Caught exception inside MyHandler Caught exception inside Main Main end 14. Write afunctiontemplate tofind the minimum value contained in an array. (8)[N/D-14] #include<iostream.h> #include<conio.h> template<class T> T minimum(t a[],int size) T min=a[0]; for(int i=0;i<size;i++) if(a[i]<min) min=a[i]; return min; int main()

31 int a[10],size,i,min1; float b[10],min2; clrscr(); cout<<"enter the size value:\n"; cin>>size; cout<<"enter the integer aray elements\n"; for(i=0;i<size;i++) cin>>a[i]; cout<<"enter the floating array elements\n"; for(i=0;i<size;i++) cin>>b[i]; min1=minimum(a,size); min2=minimum(b,size); cout<<"the minimum integer elements is:\n"; cout<<min1; cout<<"\nthe minimum floating elements is :\n"; cout<<min2; getch(); return 0;

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

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

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

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

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

QUESTION BANK UNIT III

QUESTION BANK UNIT III 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

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

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

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

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

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

THE STANDARD TEMPLATE LIBRARY (STL) Week 6 BITE 1513 Computer Game Programming

THE STANDARD TEMPLATE LIBRARY (STL) Week 6 BITE 1513 Computer Game Programming THE STANDARD TEMPLATE LIBRARY (STL) Week 6 BITE 1513 Computer Game Programming What the heck is STL???? Another hard to understand and lazy to implement stuff? Standard Template Library The standard template

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

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

Unit-V File operations

Unit-V File operations Unit-V File operations What is stream? C++ IO are based on streams, which are sequence of bytes flowing in and out of the programs. A C++ stream is a flow of data into or out of a program, such as the

More information

Object Oriented Programming In C++

Object Oriented Programming In C++ C++ Question Bank Page 1 Object Oriented Programming In C++ 1741059 to 1741065 Group F Date: 31 August, 2018 CIA 3 1. Briefly describe the various forms of get() function supported by the input stream.

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

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

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

A SHORT COURSE ON C++

A SHORT COURSE ON C++ Introduction to A SHORT COURSE ON School of Mathematics Semester 1 2008 Introduction to OUTLINE 1 INTRODUCTION TO 2 FLOW CONTROL AND FUNCTIONS If Else Looping Functions Cmath Library Prototyping Introduction

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

CPSC 427: Object-Oriented Programming

CPSC 427: Object-Oriented Programming CPSC 427: Object-Oriented Programming Michael J. Fischer Lecture 19 November 7, 2018 CPSC 427, Lecture 19, November 7, 2018 1/18 Exceptions Thowing an Exception Catching an Exception CPSC 427, Lecture

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

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

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

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

Function Templates. Consider the following function:

Function Templates. Consider the following function: Function Templates Consider the following function: void swap (int& a, int& b) { int tmp = a; a = b; b = tmp; Swapping integers. This function let's you swap the contents of two integer variables. But

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

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

I/O Streams and Standard I/O Devices (cont d.)

I/O Streams and Standard I/O Devices (cont d.) Chapter 3: Input/Output Objectives In this chapter, you will: Learn what a stream is and examine input and output streams Explore how to read data from the standard input device Learn how to use predefined

More information

1 Introduction to C++ C++ basics, simple IO, and error handling

1 Introduction to C++ C++ basics, simple IO, and error handling 1 Introduction to C++ C++ basics, simple IO, and error handling 1 Preview on the origins of C++ "Hello, World!" programs namespaces to avoid collisions basic textual IO: reading and printing values exception

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

! 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

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

AC55/AT55 OBJECT ORIENTED PROGRAMMING WITH C++ DEC 2014 Q.2 a. Differentiate between: (i) C and C++ (3) (ii) Insertion and Extraction operator (iii) Polymorphism and Abstraction (iv) Source File and Object File (v) Bitwise and Logical operator Answer: (i) C

More information

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

S.E Computer (First Semester) Examination 2016 OBJECT ORIENTED PROGRAMMING (2015 Pattern) Nov / Dec 2016 Time : 2 Hours Maximum Marks : 50 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)

More information

C++ Namespaces, Exceptions

C++ Namespaces, Exceptions C++ Namespaces, Exceptions CSci 588: Data Structures, Algorithms and Software Design http://www.cplusplus.com/doc/tutorial/namespaces/ http://www.cplusplus.com/doc/tutorial/exceptions/ http://www.cplusplus.com/doc/tutorial/typecasting/

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

PHY4321 Summary Notes

PHY4321 Summary Notes PHY4321 Summary Notes The next few pages contain some helpful notes that summarize some of the more useful material from the lecture notes. Be aware, though, that this is not a complete set and doesn t

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

This chapter introduces the notion of namespace. We also describe how to manage input and output with C++ commands via the terminal or files.

This chapter introduces the notion of namespace. We also describe how to manage input and output with C++ commands via the terminal or files. C++ PROGRAMMING LANGUAGE: NAMESPACE AND MANGEMENT OF INPUT/OUTPUT WITH C++. CAAM 519, CHAPTER 15 This chapter introduces the notion of namespace. We also describe how to manage input and output with C++

More information

CS242 COMPUTER PROGRAMMING

CS242 COMPUTER PROGRAMMING CS242 COMPUTER PROGRAMMING I.Safa a Alawneh Variables Outline 2 Data Type C++ Built-in Data Types o o o o bool Data Type char Data Type int Data Type Floating-Point Data Types Variable Declaration Initializing

More information

Computational Physics

Computational Physics Computational Physics numerical methods with C++ (and UNIX) 2018-19 Fernando Barao Instituto Superior Tecnico, Dep. Fisica email: fernando.barao@tecnico.ulisboa.pt Computational Physics 2018-19 (Phys Dep

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

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

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

CSC 330. An Exception is. Handling Exceptions. Error Handling. Assertions. C++ Exception. Example

CSC 330. An Exception is. Handling Exceptions. Error Handling. Assertions. C++ Exception. Example An Exception is CSC 330 Handling Exceptions CSC330 OO Software Design 1 An unusual, often unpredictable event, detectable by software or hardware, that requires special processing; also, in C++, a variable

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

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

Programming II with C++ (CSNB244) Lab 10. Topics: Files and Stream

Programming II with C++ (CSNB244) Lab 10. Topics: Files and Stream Topics: Files and Stream In this lab session, you will learn very basic and most common I/O operations required for C++ programming. The second part of this tutorial will teach you how to read and write

More information

The Standard Template Library. An introduction

The Standard Template Library. An introduction 1 The Standard Template Library An introduction 2 Standard Template Library (STL) Objective: Reuse common code Common constructs: Generic containers and algorithms STL Part of the C++ Standard Library

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

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

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

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

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

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

Strings and Streams. Professor Hugh C. Lauer CS-2303, System Programming Concepts

Strings and Streams. Professor Hugh C. Lauer CS-2303, System Programming Concepts Strings and Streams 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

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

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

Downloaded from

Downloaded from Unit-II Data Structure Arrays, Stacks, Queues And Linked List Chapter: 06 In Computer Science, a data structure is a particular way of storing and organizing data in a computer so that it can be used efficiently.

More information

CS

CS CS 1666 www.cs.pitt.edu/~nlf4/cs1666/ Programming in C++ First, some praise for C++ "It certainly has its good points. But by and large I think it s a bad language. It does a lot of things half well and

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

Lecture on pointers, references, and arrays and vectors

Lecture on pointers, references, and arrays and vectors Lecture on pointers, references, and arrays and vectors pointers for example, check out: http://www.programiz.com/cpp-programming/pointers [the following text is an excerpt of this website] #include

More information

Introduction. Common examples of exceptions

Introduction. Common examples of exceptions Exception Handling Introduction Common examples of exceptions Failure of new to obtain memory Out-of-bounds array subscript Division by zero Invalid function parameters Programs with exception handling

More information

G52CPP C++ Programming Lecture 18

G52CPP C++ Programming Lecture 18 G52CPP C++ Programming Lecture 18 Dr Jason Atkin http://www.cs.nott.ac.uk/~jaa/cpp/ g52cpp.html 1 Welcome Back 2 Last lecture Operator Overloading Strings and streams 3 Operator overloading - what to know

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

G52CPP C++ Programming Lecture 17

G52CPP C++ Programming Lecture 17 G52CPP C++ Programming Lecture 17 Dr Jason Atkin http://www.cs.nott.ac.uk/~jaa/cpp/ g52cpp.html 1 Last Lecture Exceptions How to throw (return) different error values as exceptions And catch the exceptions

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

CS102 C++ Exception Handling & Namespaces

CS102 C++ Exception Handling & Namespaces CS102 C++ Exception Handling & Namespaces Bill Cheng http://merlot.usc.edu/cs102-s12 1 Topics to cover C Structs (Ch 10) C++ Classes (Ch 11) Constructors Destructors Member functions Exception Handling

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

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

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

C++ Programming Lecture 10 File Processing

C++ Programming Lecture 10 File Processing C++ Programming Lecture 10 File Processing By Ghada Al-Mashaqbeh The Hashemite University Computer Engineering Department Outline Introduction. The Data Hierarchy. Files and Streams. Creating a Sequential

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

Convenient way to deal large quantities of data. Store data permanently (until file is deleted).

Convenient way to deal large quantities of data. Store data permanently (until file is deleted). FILE HANDLING Why to use Files: Convenient way to deal large quantities of data. Store data permanently (until file is deleted). Avoid typing data into program multiple times. Share data between programs.

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

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

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

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

Templates and Vectors

Templates and Vectors Templates and Vectors 1 Generic Programming function templates class templates 2 the STL vector class a vector of strings enumerating elements with an iterator inserting and erasing 3 Writing our own vector

More information

CS11 Advanced C++ Fall Lecture 3

CS11 Advanced C++ Fall Lecture 3 CS11 Advanced C++ Fall 2006-2007 Lecture 3 Today s Topics C++ Standard Exceptions Exception Cleanup Fun with Exceptions Exception Specifications C++ Exceptions Exceptions are nice for reporting many errors

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

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

UNIT- 3 Introduction to C++

UNIT- 3 Introduction to C++ UNIT- 3 Introduction to C++ C++ Character Sets: Letters A-Z, a-z Digits 0-9 Special Symbols Space + - * / ^ \ ( ) [ ] =!= . $, ; : %! &? _ # = @ White Spaces Blank spaces, horizontal tab, carriage

More information

Objects and streams and files CS427: Elements of Software Engineering

Objects and streams and files CS427: Elements of Software Engineering Objects and streams and files CS427: Elements of Software Engineering Lecture 6.2 (C++) 10am, 13 Feb 2012 CS427 Objects and streams and files 1/18 Today s topics 1 Recall...... Dynamic Memory Allocation...

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

CS2141 Software Development using C/C++ Stream I/O

CS2141 Software Development using C/C++ Stream I/O CS2141 Software Development using C/C++ Stream I/O iostream Two libraries can be used for input and output: stdio and iostream The iostream library is newer and better: It is object oriented It can make

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

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

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

Outline. Introduction. Arrays declarations and initialization. Const variables. Character arrays. Static arrays. Examples.

Outline. Introduction. Arrays declarations and initialization. Const variables. Character arrays. Static arrays. Examples. Outline Introduction. Arrays declarations and initialization. Const variables. Character arrays. Static arrays. Examples. 1 Arrays I Array One type of data structures. Consecutive group of memory locations

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

Chapte t r r 9

Chapte t r r 9 Chapter 9 Session Objectives Stream Class Stream Class Hierarchy String I/O Character I/O Object I/O File Pointers and their manipulations Error handling in Files Command Line arguments OOPS WITH C++ Sahaj

More information

Object Oriented Programming Using C++ UNIT-3 I/O Streams

Object Oriented Programming Using C++ UNIT-3 I/O Streams File - The information / data stored under a specific name on a storage device, is called a file. Stream - It refers to a sequence of bytes. Text file - It is a file that stores information in ASCII characters.

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

Throwing exceptions 02/12/2018. Throwing objects. Exceptions

Throwing exceptions 02/12/2018. Throwing objects. Exceptions ECE 150 Fundamentals of Programming Outline 2 In this lesson, we will: See that we can throw objects Know that there are classes defined in the standard template library These classes allow more information

More information

Unit 1: Preliminaries Part 4: Introduction to the Standard Template Library

Unit 1: Preliminaries Part 4: Introduction to the Standard Template Library Unit 1: Preliminaries Part 4: Introduction to the Standard Template Library Engineering 4892: Data Structures Faculty of Engineering & Applied Science Memorial University of Newfoundland May 6, 2010 ENGI

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

DHANALAKSHMI COLLEGE OF ENGINEERING DEPARTMENT OF COMPUTER SCIENCE AND ENGINEERING EC6301 OBJECT ORIENTED PROGRAMMING AND DATA STRUCTURES

DHANALAKSHMI COLLEGE OF ENGINEERING DEPARTMENT OF COMPUTER SCIENCE AND ENGINEERING EC6301 OBJECT ORIENTED PROGRAMMING AND DATA STRUCTURES DHANALAKSHMI COLLEGE OF ENGINEERING DEPARTMENT OF COMPUTER SCIENCE AND ENGINEERING EC6301 OBJECT ORIENTED PROGRAMMING AND DATA STRUCTURES UNIT III LINEAR DATA STRUCTURES PART A 1. What is meant by data

More information