Object Oriented Programming In C++
|
|
- Jemimah Goodman
- 5 years ago
- Views:
Transcription
1 C++ Question Bank Page 1 Object Oriented Programming In C to Group F Date: 31 August, 2018 CIA 3 1. Briefly describe the various forms of get() function supported by the input stream. Give example for each of them. [ ] gets() Reads characters from the standard input (stdin) and stores them as a C string into str until a newline character or the end-of-file is reached. The newline character, if found, is not copied into str. A terminating null character is automatically appended after the characters copied to str. Example: int main() char string [256]; printf ("Insert your full address: "); gets (string); printf ("Your address is: %s\n",string); return 0; fgets() Get string from stream Reads characters from stream and stores them as a C string into str until (num-1) characters have been read or either a newline or the endof-file is reached, whichever happens first. A newline character makes fgets stop reading, but it is considered a valid character by the function and included in the string copied to str. A terminating null character is automatically appended after the characters copied to str. Example :
2 C++ Question Bank Page 2 int main() FILE * pfile; char mystring [100]; pfile = fopen ("myfile.txt", "r"); if (pfile == NULL) perror ("Error opening file"); else if ( fgets (mystring, 100, pfile)!= NULL ) puts (mystring); fclose (pfile); return 0; getchar() Returns the next character from the standard input (stdin). It is equivalent to calling getc with stdin as argument. Example: int main () int c; puts ("Enter text. Include a dot ('.') in a sentence to exit:"); do c=getchar(); putchar (c); while (c!= '.'); return 0; scanf() Reads data from stdin and stores them according to the parameter format into the locations pointed by the additional arguments. The additional arguments should point to already allocated objects of the type specified by their corresponding format specifier within the format string. Example:
3 C++ Question Bank Page 3 int main () char str [80]; int i; printf ("Enter your surname: "); scanf ("%79s",str); printf ("Enter your age: "); scanf ("%d",&i); printf ("Mr. %s, %d years old.\n",str,i); printf ("Enter a hexadecimal number: "); scanf ("%x",&i); printf ("You have entered %#x (%d).\n",i,i); return 0; 2. Create a single manipulator to provide the following output specifications for printing float values: a) 16 columns width b) Right-justified c) Four digits precision. [ ] cout << setprecision(4)<< setwidth(16)<< f <<right; 3. Briefly explain filling and padding functions in C++. [ ] get: char fill() const; This form returns the fill character. The fill character is the character used by output insertion functions to fill spaces when padding results to the field width. set char fill (char fillch);
4 C++ Question Bank Page 4 This form sets fillch as the new fill character and returns the fill character used before the call. The parametric manipulator setfill can also be used to set the fill character. 4. Why is it necessary to include the file iostream in all C++ programs? [ ] iostream.h is a file containing code for input/output operations. You need to include iostream.h so that the compiler knows about the word cout and cin, which appears a couple of lines below. 5. Compare set(), fill() and precision functions with example. [ ] set() Sets are containers that store unique elements following a specific order. In a set, the value of an element also identifies it (the value is itself the key) and each value must be unique. The value of the elements in a set cannot be modified once in the container (the elements are always const) but they can be inserted or removed from the container. Internally, the elements in a set are always sorted following a specific strict weak ordering criterion indicated by its internal comparison object (of type Compare). Sets are typically implemented as binary search trees. fill() The fill function assigns the value val to all the elements in the range [begin, end), where begin is the initial position and end is the last position. Example : int main () vector<int> vect(8); // calling fill to initialize values in the
5 C++ Question Bank Page 5 // range to 4 fill(vect.begin() + 2, vect.end() - 1, 4); for (int i=0; i<vect.size(); i++) cout << vect[i] << " "; return 0; Precision functions streamsize precision() const; This returns the value of the current floating-point precision field for the stream. streamsize precision (streamsize prec); This form also sets it to a new value. Set decimal precision Sets the decimal precision to be used to format floating-point values on output operations. 6. Briefly explain the importance of cin and cout in C++. [ ] The Standard Output Stream (cout) The predefined object cout is an instance of ostream class. The cout object is said to be "connected to" the standard output device, which usually is the display screen. The cout is used in conjunction with the stream insertion operator, which is written as << which are two less than signs. The Standard Input Stream (cin) The predefined object cin is an instance of istream class. The cin object is said to be attached to the standard input device, which usually is the keyboard. The cin is used in conjunction with the stream extraction operator, which is written as >> which are two greater than signs.
6 C++ Question Bank Page 6 7. Compare input and output stream with a diagram. [ ] Input Stream Input stream objects can read and interpret input from sequences of characters. cin is the instance of the class istream and is used to read input from the standard input device which is usually keyboard. The extraction operator(>>) is used along with the object cin for reading inputs. Output Stream Output stream objects can write sequences of characters and represent other kinds of data. cout is the instance of the ostream class. cout is used to produce output on the standard output device which is usually the display screen. The data needed to be displayed on the screen is inserted in the standard output stream (cout) using the insertion operator (<<).
7 C++ Question Bank Page 7 8. Write a program to print the numeral and the square root of the numeral from 1 to 5 by using the precision setting. [ ] Theory: The precision of a floating-point number defines how many significant digits it can represent. We use the manipulator setprecision(int) to display numbers up to a specified decimal digit. setprecision(int) is declared in header <iomanip> setprecision must take an integer as an argument, which specifies the number of significant digits the output should be in cout has a default precision of 6, so it truncates anything after 6 significant figures A variation of this can be done using keywords fixed and scientific. The keyword fixed is used to keep the number of digits that come after the decimal point fixed. This does not count significant figures, but the number of digits that occur after the decimal point. It has to be the same as specified by the setprecision() manipulator, so the statement cout<<fixed<<setprecision(5)<<a<<endl; where a holds the value 7.5 will print Notice how there has to be 5 digits after the decimal so it makes up with 0s for lacking digits.similarly, if a is 123, it would print Program: /*Program to demonstrate setprecision manipulator *Author: Vijay Kumar Prakash *Date: 02/August/2018/Sunday*/ #include <iostream> #include <iomanip> predefined library #include <math.h> using namespace std; //setprecision function is defined in this int main () int i;
8 C++ Question Bank Page 8 double pi,fraction; pi=22.0/7.0; cout<<"using DEFAULT PRECISION:\n"; cout<<"22/7 (PI) IS "<<pi<<endl; fraction=1.0/3.0; cout<<"1/3 IS "<<fraction<<endl; cout<<"\nusing SET PRECISION:\n"; fraction=43.0/8; cout<<setprecision(2)<<fraction<<endl; cout<<setprecision(9)<<fraction<<endl; cout<<"\nusing FIXED SET PRECISION:\n"; cout<<fixed; cout<<setprecision(1)<<fraction<<endl; cout<<setprecision(5)<<fraction<<endl; cout<<setprecision(9)<<fraction<<endl; /*printing numbers 1 to 5 along with their square roots. The square root of every number is printed along with that number as the precision value*/ cout<<"\nnumbers ALONG WITH SQUARE ROOTS\n"; for(i=1;i<=5;i++) cout<<"number IS "<<setprecision(i)<<i<<endl; cout<<"square ROOT OF "<<i<<" IS "<<setprecision(i)<<sqrt(i)<<endl; cout<<"\nusing 'SCIENTIFIC' PRECISION:\n"; cout<<scientific<<pi<<endl; return 1; Output: 22/7 (PI) IS /3 IS USING SET PRECISION: USING FIXED SET PRECISION: 5.4
9 C++ Question Bank Page NUMBERS ALONG WITH SQUARE ROOTS NUMBER IS 1 SQUARE ROOT OF 1 IS 1.0 NUMBER IS 2 SQUARE ROOT OF 2 IS 1.41 NUMBER IS 3 SQUARE ROOT OF 3 IS NUMBER IS 4 SQUARE ROOT OF 4 IS NUMBER IS 5 SQUARE ROOT OF 5 IS USING 'SCIENTIFIC' PRECISION: e Compare between opening a file with a constructor and opening a file with open( ) method with suitable examples. [ ] Opening a file using constructor: 1. Create file stream subject 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. 2. Initialize the file object with the desired filename. Syntax: ofstream object(file_name); Example: ofstream obj( sample.doc ); This creates obj1 as an ofstream that manages the output stream. #include stream.h #include string.h Void main() char str[]= ssi computer center ; ofstream outfile( sample.doc );
10 C++ Question Bank Page 10 Opening a file using open(): In order to open a file with a stream object we use its member function open: Syntax: open (filename, mode); where filename is a string representing the name of the file to be opened, and mode is an optional parameter. Example: #include <iostream> #include <fstream> using namespace std; int main () ofstream myfile; myfile.open ("example.txt"); myfile << "Writing this to a file.\n"; myfile.close(); return 0; 10.Describe the various file mode options available in C++ with examples. [ ] File Modes: The general form of the function open() with two arguments is: stream-object.open ( filename, mode); Parameter Meaning ios::app Append to end of file ios::ate Go to end of file on opening ios::binary Binary file ios::in Open file for reading only ios::nocreate Open fails if the file does not exist ios::noreplace Open fails if the file already exists ios::out Open file for writing only ios::trunc Delete the contents of the file if it exists File pointers and their manipulations.
11 C++ Question Bank Page 11 Each file has two associated pointers known as the file pointers. They are input pointer and output pointer. The input pointer is used for reading the contents of a given file location and the output pointer is used for writing to a given file location. Read only mode: Input pointer is automatically set at the beginning so that we can read the file from start. Write only mode: Existing contents are deleted and the output pointer is set at the beginning. Append mode: The output pointer is set to the end of file. Functions for manipulations of file pointers: seekg() Moves input pointer to a specified location seekp() Moves output pointer to a specified location tellg() Gives the current position of the input pointer tellp() Gives the current position of the output pointer Example: infile.seekg(10); moves file pointer to the byte number 10. The bytes are numbered from zero hence it points to the 11th byte in the file. ofstream out out.open( filename,ios::app); int p = out.tellp() 11.Describe the various classes available for file operations. [ ] fstreambase:the base class for ifstream, ofstream, and fstream classes. Functions such are open() and close() are defined in this class. fstream: It allows simultaneous input and output operations on filebuf. This class inherits istream and ostream classes. Member functions of the base classes istream and ostream starts the input and output. ifstream: This class inherits both fstreambase and istream classes. It can access member functions such as get(), getline(), seekg(), tellg(), and read(). It allows input operations and provides open() with the default input mode.
12 C++ Question Bank Page 12 ofstream: This class inherits both fstreambase and ostream classes. It can access member functions such as put(), seekp(), write(), and tellp(). It allows output operations and provides the open() function with the default output mode. filebuf: The filebuf is used for input and output operations on files. This class inherits streambuf class. It also arranges memory for keeping input data and for sending output. The I/O functions of istream and ostream invoke the filebuf functions to perform the insertion and extraction on the streams. 12.Draw the neat diagram of various classes available for file operations. [ ]
13 C++ Question Bank Page Describe the following functions for manipulation of file pointers : a) seekg() b) seekp() c) tellg() d) tellp(). [ ] In C++ we have a get pointer for getting (i.e. reading) data from a file and a put pointer for putting(i.e. writing) data to the file. seekg() is used to move the get pointer to a desired location with respect to a reference point. Syntax: file_pointer.seekg (number of bytes,reference point); Example: fin.seekg(10,ios::beg); seekp() is used to move the put pointer to a desired location with respect to a reference point. Syntax: file_pointer.seekp(number of bytes,reference point); Example: fout.seekp(10,ios::beg); tellg() is used to know where the get pointer is in a file. Syntax: file_pointer.tellg(); Example: int posn = fin.tellg(); tellp() is used to know where the put pointer is in a file. Syntax: file_pointer.tellp(); Example: int posn=fout.tellp(); The reference points are: ios::beg from beginning of file ios::end from end of file ios::cur from current position in the file. In seekg() and seekp() if we put sign in front of number of bytes then we can move backwards.
14 C++ Question Bank Page Detect the end of file condition successfully. Explain. [ ] C++ provides a special function, eof( ), that returns nonzero (meaning TRUE) when there are no more data to be read from an input filestream, and zero (meaning FALSE) otherwise or fin() can be used that returns 0 on the end of file. End of file in C++ can be detected using eof. While reading data from a file, if the file contains multiple rows, it is necessary to detect the end of file. This can be done using the eof() function of ios class. It returns 0 when there is data to be read and a non-zero value if there is no data. 15.Explain sequential input and output operations (put(), get(), read() and write()). [ ] put()-the function put () writes a single character to the associated stream. Syntax: obj.put(char ch); Example: fout.put(ch); get()-the function get () reads a single character to the associated stream. Syntax: obj.get(char &ch); Example: fout.put(ch); read()-the read() function is used to read object (sequence of bytes) to the file. Syntax: fin.read( (char *) &obj, sizeof(obj) ); Example: f.read((char*)&stu,sizeof(stu)); write()-the write() function is used to write object or record (sequence of bytes) to the file. Syntax: fout.write( (char *) &obj, sizeof(obj) ); Example: f.write( (char *) &Stu, sizeof(stu) ); 16.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. [ ]
15 C++ Question Bank Page 15 #include<fstream> #include<iostream> #include<string.h> #include<conio.h> using namespace std; main() ifstream f1; ofstream f2; char s[10],t[10],ch; strcpy(s,"source.txt"); strcpy(t,"target.txt"); //Creating Source File f2.open(s); f2<<"welcome to File Handling"<<endl; f2.close(); //Checking for mutiple spaces and copying source content to target content f1.open(s); f2.open(t); if(!f1) cout<<"error\n"; exit(0); f1.get(ch); while(!f1.eof()) f2<<ch; cout<<ch; if(ch==' ') while(ch==' ') f1.get(ch); f2<<ch; cout<<ch; f1.get(ch); f1.close();
16 C++ Question Bank Page 16 f2.close(); //Displaying Source and Target Content system("cls"); cout<<"source File Contents\n"; f1.open(s); while(!f1.eof()) f1.get(ch); cout<<ch; f1.close(); cout<<"\n\ntarget File Contents\n"; f1.open(t); while(!f1.eof()) f1.get(ch); cout<<ch; f1.close(); getch(); Output: Source File Contents Welcome to File Handling Target File Contents Welcome to File Handling
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 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 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 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 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 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 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 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 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 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 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 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 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 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 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 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 informationQUESTION 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 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 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 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 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 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 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 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 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 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 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 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 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 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 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 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 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 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 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 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 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 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 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 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 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 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 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 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 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 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 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 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 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 informationText File I/O. #include <iostream> #include <fstream> using namespace std; int main() {
Text File I/O We can use essentially the same techniques we ve been using to input from the keyboard and output to the screen and just apply them to files instead. If you want to prepare input data ahead,
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 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 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 informationA function is a named group of statements developed to solve a sub-problem and returns a value to other functions when it is called.
Chapter-12 FUNCTIONS Introduction A function is a named group of statements developed to solve a sub-problem and returns a value to other functions when it is called. Types of functions There are two types
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 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 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 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 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 informationFig: iostream class hierarchy
Unit 6: C++ IO Systems ================== Streams: Θ A stream is a logical device that either produces or consumes information. Θ A stream is linked to a physical device by the I/O system. Θ All streams
More informationInput and Output. Data Processing Course, I. Hrivnacova, IPN Orsay
Input and Output Data Processing Course, I. Hrivnacova, IPN Orsay Output to the Screen Input from the Keyboard IO Headers Output to a File Input from a File Formatting I. Hrivnacova @ Data Processing Course
More informationWeek 3: File I/O and Formatting 3.7 Formatting Output
Week 3: File I/O and Formatting 3.7 Formatting Output Formatting: the way a value is printed: Gaddis: 3.7, 3.8, 5.11 CS 1428 Fall 2014 Jill Seaman spacing decimal points, fractional values, number of digits
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 informationStreams contd. Text: Chapter12, Big C++
Streams contd pm_jat@daiict.ac.in Text: Chapter12, Big C++ Streams Objects are Abstracted Wrapper around input/output source/destinations Steps in reading/writing streams- Open: Establish connection between
More informationStandard File Pointers
1 Programming in C Standard File Pointers Assigned to console unless redirected Standard input = stdin Used by scan function Can be redirected: cmd < input-file Standard output = stdout Used by printf
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 informationApplications with Files, Templates
Files - Introduction A file is collection of data or information that has a name, called the filename. Files are stored in secondary storage devices such as floppy disks and hard disks. The main memories
More informationMore File IO. CIS 15 : Spring 2007
More File IO CIS 15 : Spring 2007 Functionalia Office Hours Today 2 to 3pm - 0317 N (Bridges Room) HW 2 due on Sunday March 11, 11:59pm Note: Midterm is on MONDAY, March 12th Review: Thursday Today: Survey
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 informationDATA FILE HANDLING FILES. characters (ASCII Code) sequence of bytes, i.e. 0 s & 1 s
DATA FILE HANDLING The Language like C/C++ treat everything as a file, these languages treat keyboard, mouse, printer, Hard disk, Floppy disk and all other hardware as a file. In C++, a file, at its lowest
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 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 informationDownloaded from
DATA FILE HANDLING IN C++ Key Points: Text file: A text file stores information in readable and printable form. Each line of text is terminated with an EOL (End of Line) character. Binary file: A binary
More informationPhysics 6720 I/O Methods October 30, C++ and Unix I/O Streams
Physics 6720 I/O Methods October 30, 2002 We have been using cin and cout to handle input from the keyboard and output to the screen. In these notes we discuss further useful capabilities of these standard
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 informationComputer Programming Unit v
READING AND WRITING CHARACTERS We can read and write a character on screen using printf() and scanf() function but this is not applicable in all situations. In C programming language some function are
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 informationDISK FILE PROGRAM. ios. ofstream
[1] DEFINITION OF FILE A file is a bunch of bytes stored on some storage media like magnetic disk, optical disk or solid state media like pen-drive. In C++ a file, at its lowest level is interpreted simply
More informationComputer programs are associated to work with files as it helps in storing data & information permanently. File - itself a bunch of bytes stored on
Computer programs are associated to work with files as it helps in storing data & information permanently. File - itself a bunch of bytes stored on some storage devices. In C++ this is achieved through
More informationC++ Basics. Lecture 2 COP 3014 Spring January 8, 2018
C++ Basics Lecture 2 COP 3014 Spring 2018 January 8, 2018 Structure of a C++ Program Sequence of statements, typically grouped into functions. function: a subprogram. a section of a program performing
More informationWhat we will learn about this week:
What we will learn about this week: Streams Basic file I/O Tools for Stream I/O Manipulators Character I/O Get and Put EOF function Pre-defined character functions Objects 1 I/O Streams as an Introduction
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 informationEP241 Computing Programming
EP241 Computing Programming Topic 9 File Management Department of Engineering Physics University of Gaziantep Course web page www.gantep.edu.tr/~bingul/ep241 Sep 2013 Sayfa 1 Overview of Streams in C++
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 informationAll About: File I/O in C++ By Ilia Yordanov, ; C++ Resources
All About: File I/O in C++ By Ilia Yordanov, loobian@cpp-home.com www.cpp-home.com ; C++ Resources This tutorial may not be republished without a written permission from the author! Introduction This tutorial
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 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 3: Input/Output
Chapter 3: Input/Output I/O: sequence of bytes (stream of bytes) from source to destination Bytes are usually characters, unless program requires other types of information Stream: sequence of characters
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 information7/21/ FILE INPUT / OUTPUT. Dong-Chul Kim BioMeCIS UTA
7/21/2014 1 FILE INPUT / OUTPUT Dong-Chul Kim BioMeCIS CSE @ UTA What s a file? A named section of storage, usually on a disk In C, a file is a continuous sequence of bytes Examples for the demand of a
More informationReview for COSC 120 8/31/2017. Review for COSC 120 Computer Systems. Review for COSC 120 Computer Structure
Computer Systems Computer System Computer Structure C++ Environment Imperative vs. object-oriented programming in C++ Input / Output Primitive data types Software Banking System Compiler Music Player Text
More informationChapter 6. I/O Streams as an Introduction to Objects and Classes. Copyright 2007 Pearson Education, Inc. Publishing as Pearson Addison-Wesley
Chapter 6 I/O Streams as an Introduction to Objects and Classes Overview 6.1 Streams and Basic File I/O 6.2 Tools for Stream I/O 6.3 Character I/O Slide 6-3 6.1 Streams and Basic File I/O I/O Streams I/O
More informationCOMP322 - Introduction to C++
COMP322 - Introduction to C++ Winter 2011 Lecture 05 - I/O using the standard library & Introduction to Classes Milena Scaccia School of Computer Science McGill University February 1, 2011 Final note on
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 informationInput/output. Remember std::ostream? std::istream std::ostream. std::ostream cin std::istream. namespace std { class ostream { /*...
Input/output Remember std::ostream? namespace std { class ostream { /*... */ }; } extern istream cin; extern ostream cout; extern ostream cerr; extern ostream clog; 7 / 24 std::istream std::ostream std
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 informationCS201 Solved MCQs.
15.1 Answer each of the following: a. Input/output in C++ occurs as of bytes. b. The stream manipulators that format justification are, and. c. Member function can be used to set and reset format state.
More informationInput/Output Streams: Customizing
DM560 Introduction to Programming in C++ Input/Output Streams: Customizing Marco Chiarandini Department of Mathematics & Computer Science University of Southern Denmark [Based on slides by Bjarne Stroustrup]
More informationGetting started with C++ (Part 2)
Getting started with C++ (Part 2) CS427: Elements of Software Engineering Lecture 2.2 11am, 16 Jan 2012 CS427 Getting started with C++ (Part 2) 1/22 Outline 1 Recall from last week... 2 Recall: Output
More informationWe can even use the operator << to chain the output request as:
IO Management Writing to the stream: cout
More information