Objects and streams and files CS427: Elements of Software Engineering
|
|
- Myles Mills
- 5 years ago
- Views:
Transcription
1 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
2 Today s topics 1 Recall Dynamic Memory Allocation... Encapsulation The stack example again 2 Constructor 3 Destructors 4 Streams as examples of Objects 5 code, cin methods manipulators 6 Files open CS427 Objects and streams and files 2/18
3 Recall Dynamic Memory Allocation In C++ dynamic memory allocation is achieved using new and delete. Example int *contents; contents = new int[20];... delete [] contents; Note: unlike calloc and malloc in C, new will work with any data type, including user-defined types such as class. Also, casting is not required. CS427 Objects and streams and files 3/18
4 Recall Encapsulation Encapsulation incorporating the data associated with an entity, and the methods of manipulating that data, into a single abstract data type. Usually, Public methods provide the interface to an object, while its internal state is represented by private data. In C++, encapsulation is usually achieved using the class construct In today s class we ll quickly revise what we did in Lecture 4.2 and Lab 3: classes private and public members constructors Destructors, And then go onto streams as an example of a class. CS427 Objects and streams and files 4/18
5 Recall... The stack example again In Lecture 4.2 and Lab 3, we used a stack (LIFO queue) as an example of an bstract Data Type. Any function in the program can: declare a instance of the class stack. added to the top of the stack: s.push() ; removed from the top of the stack: s.pop(). These are the interfaces to the stack, and are public: For the stack itself, the following must be maintained: a character array contents[] a integer count of the number of items on the stack (top). These are private to the class. CS427 Objects and streams and files 5/18
6 Constructor We also introduced the idea of constructor. It is a public member function that has the same name as the class It is called automatically when an instance of the class is declared. It cannot have a return type. class stack private: char *contents; int top; public: stack(void); void push(char c); char pop(void ); }; stack::stack(void) top=0; contents = new char[max_stack]; } CS427 Objects and streams and files 6/18
7 Constructor This is a particularly basic example of a constructor. More commonly we pass arguments to the constructor that can be used Set the value of a data member; Dynamically size an array using new. However, one should still provide a default constructor (i.e., one with no arguments). class stack private: char *contents; int top; public: stack(void); stack(unsigned int StackSize); void push(char c); char pop(void ); }; stack::stack(void) top=0; contents = new char[max_stack]; } stack::stack(unsigned int StackSize) top=0; contents = new char[stacksize]; } CS427 Objects and streams and files 7/18
8 Destructors Complementing the idea of a constructor is a destructor. This function is called for a local object whenever it goes out of scope for a global object when the program ends. The name of the destructor is the same as the class, but preceded by a tilde: class stack private: char *contents; int top; public: stack(void ); stack(void ); void push(char c); char pop(); }; stack:: stack() delete [] contents; } CS427 Objects and streams and files 8/18
9 Streams as examples of Objects I/O means Input/Output. So far, we have taken input from the keyboard, typically using cin, and sent output to a terminal window, using cout. These are examples of streams: flows of data to or from your program. Moreover, they are examples of objects in C++. In this section, we ll study how to manipulate these streams in C++, including writing to and reading from files. But first, some more information about cout and cin. CS427 Objects and streams and files 9/18
10 code, cin methods The objects cout and cin are objects and are manipulated by their methods, i.e., public member functions and operators. Methods: width(int x) minimum number of characters for next output, fill(char x) character used to fill with in the case that the width needs to be elongated to fill the minimum. precision(int x) sets the number of significant digits for floating-point numbers. CS427 Objects and streams and files 10/18
11 code, cin methods See 01cinANDcout.cpp Code width for (int i=65; i<123; i++) cout.width(8); cout << i; cout.width(3); cout << (char) i; if ( (i%5) == 4) cout << endl; } Output 65 A 66 B 67 C F 71 G 72 H K 76 L 77 M P 81 Q 82 R U 86 V 87 W 90 Z 91 [ 92 \ 95 _ a 100 d 101 e 102 f 105 i 106 j 107 k 110 n 111 o 112 p 115 s 116 t 117 u 120 x 121 y 122 CS427 Objects and streams and files 11/18
12 code, cin methods Code width, fill cout.fill( 0 ); for (int i=0; i<10000; i+= rand()%2000) cout.width(6); cout << i <<endl; } Output CS427 Objects and streams and files 12/18
13 code, cin methods Code precision double Pi= ; for (int i=1; i<=10; i++) cout.precision(i); cout << Pi (correct to << i << digits) is << Pi << endl; } Output Pi (correct to 1 digits) is 3 Pi (correct to 2 digits) is 3.1 Pi (correct to 3 digits) is 3.14 Pi (correct to 4 digits) is Pi (correct to 5 digits) is Pi (correct to 6 digits) is Pi (correct to 7 digits) is Pi (correct to 8 digits) is Pi (correct to 9 digits) is Pi (correct to 10 digits) is CS427 Objects and streams and files 13/18
14 code, cin manipulators setw like width left Left justifies output in field width. Used after setw(n). right right justify. endl inserts a newline into the stream and calls flush. flush forces an output stream to write any buffered characters dec changes the output format of number to be in decimal format oct octal format hex hexadecimal format showpoint show the decimal point and some zeros with whole numbers Others: setprecision(n), fixed, scientific, boolalpha, noboolalpha,... Need to include iomanip CS427 Objects and streams and files 14/18
15 code, cin manipulators All of the C++ programs we have looked at so far took their input from the standard input stream: this was usually the keyboard. Example: cout << Enter an inteter: ; cin >> i; Although, for example, the standard input stream can be redirected to a file, it is usually necessary to open a file from within the program and take the data from there. The same is true for writing to a file. To do either of these takes in C++ we create a file stream and use it just as we would cin or cout. CS427 Objects and streams and files 15/18
16 Files When working with files, we need to include the fstream header file. To read from a file, declare an object of type ifstream; to write to a file, declare an object of type ofstream. Open the file by calling the open() member function. To read a single character, can use InFile.get ) 1 include iostream > 2 include fstream > 3 include c s t d l i b > 5 using namespace std ; 02CountChars.cpp 7 i n t main ( void ) 8 9 i f s t r e a m I n F i l e ; 10 ofstream OutFile ; 11 char InFileName [ 30]= CPlusPlusTerms. t x t ; 12 char c ; 14 cout Processing the contents of 15 InFileName endl ; 16 cout See Output. t x t f o r more i n f o 17 endl ; 18 I n F i l e. open ( InFileName ) ; 19 OutFile. open ( Output. t x t ) ; 21 i n t i =0; 22 I n F i l e. get ( c ) ; CS427 Objects and streams and files 16/18
17 Files If there are no more characters left in the input stream, then InFile.eof() evaluates as true. Use the steam objects just as you would use cin or cout: InFile >> data or OutFile << data. Close the files: InFile.close(), OutFile.close() 02CountChars.cpp (continued) 22 while ( I n F i l e. eof ( ) ) i ++; 25 I n F i l e. get ( c ) ; 26 } 28 OutFile InFileName contains 29 i characters n ; 32 I n F i l e. close ( ) ; 33 OutFile. close ( ) ; 35 return ( 0 ) ; 36 } CS427 Objects and streams and files 17/18
18 Files open Note that the method open works differently for ifstream and ofstream; InFile.open Opens an existing file for reading, OutFile.open Opens a file for writing. If it already exists, its contents are overwritten. To open an existing file and append to its contents, use OutFile.open( Output.txt, ios::app); If the open call fails, then the method fail() returns true. So you should always include something like to following after opening a file: if (InFile.fail()) cerr << Error - can t open << InFileName << endl; exit(1); } CS427 Objects and streams and files 18/18
Week 5: Files and Streams
CS319: Scientific Computing (with C++) Week 5: and Streams 9am, Tuesday, 12 February 2019 1 Labs and stuff 2 ifstream and ofstream close a file open a file Reading from the file 3 Portable Bitmap Format
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 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 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 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 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 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 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 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 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 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 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 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 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 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 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 information[CSE10200] Programming Basis ( 프로그래밍기초 ) Chapter 7. Seungkyu Lee. Assistant Professor, Dept. of Computer Engineering Kyung Hee University
[CSE10200] Programming Basis ( 프로그래밍기초 ) Chapter 7 Seungkyu Lee Assistant Professor, Dept. of Computer Engineering Kyung Hee University Input entities Keyboard, files Output entities Monitor, files Standard
More informationFormatting outputs String data type Interactive inputs File manipulators. Access to a library that defines 3. instead, a library provides input
Input and Output Outline Formatting outputs String data type Interactive inputs File manipulators CS 1410 Comp Sci with C++ Input and Output 1 CS 1410 Comp Sci with C++ Input and Output 2 No I/O is built
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 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 informationObject-oriented Programming for Automation & Robotics Carsten Gutwenger LS 11 Algorithm Engineering
Object-oriented Programming for Automation & Robotics Carsten Gutwenger LS 11 Algorithm Engineering Lecture 3 Winter 2011/12 Oct 25 Visual C++: Problems and Solutions New section on web page (scroll down)
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 informationFile Input / Output Streams in C++ CS 16: Solving Problems with Computers I Lecture #9
File Input / Output Streams in C++ CS 16: Solving Problems with Computers I Lecture #9 Ziad Matni Dept. of Computer Science, UCSB Midterm Exam grades out! Announcements If you want to see your exams, visit
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 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 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 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 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 informationChapter 12. Streams and File I/O
Chapter 12 Streams and File I/O Learning Objectives I/O Streams File I/O Character I/O Tools for Stream I/O File names as input Formatting output, flag settings Introduction Streams Special objects Deliver
More informationIntroduction to C++ (Extensions to C)
Introduction to C++ (Extensions to C) C is purely procedural, with no objects, classes or inheritance. C++ is a hybrid of C with OOP! The most significant extensions to C are: much stronger type checking.
More 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 informationPROGRAMMING EXAMPLE: Checking Account Balance
Programming Example: Checking Account Balance 1 PROGRAMMING EXAMPLE: Checking Account Balance A local bank in your town is looking for someone to write a program that calculates a customer s checking account
More informationC++ Programming Classes. Michael Griffiths Corporate Information and Computing Services The University of Sheffield
C++ Programming Classes Michael Griffiths Corporate Information and Computing Services The University of Sheffield Email m.griffiths@sheffield.ac.uk Presentation Outline Differences between C and C++ Object
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 informationC Legacy Code Topics. Objectives. In this appendix you ll:
cppfp2_appf_legacycode.fm Page 1 Monday, March 25, 2013 3:44 PM F C Legacy Code Topics Objectives In this appendix you ll: Redirect keyboard input to come from a file and redirect screen output to a file.
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 informationWe will exclusively use streams for input and output of data. Intro Programming in C++
C++ Input/Output: Streams 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: 1 istream
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 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 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 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 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 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 information3.1. Chapter 3: Displaying a Prompt. Expressions and Interactivity
Chapter 3: Expressions and Interactivity 3.1 The cin Object Copyright 2009 Pearson Education, Inc. Copyright 2009 Publishing Pearson as Pearson Education, Addison-Wesley Inc. Publishing as Pearson Addison-Wesley
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 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 informationUnit 1 : Principles of object oriented programming
Unit 1 : Principles of object oriented programming Difference Between Procedure Oriented Programming (POP) & Object Oriented Programming (OOP) Divided Into Importance Procedure Oriented Programming In
More informationChapter 12 - C++ Stream Input/Output
Chapter 12 - C++ Stream Input/Output 1 12.1 Introduction 12.2 Streams 12.2.1 Classic Streams vs. Standard Streams 12.2.2 iostream Library Header Files 12.2.3 Stream Input/Output Classes and Objects 12.3
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 Overview. I/O Streams as an Introduction to Objects and Classes. I/O Streams. Streams and Basic File I/O. Objects
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 Copyright 2008 Pearson Addison-Wesley. All rights reserved.
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 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 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 informationC++ Quick Guide. Advertisements
C++ Quick Guide Advertisements Previous Page Next Page C++ is a statically typed, compiled, general purpose, case sensitive, free form programming language that supports procedural, object oriented, and
More 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 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 informationEngineering Problem Solving with C++, 3e Chapter 2 Test Bank
1. Match each of the following data types with literal constants of that data type. A data type can be used more than once. A. integer B 1.427E3 B. double D "Oct" C. character B -63.29 D. string F #Hashtag
More informationFundamental File Processing Operations 2. Fundamental File Processing Operations
2 Fundamental File Processing Operations Copyright 2004, Binnur Kurt Content Sample programs for file manipulation Physical files and logical files Opening and closing files Reading from files and writing
More informationCS 151 Review #3. // More than one variable can be defined // in a statement. Multiple variables are // separated by a comma.
REVIEW cout Statement The cout statement invokes an output stream, which is a sequence of characters to be displayed to the screen. cout
More informationBITG 1233: Introduction to C++
BITG 1233: Introduction to C++ 1 Learning Outcomes At the end of this lecture, you should be able to: Identify basic structure of C++ program (pg 3) Describe the concepts of : Character set. (pg 11) Token
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 informationChapter 3. Numeric Types, Expressions, and Output
Chapter 3 Numeric Types, Expressions, and Output 1 Chapter 3 Topics Constants of Type int and float Evaluating Arithmetic Expressions Implicit Type Coercion and Explicit Type Conversion Calling a Value-Returning
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 informationThe C++ Language. Output. Input and Output. Another type supplied by C++ Very complex, made up of several simple types.
The C++ Language Input and Output Output! Output is information generated by a program.! Frequently sent the screen or a file.! An output stream is used to send information. Another type supplied by C++
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 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 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 informationFor Teacher's Use Only Q No Total Q No Q No
Student Info Student ID: Center: Exam Date: FINALTERM EXAMINATION Spring 2010 CS201- Introduction to Programming Time: 90 min Marks: 58 For Teacher's Use Only Q No. 1 2 3 4 5 6 7 8 Total Marks Q No. 9
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 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 informationStreams and Basic File I/O Tools for Stream I/O Character I/O Inheritance
Chapter 6 In this chapter, you will learn about: Streams and Basic File I/O Tools for Stream I/O Character I/O Inheritance Streams and Basic File I/O I refers to the program Input O refers to program Output:
More informationLecture 14: more class, C++ streams
CIS 330: / / / / (_) / / / / _/_/ / / / / / \/ / /_/ / `/ \/ / / / _/_// / / / / /_ / /_/ / / / / /> < / /_/ / / / / /_/ / / / /_/ / / / / / \ /_/ /_/_/_/ _ \,_/_/ /_/\,_/ \ /_/ \ //_/ /_/ Lecture 14:
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 informationWindow s Visual Studio Output
1. Explain the output of the program below. Program char str1[11]; char str2[11]; cout > str1; Window s Visual Studio Output Enter a string: 123456789012345678901234567890 Enter
More information1. Match each of the following data types with literal constants of that data type. A data type can be used more than once. A.
Engineering Problem Solving With C++ 4th Edition Etter TEST BANK Full clear download (no error formating) at: https://testbankreal.com/download/engineering-problem-solving-with-c-4thedition-etter-test-bank/
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 informationEL2310 Scientific Programming
Lecture 14: Object Oriented Programming in C++ (ramviyas@kth.se) Overview Overview Lecture 14: Object Oriented Programming in C++ Classes (cont d) More on Classes and Members Group presentations Last time
More informationSHORT REVIEW OF CS TOPICS RANDOM NUMBERS (2 MARKS) which generates a random number in the range of 0 to n-1. For example;
SHORT REVIEW OF CS TOPICS RANDOM NUMBERS (2 MARKS) Generating Random Numbers The key function in generating random numbers is; int random (int n); which generates a random number in the range of 0 to n-1.
More informationCSE 333. Lecture 9 - intro to C++ Hal Perkins Department of Computer Science & Engineering University of Washington
CSE 333 Lecture 9 - intro to C++ Hal Perkins Department of Computer Science & Engineering University of Washington Administrivia New exercise posted yesterday afternoon, due Monday morning - Read a directory
More informationComputational Physics
Computational Physics numerical methods with C++ (and UNIX) 2018-19 Fernando Barao Instituto Superior Tecnico, Dep. Fisica email: fernando.barao@tecnico.ulisboa.pt Computational Physics 2018-19 (Phys Dep
More informationCSE 333 Lecture 9 - intro to C++
CSE 333 Lecture 9 - intro to C++ Hal Perkins Department of Computer Science & Engineering University of Washington Administrivia & Agenda Main topic: Intro to C++ But first: Some hints on HW2 Labs: The
More informationFundamentals of Programming CS-110. Lecture 2
Fundamentals of Programming CS-110 Lecture 2 Last Lab // Example program #include using namespace std; int main() { cout
More informationCSCE 206: Structured Programming in C++
CSCE 206: Structured Programming in C++ 2017 Spring Exam 2 Monday, March 20, 2017 Total - 100 Points B Instructions: Total of 13 pages, including this cover and the last page. Before starting the exam,
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 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 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 informationWentworth Institute of Technology COMP201 Computer Science II Spring 2015 Derbinsky. Stacks and Queues. Lecture 11.
Lecture 11 1 More Data Structures In this lecture we will use a linked list to implement two abstract data types (ADT) An ADT provides the interface, or what a data structure does We can then use code
More informationCome and join us at WebLyceum
Come and join us at WebLyceum For Past Papers, Quiz, Assignments, GDBs, Video Lectures etc Go to http://www.weblyceum.com and click Register In Case of any Problem Contact Administrators Rana Muhammad
More informationStreams. Parsing Input Data. Associating a File Stream with a File. Conceptual Model of a Stream. Parsing. Parsing
Input Data 1 Streams 2 Streams Conceptual Model of a Stream Associating a File Stream with a File Basic Stream Input Basic Stream Output Reading Single Characters: get() Skipping and Discarding Characters:
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 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 informationC++ basics Getting started with, and Data Types.
C++ basics Getting started with, and Data Types pm_jat@daiict.ac.in Recap Last Lecture We talked about Variables - Variables, their binding to type, storage etc., Categorization based on storage binding
More informationIntroduction to Standard C++ Console I/O. C++ Object Oriented Programming Pei-yih Ting NTOU CS
Introduction to Standard C++ Console I/O C++ Object Oriented Programming Pei-yih Ting NTOU CS 1 Contents I/O class hierarchy, cin, cout > operators Buffered I/O cin.get() and cin.getline() status
More informationEngineering Problem Solving with C++, Etter/Ingber
Engineering Problem Solving with C++, Etter/Ingber Chapter 2 Simple C++ Programs C++, Second Edition, J. Ingber 1 Simple C++ Programs Program Structure Constants and Variables C++ Operators Standard Input
More informationFile Input/Output Streams in C++ CS 16: Solving Problems with Computers I Lecture #10
File Input/Output Streams in C++ CS 16: Solving Problems with Computers I Lecture #10 Ziad Matni Dept. of Computer Science, UCSB Announcements Homework #9 due today Homework #10 is out Midterm #2 is on
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 informationThe cin Object. cout << "Enter the length and the width of the rectangle? "; cin >> length >> width;
The cin Object Short for console input. It is used to read data typed at the keyboard. Must include the iostream library. When this instruction is executed, it waits for the user to type, it reads the
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 informationCS24 Week 3 Lecture 1
CS24 Week 3 Lecture 1 Kyle Dewey Overview Some minor C++ points ADT Review Object-oriented Programming C++ Classes Constructors Destructors More minor Points (if time) Key Minor Points const Motivation
More information