QUESTION BANK. SUBJECT CODE / Name: CS2311 OBJECT ORIENTED PROGRAMMING
|
|
- Clyde Montgomery
- 6 years ago
- Views:
Transcription
1 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++, exception handling is useful because it makes it easy to separate the error handling code from the code written to handle the chores of the program. Doing so makes reading and writing the code easier. C++ uses to handle exceptions means that it can easily handle those exceptions without any code in the intermediate functions. 2. What is Standard Template Library? State its purpose. (AUC MAY 2013, DEC 2010) A collection of generic classes and functions is called the Standard Template Library. STL components are part of C++ standard library. It provides many of the basic algorithms and data structures of computer science. The STL is a generic library, meaning that its components are heavily parameterized: almost every component in the STL is a template. 3. What is a namespace? State the purpose of namespaces with example (AUC DEC 2012, MAY 2012) ANSI C++ Standard has added a new keyword namespace to define a scope that could hold global identifiers. The best example of namespace scope is the C++ Standard Library.All classes, functions and templates are declared within the namespace named std. Using namespace std; The using namespace statement specifies that the members defined in std namespace will be used frequently throughout the program. The namespace is useful in the case that there is a possibility that a global object or function 1 1
2 uses the same identifier as another one, causing redefinition errors. 4. What is the difference between throw and throws? (AUC DEC 2012) Throw is used to actually throw the exception, whereas throws is declarative for the method. They are not interchangeable. Throws: this is to be used when you are not using the try catch statement in your code but you know that this particular class is capable of throwing so and so exception(only checked exceptions). In this you do not use try catch block but write using the throw clause at appropriate point in your code and the exception is thrown to caller of the method and is handled by it. 5. Define exception. Give example.(auc MAY 2012) Exceptions which occur during the program execution, due to some fault in the input data. Example: Array limit exceeding, division by zero. Exceptions are classifieds into a)synchronous exception b) Asynchronous exception 6. What are manipulators? How do you create a one? (AUC DEC 2011) The header file iomanip provides a set of functions called manipulators which can be used to manipulate the output formats. They provide same features as that of the ios member functions and flags. Ex: setw(5); - to set the width of size 5 bytes. 7. What is the difference between a function template and template function? (AUC DEC 2011) The term function template refers to a kind of template. The term template function is sometimes used to mean the same thing, and sometimes to mean a function instantiated from a function template. The template function is also called as instance of a function template. 8. What are IO streams? Give an example. (AUC DEC 2010) A Stream is a sequence of bytes. It can either as a source from which the input data can be obtained or as a destination to which the output data can be sent. The stream source that provides data to the program is called the input stream and the 2
3 destination stream that receives output from the program is called output stream. 9. List the containers supported by Standard Template Library. The STL contains three types of containers 1) Sequence containers 2) Associative containers 3) Derived containers 10. List some of the file modes. 1)ios::in 2)ios::out 3)ios::ate 4)ios::app 5)ios::trunk 6)ios::nocreate 7)ios::noreplace 8)ios::binary 11. Compare the performance characteristics of 3 containers. 12. What is container? A container is an object that actually stores data. It is a way data is organized in memory. The STL containers are implemented by template classes and therefore can be easily customized to hold different types of data 13. What is an iterator? An iterator is an object that points to an element in a container. We can use iterators to move through the contents of containers. Iterators are handled just like pointers 14. Define vector and list. The vector stores elements in contiguous memory locations and enables direct access to any element using the subscript operator[]. A vector can change its size dynamically and therefore 3
4 allocates memory as needed at run time The list is another container that is popularly used. It supports a bidirectional, linear list and provides an efficient implementation for deletion and insertion operations. 15. What are the types of derived containers? The STL provides three types of derived containers 1) Stack 2) Queue 3) Priority queue 16. What are 3 basic keywords of exception handling mechanism? Try - try for indicating program area where exception can be thrown. Throw for throwing an exception. Catch catch for actually taking an action for the specific exception. 17. List out some of the unformatted I/O operators and formatted I/O operations. Unformatted: a)put() b)get() c)getline() d)write() Formatted: a)ios stream class member functions and flags b)standard manipulators c)user defined manipulators 18. List out some of the manipulators. a)setw(int width) b)setprecision(int prec) c)setfill(int fchar) 4
5 d)setbase(int base) e)setiosflags(long flags) f)resetioflags(long flags) 19. What are the functions that the file stream class provides? a)seekg()-moves get pointer to a specified location b)seekp()-moves put pointer to a specified location c)tellg()-gives the current position of the get pointer d)tellp()-gives the current position of the put pointer 20. What is unnamed namespaces? An unnamed namespace is one that does not have a name. Unnamed namespace members occupy global scope and are accessible in all scopes following the declaration in the file PART B (16 Marks) 1. (i) What are the various ways of handling exceptions? When do we use multicatch handlers? Explain with an example. (8) (AUC MAY 2013) Exception handling is a mechanism that separates code that detects and handles exceptional circumstances from the rest of your program. Note that an exceptional circumstance is not necessarily an error. When a function detects an exceptional situation, you represent this with an object. This object is called an exception object. In order to deal with the exceptional situation you throw the exception. This passes control, as well as the exception, to a designated block of code in a direct or indirect caller of the function that threw the exception. This block of code is called a handler. In a handler, you specify the types of exceptions that it may process. The C++ run time, together with the generated code, will pass control to the first appropriate handler that is able to process the exception thrown. When this happens, an exception is caught. A handler may rethrow an exception so it can be caught by another handler. The exception handling mechanism is made up of the following elements: try blocks catch blocks 5
6 throw expressions Multiple Catch statements (ii)draw the I/O stream hierarchy in C++ and explain it clearly. (8) (AUC MAY 2013) 6
7 2. (i) 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. (8) (AUC MAY 2013) 7
8 (ii)explain the following functions (with example) for manipulating file pointers: seekg(), seekp(), tellg(), tellp(). (8) (AUC MAY 2013) Functions for manipulation of file pointers: seekg() - Moves get pointer (input) to a specified location. seekp() - Moves put pointer (output) to a specified location. tellg() - Gives the current position of the get pointer. tellp() - Gives the current position of the put pointer. For example, infile.seekg(10); Example program: #include <iostream> #include <fstream> using namespace std; void main(void) { char filename[ ] = "C:\\amad\\testfileio3.txt"; fstream inputfile, outputfile; int length; char* buffer; // create, open and write data to file outputfile.open(filename, ios::out); // simple error handling if(inputfile.fail()) { cerr<<"the file "<<filename<<" could not be created/opened!\n"; exit(1); } // test if successful to close the file else 8
9 cout<<"the "<<filename<<" file was opened successfully!\n"; // write some text cout<<"writing some text to the output file..."<<endl; outputfile<<"this is just line of text as a simple file content. This is testfileio3.txt file"<<endl; // close the output file cout<<"closing the output file..."<<endl; outputfile.close(); // opening and reading data from file cout<<"opening the input file..."<<endl; inputfile.open(filename, ios::in); // simple error handling for files creating/opening for writing if(inputfile.fail()) { cout<<"opening "<<filename<<" file for reading\n"; cout<<" \n"; cerr<<"the file "<<filename<<" could not be created/opened!\n"; cerr<<"possible errors:\n"; cerr<<"1. The file does not exist.\n"; cerr<<"2. The path was not found.\n"; exit(1); // just exit // 0-normal, non zero - some errors } else { cout<<"the "<<filename<<" file was opened successfully!\n"; cout<<"\nmove the pointer to the end\n" <<"Then back to the beginning with\n" <<"10 offset. The pointer now at...\n"<<endl; // flush the stream buffer explicitly cout<<flush; // get length of file, move the get pointer to the end of the stream inputfile.seekg(0, ios::end); // The tellg() member function returns the current stream position. length = inputfile.tellg(); cout<<"string length = "<<length<<"\n"; // dynamically allocate some memory storage for type char buffer = new char[length]; // move back the pointer to the beginning with offset of 10 (skips 10 char) inputfile.seekg(10, ios::beg); // read data as block from input file inputfile.read(buffer, length); cout<<buffer<<endl; // free up the allocated memory storage delete [ ] buffer; // close the input file inputfile.close(); } return; } 9
10 Output example: The C:\amad\testfileio3.txt file was opened successfully! Writing some text to the output file... Closing the output file... Opening the input file... The C:\amad\testfileio3.txt file was opened successfully! Move the pointer to the end Then back to the beginning with 10 offset. The pointer now at... string length = Explain file handling techniques in cpp. (AUC DEC 2012, MAY 2012) Many real-life problems handle large volumes of data, therefore we need to use some devices such as floppy disk or hard disk to store the data. The data is stored in these devices using the concept of files. A file is a collection of related data stored in a particular area on the disk. Programs can be designed to perform the read and write operations on these files. A program typically involves either or both of the following kinds of data communication: Data transfer between the console unit and the program. Data transfer between the program and a disk file. The input/output system of C++ handles file operations which are very much similar to the console input and output operations. It uses file streams as an interface between the programs and the files. The stream that supplies data to the program is known as input stream and the one that receives data from the program is known as output stream. In other words, the input stream extracts or reads data from the file and the output stream inserts or writes data to the file. Classes for the file stream operations The I/O system of C++ contains a set of classes that define the file handling methods. These include ifstream, ofstream and fstream. These classes, designed to manage the disk files, are declared in fstream.h and therefore we must include this file in any program that uses files. 10
11 filebuf Its purpose is to set the file buffer to read and write. Contains openprot constant used in the open() of the filestream classes. Also contains close() and open() as member functions. fstreambase Provides operations common to the file streams. Serves as a base for fstream, ifstream and ofstream classes. Contains open() and close() functions. ifstream Provides input operations. Contains open() with default input mode. Inherits the functions get(), getline(), read(), seekg() and tellg() functions from istream. ofstream Provides output operations. Contains open() with default output mode. Inherits put(), seekp(), tellp(), and write() functions from ostream. fstream Provides support for simultaneous input and output operations. Contains open() with default input mode. Inherits all the functions from istream and ostream classes through iostream. The ifstream, ofstream and fstream classes are declared in the file fstream.h The istream and ostream classes are also included in the fstream.h file. Opening and closing a file For opening a file, we must first create a file stream and than link it to the filename. A filestream can be defined using the classes ifstream, ofstream, and fstream that are contained in the header file fstream.h A file can be opened in two ways: Using the constructor function of the class. This method is useful when we open only one file in the stream. Using the member function open() of the class. This method is used when we want to manage multiple files using one stream. Using Constructor 11
12 Create a file stream object to manage the stream using the appropriate class. That is, the class ofstream is used to create the output stream and the class ifstream to create the input stream. Initialize the file object with the desired filename, e.g.: ofstream outfile( sample.txt ); The above statement creates an object outfile of class ofstream that manages the output stream. This statement also opens the file sample.txt and attaches it to the output stream for writing. Similarly, the statement declared in as an ifstream object and attaches to the file sample.txt for reading. ifstream infile( sample.txt ); Program: Writing and reading data into file, using constructors 12
13 To write data into the file, character by character Writing and reading Objects of a class : So far we have done I/O of basic data types. Since the class objects are the central elements of C++ programming, it is quite natural that the language supports features for writing and reading from the disk files objects directly. The binary input and output functions read() and write() are designed to do exactly this job. The write() function is used to write the object of a class into the specified file and read() function is used to read the object of the class from the file. Both these functions take two arguments: 1. address of object to be written. 2. size of the object. The address of the object must be cast to the type pointer to char. One important point to remember is that only data members are written to the disk file and the member functions are not. 13
14 Writing an object into the file fstream object can be used for both input & output. In the open() function we include several mode bits to specify certain aspects of the file object. app -> To preserve whatever was in the file before. Whatever we write to the file will be appended to the existing contents. We use in and out because we want to perform both input and output on the file. eof() is a member function of ios class. It returns a nonzero value if EOF is encountered and a zero otherwise. Functions for manipulation of file pointers: seekg() - Moves get pointer (input) to a specified location. seekp() - Moves put pointer (output) to a specified location. tellg() - Gives the current position of the get pointer. tellp() - Gives the current position of the put pointer. 4. Explain the different types of streams and various formatted I/O.(AUC MAY 14
15 2012) Formatted I/O C++ supports a number of features that could be used for formatting the output. They include: ios class functions and flags manipulators 15
16 user-defined output functions 16
17 Designing our own manipulators: The general form for creating a manipulator without any argument is: Example ostream & manipulator(ostream & output) { (code) return output; } ostream & unit(ostream output) { output<< inches- ; return output; } The statement cout<<36<<unit; will produce the following output 36 inches- 5. (i) Explain the features of I/O system supported in C++. (10) (AUC DEC 2011) [Refer Q.No 1] (ii) Write a program containing a possible exception. Use a try block and throw it and a catch block to handle it properly. (6) (AUC DEC 2011) 17
18 6. (i) Write a program that reads a name from the keyboard into three separate string objects and then concatenates them into a new string object using + operator and append() function. (10) (AUC DEC 2011) #include<iostream.h> #include<string.h> using namespace std; void main(void) { char *s1,*s2,*s3; char *fullstring; cout<< Enter three strings: ; cin>>s1>>s2>>s3; 18 M.Sathya Asst.Prof./CSE
19 fullstring.assign(s1); fullstring.append( + ); strcat(fullstring, s2); fullstring.append( + ); strcat(fullstring,s3); cout<< Full string is: ; cout<<fullstring; } OUTPUT Enter three strings One Two Three Full string is: One+Two+Three (ii) List the major categories of containers supported by STL. (6) (AUC DEC 2011) 19 M.Sathya Asst.Prof./CSE
20 7. Write a C++ program to demonstrate file handling as follows : get strings as input from the user, store them in a file, retrieve them and display them. (AUC DEC 2010) 20 M.Sathya Asst.Prof./CSE
21 8. Explain the exception handling mechanism available in C++ with suitable examples. (AUC DEC 2010) Exceptions are run time anomalies. They include conditions like division by zero or access to an array outside to its bound etc. Types: Synchronous exception Asynchronous exception. Find the problem ( Hit the exception ) Inform that an error has occurred. (Throw exception) Receive error information (Catch exception) Take corrective action (Handle exception) C++ exception handling mechanism is basically built upon three keywords, namely, try, throw and catch. The keyword try is used to preface a block of statements which may generate exceptions. This block of statements is known as try block. When an exception is detected it is thrown using a throw statement in the try block. A catch block defined by the keyword catch catches the exception thrown by the throw statement in the try block and handles it appropriately. 21
22 22 M.Sathya Asst.Prof./CSE
23 9. Explain namespaces with example. One of C++'s less heralded additions is addition of namespaces, which can be used to structure a program into "logical units". A namespace functions in the same way that a company division might function -- inside a namespace you include all functions appropriate for fulfilling a certain goal. For instance, if you had a program that connected to the Internet, you might have a namespace to handle all connection functions: namespace net_connect { int make_connection(); int test_connection(); //so forth... } 23 M.Sathya Asst.Prof./CSE
24 You can then refer to functions that are part of a namespace by prefixing the function with the namespace name followed by the scope operator -- ::. For instance, net_connect::make_connection() By enabling this program structure, C++ makes it easier for you to divide up a program into groups that each perform their own separate functions, in the same way that classes or structs simplify object oriented design. But namespaces, unlike classes, do not require instantiation; you do not need an object to use a specific namespace. You only need to prefix the function you wish to call with namespace_name:: -- similar to how you would call a static member function of a class. Another convenience of namespaces is that they allow you to use the same function name, when it makes sense to do so, to perform multiple different actions. For instance, if you were implementing a low-level IO routine and a higher level IO routine that uses that lower level IO, you might want to have the option of having two different functions named "input" -- one that handles low-level keyboard IO and one that handles converting that IO into the proper data type and setting its value to a variable of the proper type. So far, when we've wanted to use a namespace, we've had to refer to the functions within the namespace by including the namespace identifier followed by the scope operator. You can, however, introduce an entire namespace into a section of code by using a using-directive with the syntax using namespace namespace_name; Doing so will allow the programmer to call functions from within the namespace without having to specify the namespace of the function while in the current scope. (Generally, until the next closing bracket, or the entire file, if you aren't inside a block of code.) This convenience can be abused by using a namespace globally, which defeats some of the purpose of using a namespace. A common example of this usage is using namespace std; which grants access to the std namespace that includes C++ I/O objects cout and cin. Finally, you can introduce only specific members of a namespace using a using-declaration with the syntax using namespace_name::thing; One trick with namespaces is to use an unnamed namespace to avoid naming conflicts. To 24 M.Sathya Asst.Prof./CSE
25 do so, simply declare a namespace with the normal syntax, but leave off the identifier; when this is done, you will have namespace { //functions } and within the namespace you are assured that no global names will conflict because each namespace's function names take precedence over outside function names. Now, you might ask, how can you actually use anything in that namespace? When your program is compiled, the "anonymous" namespace you have created will be accessible within the file you created it in. In effect, it's as though an additional "using" clause was included implicitly. This effectively limits the scope of anything in the namespace to the file level (so you can't call the functions in that namespace from another other file). This is comparable to the effect of the static keyword. Renaming namespaces Finally, if you just don't feel like typing the entire name of namespace, but you're trying to keep to a good style and not use the using keyword, you can rename a namespace to reduce the typing: namespace <new> = <old> 10. (i) List the advantages of exception handling mechanisms. (4) The following are some of the advantages of exception handling mechanisms 1. Diving by zero error handling: the library designer and library user 2. Unconditional termination and program preferred termination. 3. Separating error reporting and error handling. 4. The object destroy problem. (ii) Write a C++ program for the following : (12) (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. 25 M.Sathya Asst.Prof./CSE
26 11. Write brief notes on Standard template Library (16) The collection of generic classes and functions is called the Standard Template Library (STL). STL components which are now part of the standard C++ library are defined in the namespace std. We must therefore use the using namespace directive using namespace std; 26 M.Sathya Asst.Prof./CSE
27 Components of STL Containers Types of container are; sequence container Vector - it allows insertion and deletion at back it permits direct access- header file is < vector > Deque - double ended queue it allows insertion and deletion at both ends- permits direct accessheader file is < deque> List - allows insertion and deletion anywhere header file is < list > Associative container Set - used for storing unique set it allows rapid look up- bidirectional access - header file is < set > Multiset - Used for storing non unique set header file is < set > Map - Used for storing unique key/value header file is <map> Multimap Derived container Stack - Last in first out no iterator- header file is < stack > Queue - First in first out no iterator- header file is < queue> priority queue - first element out is always with the highest priority- header file is <queue>- no iterator Algorithms Iterators Application of Container Classes 12. Write a program which copies the contents of one file to a new file by removing unnecessary spaces between words. 27 M.Sathya Asst.Prof./CSE
28 28 M.Sathya Asst.Prof./CSE
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 informationConvenient 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 informationChapter-12 DATA FILE HANDLING
Chapter-12 DATA FILE HANDLING Introduction: A file is a collection of related data stored in a particular area on the disk. Programs can be designed to perform the read and write operations on these files.
More informationAfter going through this lesson, you would be able to: store data in a file. access data record by record from the file. move pointer within the file
16 Files 16.1 Introduction At times it is required to store data on hard disk or floppy disk in some application program. The data is stored in these devices using the concept of file. 16.2 Objectives
More informationJAYARAM 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 informationJayaram 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 informationDeveloped By : Ms. K. M. Sanghavi
Developed By : Ms. K. M. Sanghavi Designing Our Own Manipulators We can design our own manipulators for certain special purpose.the general form for creating a manipulator without any arguments is: ostream
More informationObject 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 informationIS 0020 Program Design and Software Tools
1 IS 0020 Program Design and Software Tools Stack/Queue - File Processing Lecture 10 March 29, 2005 Introduction 2 Storage of data Arrays, variables are temporary Files are permanent Magnetic disk, optical
More informationC++ 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 informationRandom File Access. 1. Random File Access
Random File Access 1. Random File Access In sequential file access, the file is read or written sequentially from the beginning. In random file access, you can skip around to various points in the file
More informationThis 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 informationLecture 9. Introduction
Lecture 9 File Processing Streams Stream I/O template hierarchy Create, update, process files Sequential and random access Formatted and raw processing Namespaces Lec 9 Programming in C++ 1 Storage of
More informationChapte 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 informationC++ files and streams. Lec 28-31
C++ files and streams Lec 28-31 Introduction So far, we have been using the iostream standard library, which provides cin and cout methods for reading from standard input and writing to standard output
More informationObject 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 informationFall 2017 CISC/CMPE320 9/27/2017
Notices: CISC/CMPE320 Today File I/O Text, Random and Binary. Assignment 1 due next Friday at 7pm. The rest of the assignments will also be moved ahead a week. Teamwork: Let me know who the team leader
More informationC++ Binary File I/O. C++ file input and output are typically achieved by using an object of one of the following classes:
C++ Binary File I/O C++ file input and output are typically achieved by using an object of one of the following classes: ifstream for reading input only. ofstream for writing output only. fstream for reading
More informationStream States. Formatted I/O
C++ Input and Output * the standard C++ library has a collection of classes that can be used for input and output * most of these classes are based on a stream abstraction, the input or output device is
More informationObject Oriented Programming
Object Oriented Programming Course Title: Object Oriented Programming Full Marks: 60 20 20 Course No: CSC161 Pass Marks: 24 8 8 Nature of Course: Theory Lab Credit Hrs: 3 Semester: II Course Description:
More informationC++ does not, as a part of the language, define how data are sent out and read into the program
Input and Output C++ does not, as a part of the language, define how data are sent out and read into the program I/O implementation is hardware dependent The input and output (I/O) are handled by the standard
More informationPreface to the Second Edition Preface to the First Edition Brief Contents Introduction to C++ p. 1 A Review of Structures p.
Preface to the Second Edition p. iii Preface to the First Edition p. vi Brief Contents p. ix Introduction to C++ p. 1 A Review of Structures p. 1 The Need for Structures p. 1 Creating a New Data Type Using
More informationInterview Questions of C++
Interview Questions of C++ Q-1 What is the full form of OOPS? Ans: Object Oriented Programming System. Q-2 What is a class? Ans: Class is a blue print which reflects the entities attributes and actions.
More information(1)Given a binary file PHONE.DAT, containing records of the following structure type class Phonlist { char Name[20]; char Address[30]; char
(1)Given a binary file PHONE.DAT, containing records of the following structure type class Phonlist char Name[20]; char Address[30]; char AreaCode[5]; char PhoneNo[15]; Public: void Register(); void Show();
More informationCS2141 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 informationStudy Material for Class XII. Data File Handling
Study Material for Class XII Page 1 of 5 Data File Handling Components of C++ to be used with handling: Header s: fstream.h Classes: ifstream, ofstream, fstream File modes: in, out, in out Uses of cascaded
More informationby Pearson Education, Inc. All Rights Reserved. 2
Data that is formatted and written to a sequential file as shown in Section 17.4 cannot be modified without the risk of destroying other data in the file. For example, if the name White needs to be changed
More informationChapter 14 Sequential Access Files
Chapter 14 Sequential Access Files Objectives Create file objects Open a sequential access file Determine whether a sequential access file was opened successfully Write data to a sequential access file
More informationios ifstream fstream
File handling in C++ In most of the real time programming problems we need to store the data permanently on some secondary storage device so that it can be used later. Whenever we have to store the data
More informationVALLIAMMAI 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 informationCOMP322 - Introduction to C++
COMP322 - Introduction to C++ Lecture 05 - I/O using the standard library, stl containers, stl algorithms Dan Pomerantz School of Computer Science 5 February 2013 Basic I/O in C++ Recall that in C, we
More informationWriting a Good Program. 7. Stream I/O
Writing a Good Program 1 Input and Output I/O implementation is hardware dependent C++ does not, as a part of the language, define how data are sent out and read into the program The input and output (I/O)
More informationStreams in C++ Stream concept. Reference information. Stream type declarations
Stream concept A stream represent a sequence of bytes arriving, being retrieved, being stored, or being sent, in order. A stream is continuos and offer sequential access to the data. Each byte can be read
More informationStreams - Object input and output in C++
Streams - Object input and output in C++ Dr. Donald Davendra Ph.D. Department of Computing Science, FEI VSB-TU Ostrava Dr. Donald Davendra Ph.D. (Department of Computing Streams - Object Science, input
More informationCS201 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 informationUEE1303(1070) S 12 Object-Oriented Programming in C++
Computational Intelligence on Automation Lab @ NCTU Learning Objectives UEE1303(1070) S 12 Object-Oriented Programming in C++ Lecture 06: Streams and File Input/Output I/O stream istream and ostream member
More informationUNIT V FILE HANDLING
UNIT V CONTENTS: Streams and formatted I/O I/O manipulators File handling Random access Object serialization Namespaces Std namespace ANSI String Objects Standard template library FILE HANDLING Streams:
More informationCSc Introduc/on to Compu/ng. Lecture 19 Edgardo Molina Fall 2011 City College of New York
CSc 10200 Introduc/on to Compu/ng Lecture 19 Edgardo Molina Fall 2011 City College of New York 18 Standard Device Files Logical file object: Stream that connects a file of logically related data to a program
More informationAnd Even More and More C++ Fundamentals of Computer Science
And Even More and More C++ Fundamentals of Computer Science Outline C++ Classes Friendship Inheritance Multiple Inheritance Polymorphism Virtual Members Abstract Base Classes File Input/Output Friendship
More informationObjects 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 informationI/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 informationby Pearson Education, Inc. All Rights Reserved. 2
In Fig. 17.4, the file is to be opened for output, so an ofstream object is created. Two arguments are passed to the object s constructor the filename and the file-open mode (line 12). For an ofstream
More informationQuiz Start Time: 09:34 PM Time Left 82 sec(s)
Quiz Start Time: 09:34 PM Time Left 82 sec(s) Question # 1 of 10 ( Start time: 09:34:54 PM ) Total Marks: 1 While developing a program; should we think about the user interface? //handouts main reusability
More informationFundamentals of Programming Session 27
Fundamentals of Programming Session 27 Instructor: Reza Entezari-Maleki Email: entezari@ce.sharif.edu 1 Fall 2013 These slides have been created using Deitel s slides Sharif University of Technology Outlines
More informationConsider the following example where a base class has been derived by other two classes:
Class : BCA 3rd Semester Course Code: BCA-S3-03 Course Title: Object Oriented Programming Concepts in C++ Unit IV Polymorphism The word polymorphism means having many forms. Typically, polymorphism occurs
More informationFile I/O. File Names and Types. I/O Streams. Stream Extraction and Insertion. A file name should reflect its contents
File I/O 1 File Names and Types A file name should reflect its contents Payroll.dat Students.txt Grades.txt A file s extension indicates the kind of data the file holds.dat,.txt general program input or
More informationAdvanced I/O Concepts
Advanced Object Oriented Programming Advanced I/O Concepts Seokhee Jeon Department of Computer Engineering Kyung Hee University jeon@khu.ac.kr 1 1 Streams Diversity of input sources or output destinations
More informationChapter 12: Advanced File Operations
Chapter 12: Advanced File Operations 12.1 File Operations File Operations File: a set of data stored on a computer, often on a disk drive Programs can read from, write to files Used in many applications:
More informationToday in CS162. External Files. What is an external file? How do we save data in a file? CS162 External Data Files 1
Today in CS162 External Files What is an external file? How do we save data in a file? CS162 External Data Files 1 External Files So far, all of our programs have used main memory to temporarily store
More informationChapter 12. Streams and File I/O. Copyright 2010 Pearson Addison-Wesley. All rights reserved
Chapter 12 Streams and File I/O Copyright 2010 Pearson Addison-Wesley. All rights reserved Learning Objectives I/O Streams File I/O Character I/O Tools for Stream I/O File names as input Formatting output,
More informationObject Oriented Programming CS250
Object Oriented Programming CS250 Abas Computer Science Dept, Faculty of Computers & Informatics, Zagazig University arabas@zu.edu.eg http://www.arsaliem.faculty.zu.edu.eg Object Oriented Programming Principles
More informationGet 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 informationInput and Output File (Files and Stream )
Input and Output File (Files and Stream ) BITE 1513 Computer Game Programming Week 14 Scope Describe the fundamentals of input & output files. Use data files for input & output purposes. Files Normally,
More informationC++ Input/Output: Streams
C++ Input/Output: Streams Basic I/O 1 The basic data type for I/O in C++ is the stream. C++ incorporates a complex hierarchy of stream types. The most basic stream types are the standard input/output streams:
More informationAbsolute 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 informationCS3157: Advanced Programming. Outline
CS3157: Advanced Programming Lecture #12 Apr 3 Shlomo Hershkop shlomo@cs.columbia.edu 1 Outline Intro CPP Boring stuff: Language basics: identifiers, data types, operators, type conversions, branching
More informationIS0020 Program Design and Software Tools Summer, 2004 August 2, 2004 in Class
IS0020 Program Design and Software Tools Summer, 2004 August 2, 2004 in Class Name: A. Fill in the blanks in each of the following statements [Score: 20]: 1. A base class s members can be accessed only
More informationChapter 3 - Notes Input/Output
Chapter 3 - Notes Input/Output I. I/O Streams and Standard I/O Devices A. I/O Background 1. Stream of Bytes: A sequence of bytes from the source to the destination. 2. 2 Types of Streams: i. Input Stream:
More informationCpt 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 informationKapil Sehgal PGT Computer. Science Ankleshwar Gujarat Ch - 7. Data File Handling
Introduction Data File Handling The fstream.h Header file Data Files Opening and Closing File Steps to process a File in your Program Changing the behavior of Stream Sequential I/O With Files Detecting
More informationI 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 informationFile Operations. Lecture 16 COP 3014 Spring April 18, 2018
File Operations Lecture 16 COP 3014 Spring 2018 April 18, 2018 Input/Ouput to and from files File input and file output is an essential in programming. Most software involves more than keyboard input and
More informationSRM ARTS AND SCIENCE COLLEGE SRM NAGAR, KATTANKULATHUR
SRM ARTS AND SCIENCE COLLEGE SRM NAGAR, KATTANKULATHUR 603203 DEPARTMENT OF COMPUTER SCIENCE & APPLICATIONS QUESTION BANK (2017-2018) Course / Branch : M.Sc CST Semester / Year : EVEN / II Subject Name
More informationDHANALAKSHMI 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 informationChapter 8 File Processing
Chapter 8 File Processing Outline 1 Introduction 2 The Data Hierarchy 3 Files and Streams 4 Creating a Sequential Access File 5 Reading Data from a Sequential Access File 6 Updating Sequential Access Files
More informationLecture 5 Files and Streams
Lecture 5 Files and Streams Introduction C programs can store results & information permanently on disk using file handling functions These functions let you write either text or binary data to a file,
More informationChapter 12. Streams and File I/O. Copyright 2016 Pearson, Inc. All rights reserved.
Chapter 12 Streams and File I/O Copyright 2016 Pearson, Inc. All rights reserved. Learning Objectives I/O Streams File I/O Character I/O Tools for Stream I/O File names as input Formatting output, flag
More informationExceptions, 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 informationCSC 138 Structured Programming CHAPTER 4: TEXT FILE [PART 1]
CSC 138 Structured Programming CHAPTER 4: TEXT FILE [PART 1] LEARNING OBJECTIVES Upon completion, you should be able to: o define C++ text files o explain the benefits of using I/O file processing o explain
More informationVuZs Team's Work. CS201 Spring Solved by vuzs Team with Reference Written by Administrator Wednesday, 19 May :52
CS201 Spring2009 5 Solved by vuzs Team with Reference Written by Administrator Wednesday, 19 May 2010 17:52 MIDTERM EXAMINATION Spring 2009 CS201- Introduction to Programming Shared & Solved by vuzs Team
More informationSystem Design and Programming II
System Design and Programming II CSCI 194 Section 01 CRN: 10968 Fall 2017 David L. Sylvester, Sr., Assistant Professor Chapter 12 Advanced File Operation File Operations A file is a collection of data
More informationStrings 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 informationby Pearson Education, Inc. All Rights Reserved. 2
The C++ standard libraries provide an extensive set of input/output capabilities. C++ uses type-safe I/O. Each I/O operation is executed in a manner sensitive to the data type. If an I/O member function
More informationPhysical Files and Logical Files. Opening Files. Chap 2. Fundamental File Processing Operations. File Structures. Physical file.
File Structures Physical Files and Logical Files Chap 2. Fundamental File Processing Operations Things you have to learn Physical files and logical files File processing operations: create, open, close,
More informationIntroduction 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 informationcs3157: 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 informationChapter 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 informationIntroduction. Lecture 5 Files and Streams FILE * FILE *
Introduction Lecture Files and Streams C programs can store results & information permanently on disk using file handling functions These functions let you write either text or binary data to a file, and
More informationFile I/O Christian Schumacher, Info1 D-MAVT 2013
File I/O Christian Schumacher, chschuma@inf.ethz.ch Info1 D-MAVT 2013 Input and Output in C++ Stream objects Formatted output Writing and reading files References General Remarks I/O operations are essential
More information10CS36: Object Oriented Programming with C++
10CS36: Object Oriented Programming with C++ Question Bank: UNIT 1: Introduction to C++ 1. What is Procedure-oriented Programming System? Dec 2005 2. What is Object-oriented Programming System? June 2006
More informationBITG 1113: Files and Stream LECTURE 10
BITG 1113: Files and Stream LECTURE 10 1 LEARNING OUTCOMES At the end of this lecture, you should be able to: 1. Describe the fundamentals of input & output files. 2. Use data files for input & output
More informationCS201 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 informationChapter 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 informationIntroduction to C++ Systems Programming
Introduction to C++ Systems Programming Introduction to C++ Syntax differences between C and C++ A Simple C++ Example C++ Input/Output C++ Libraries C++ Header Files Another Simple C++ Example Inline Functions
More informationC++ How to Program 14.6
C++ How to Program 14.6 14.6 Random-Access Files pg.611-pg.612 -Unlike sequential files, R.A. files are instant-access applications. Any transaction-processing system. Requiring rapid access to specific
More informationModule 11 The C++ I/O System
Table of Contents Module 11 The C++ I/O System CRITICAL SKILL 11.1: Understand I/O streams... 2 CRITICAL SKILL 11.2: Know the I/O class hierarchy... 3 CRITICAL SKILL 11.3: Overload the > operators...
More informationc++ keywords: ( all lowercase ) Note: cin and cout are NOT keywords.
Chapter 1 File Extensions: Source code (cpp), Object code (obj), and Executable code (exe). Preprocessor processes directives and produces modified source Compiler takes modified source and produces object
More informationTEMPLATES 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 informationPage 1
Virtual Functions (introduction) A virtual function is one that does not really exist but it appears real in some parts of the program. Virtual functions are advanced features of the object oriented programming
More informationG52CPP C++ Programming Lecture 14. Dr Jason Atkin
G52CPP C++ Programming Lecture 14 Dr Jason Atkin 1 Last Lecture Automatically created methods: A default constructor so that objects can be created without defining a constructor A copy constructor used
More informationAdvanced File Operations. Review of Files. Declaration Opening Using Closing. CS SJAllan Chapter 12 2
Chapter 12 Advanced File Operations Review of Files Declaration Opening Using Closing CS 1410 - SJAllan Chapter 12 2 1 Testing for Open Errors To see if the file is opened correctly, test as follows: in.open("cust.dat");
More informationPiyush Kumar. input data. both cout and cin are data objects and are defined as classes ( type istream ) class
C++ IO C++ IO All I/O is in essence, done one character at a time For : COP 3330. Object oriented Programming (Using C++) http://www.compgeom.com/~piyush/teach/3330 Concept: I/O operations act on streams
More informationFile handling Basics. Lecture 7
File handling Basics Lecture 7 What is a File? A file is a collection of information, usually stored on a computer s disk. Information can be saved to files and then later reused. 2 File Names All files
More informationModule C++ I/O System Basics
1 Module - 36 C++ I/O System Basics Table of Contents 1. Introduction 2. Stream classes of C++ 3. Predefined Standard Input/Output Streams 4. Functions of class 5. Functions of class
More informationCOEN244: 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 informationProgramming 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 informationSoftware Design & Programming I
Software Design & Programming I Starting Out with C++ (From Control Structures through Objects) 7th Edition Written by: Tony Gaddis Pearson - Addison Wesley ISBN: 13-978-0-132-57625-3 Chapter 3 Introduction
More informationShort Notes of CS201
#includes: Short Notes of CS201 The #include directive instructs the preprocessor to read and include a file into a source code file. The file name is typically enclosed with < and > if the file is a system
More informationLecture 3 The character, string data Types Files
Lecture 3 The character, string data Types Files The smallest integral data type Used for single characters: letters, digits, and special symbols Each character is enclosed in single quotes 'A', 'a', '0',
More informationDE122/DC106 Object Oriented Programming with C++ DEC 2014
Q.2 a. Distinguish between Procedure-oriented programming and Object- Oriented Programming. Procedure-oriented Programming basically consists of writing a list of instructions for the computer to follow
More information