Input/Output Main Memory istream ostream Disk Drive Keyboard Scanner Disk Drive Monitor Printer stream = sequence of bytes.

Slides:



Advertisements
Similar presentations
This Time Whitespace and Input/Output revisited The Programming cycle Boolean Operators The “if” control structure LAB –Write a program that takes an integer.
Advertisements

CPS120: Introduction to Computer Science INPUT/OUTPUT.
I/O and Program Control Statements Dick Steflik. Overloading C++ provides two types of overloading –function overloading the ability to use the same function.
1 September 6, 2005CS150 Introduction to Computer Science I What Actions Do We Have Part 1 CS150 Introduction to Computer Science I.
Chapter 9 Formatted Input/Output Acknowledgment The notes are adapted from those provided by Deitel & Associates, Inc. and Pearson Education Inc.
© Copyright 1992–2004 by Deitel & Associates, Inc. and Pearson Education Inc. All Rights Reserved. 11 Chapter 21 - C++ Stream Input/Output Outline 21.1Introduction.
C++ Programming: Program Design Including Data Structures, Fourth Edition Chapter 3: Input/Output.
How to Program in C++ CHAPTER 3: INPUT & OUTPUT INSTRUCTOR: MOHAMMAD MOJADDAM.
C++ Programming: From Problem Analysis to Program Design, Fifth Edition Chapter 3: Input/Output.
Chapter 3: Input/Output
Streams, Files. 2 Stream Stream is a sequence of bytes Input stream In input operations, the bytes are transferred from a device to the main memory Output.
Input/Output in C++ C++ iostream.h instead of stdio.h Why change? –Input/output routines in iostream can be extended to new types declared by the user.
Chapter 01: Introduction to Computer Programming
Input and Output in Console Mode UNIVERSITY OF THE PUNJAB (GUJRANWALA CAMPUS) ADNAN BABAR MT14028 CR
CSCI 1730 January 17 th, 2012 © by Pearson Education, Inc. All Rights Reserved.
© Copyright 1992–2004 by Deitel & Associates, Inc. and Pearson Education Inc. All Rights Reserved. 1 Chapter 9 - Formatted Input/Output Outline 9.1Introduction.
© Janice Regan, CMPT 128, Sept CMPT 128: Introduction to Computing Science for Engineering Students C++ Basic Input and output.
CHAPTER 3 INPUT/OUTPUT. In this chapter, you will:  Learn what a stream is and examine input and output streams  Explore how to read data from the standard.
You gotta be cool. Stream Stream Output Stream Input Unformatted I/O with read, gcount and write Stream Manipulators Stream Format States Stream Error.
Exposure C++ Chapter VII Program Input and Output.
C++ Programming: Program Design Including Data Structures, Fifth Edition Chapter 3: Input/Output.
C++ Streams Lecture-2.
Week 1 Algorithmization and Programming Languages.
C++ How to Program, 8/e © by Pearson Education, Inc. All Rights Reserved.
CHAPTER 7 DATA INPUT OUTPUT Prepared by: Lec. Ghader R. Kurdi.
Introduction to C++ Version 1.1. Topics C++ Structure Primitive Data Types I/O Casting Strings Control Flow.
C++ How to Program, Late Objects Version, 7/e © by Pearson Education, Inc. All Rights Reserved.
C++ Programming: From Problem Analysis to Program Design, Fourth Edition Chapter 3: Input/Output.
I/O and Data Formatting Introduction to Class Concepts INFSY 307 Spring 2003 Lecture 3.
C++ Streams Lecture-2. C++ Streams Stream  A transfer of information in the form of a sequence of bytes I/O Operations:  Input stream: A stream that.
Input/Output Sujana Jyothi C++ Workshop Day 2. C++ I/O Basics 2 I/O - Input/Output is one of the first aspects of programming that needs to be mastered:
1 Simple Input/Output  C++ offers the iostream library, which defines a system of character-oriented Input/Output (I/O) using object oriented programming.
Lecture Contents I/O Streams. –Input/output streams. –Unformatted vs formatted streams. –Stream manipulators. –Stream error state. –Stream tying. –Examples.
4. Input/Output Intro Programming in C++ Computer Science Dept Va Tech August, 2001 © Barnette ND & McQuain WD 1 C++ Input/Output: Streams The.
CSC141- Introduction to Computer Programming Teacher: AHMED MUMTAZ MUSTEHSAN Lecture – 31 Thanks for Lecture Slides: C How to Program by Paul Deital &
 2000 Prentice Hall, Inc. All rights reserved. Chapter 21 - C++ Stream Input/Output Basics Outline 21.1Introduction 21.2Streams Iostream Library.
CHAPTER 2 PART #3 C++ INPUT / OUTPUT 1 st Semester 1436 King Saud University College of Applied studies and Community Service CSC1101 By: Fatimah Alakeel.
CHAPTER 2 PART #3 C++ INPUT / OUTPUT 1 st Semester King Saud University College of Applied studies and Community Service CSC1101 By: Fatimah.
Chapter 3: Input/Output
Programming Fundamentals. Summary of previous lectures Programming Language Phases of C++ Environment Variables and Data Types.
Chapter -7 Basic function of Input/output system basics and file processing Stream classes : I/O Streams. A stream is a source or destination for collection.
Operating System Using setw and setprecision functions Using setiosflags function Using cin function Programming 1 DCT
CHAPTER 2 PART #3 C++ INPUT / OUTPUT 1 st Semester King Saud University College of Applied studies and Community Service CSC1101 By: Fatimah.
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.
1 COMS 261 Computer Science I Title: Functions Date: October 24, 2005 Lecture Number: 22.
Input/Output. Objectives In this chapter you will: Learn what a stream is and examine input and output streams Explore how to use the input stream functions.
 2003 Prentice Hall, Inc. All rights reserved Basics of a Typical C++ Environment C++ systems –Program-development environment –Language –C++
Chapter 4 Strings and Screen I/O. Objectives Define strings and literals. Explain classes and objects. Use the string class to store strings. Perform.
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.
C++ Programming: From Problem Analysis to Program Design, Fourth Edition Chapter 3: Input/Output Samples.
Introduction to C++ (Extensions to C)
C++ Basic Input and Output (I/O)
What Actions Do We Have Part 1
CPS120: Introduction to Computer Science
CPS120: Introduction to Computer Science
Chapter 21 - C++ Stream Input/Output
Chapter 2 part #3 C++ Input / Output
Standard Input/Output Streams
Standard Input/Output Streams
Input/Output Handouts: Quiz 2, Unit 3 practice sheets.
CS 1430: Programming in C++ Turn in your Quiz1-2 No time to cover HiC.
Introduction to C++ Programming
Basic Input and Output C++ programs can read and write information using streams A simple input stream accepts typed data from a keyboard A simple output.
Chapter 3: Input/Output
Introduction to cout / cin
Chapter 3 Input output.
What Actions Do We Have Part 1
Chapter 2 part #3 C++ Input / Output
EECE.3220 Data Structures Instructor: Dr. Michael Geiger Spring 2019
Presentation transcript:

Input/Output Main Memory istream ostream Disk Drive Keyboard Scanner Disk Drive Monitor Printer stream = sequence of bytes

Input/Output standard library Unformatted – stream of bytes. Good for high speed, high volume transfers Formatted – groupings of bytes. Integers, characters, etc.

iostream library - cin, cout, cerr an istream object named cin associated with the keyboard an ostream object named cout associated with the monitor an ostream object named cerr associated with the monitor

operators << stream insertion operator int grade = 5; cout << grade; >> stream extraction operator int grade; cin >> grade;

cout details int grade = 92; cout << grade; // causes 92 to be displayed on the screen 92 grade 4 bytes bytes integer char steps: 1)convert integer 92 to character sequence 92 2)send characters 9 2 to the screen

cout details cout << ‘9’ << ‘2’; // causes 92 to be displayed on the screen bytes char bytes char no conversion necessary cout knows what to do because it knows the data type

concatenation of stream operators int grade = 92; cout << “your grade is” << grade; is the same as: cout << “your grade is”; cout << grade;

cout escape sequences \ escape character. special character follows cout << “Hello \n”; \n newline \\ backslash \” double quote \t tab

stream manipulators endl – writes a newline, flushes buffer cout << “your grade is” << grade << endl; what’s a buffer ? place to hold data while waiting for I/O operation to complete. 1 second = 1000 milliseconds = 1 million microseconds cout << grade; // microseconds to execute // milliseconds or seconds to complete I/O 29 cout puts things in i/o device takes things out first in first out buffer

stream manipulators double veryPreciseNumber = ; cout << veryPreciseNumber << endl; prints cout << setprecision(10) << veryPreciseNumber; prints #include //needed to use setprecision stays in effect for all subsequent cout calls setprecision(0) sets it back to default value

stream manipulators cout.setf(ios::showpoint); ios::hex Format numeric values as base 16 (hexadecimal). ios::showpoint Show decimal point and trailing zeros for floating-point values. ios::showpos Show plus signs (+) for positive values. ios::scientific Display floating-point numbers in scientific format. ios::fixed Display floating-point numbers in fixed format.

cout Exercises Identify the error in each of the following statements and explain how to correct it. 1) The following statement will print the integer value for ‘c’. cout << ‘c’; 2) cout << “”A string in quotes”” << endl; 3) display the number 200 with and without the + sign.

cin int age; cin >> age; operand to right of >> must be a variable nothing read until Enter key is typed reads input until end of input value is reached. 12 (age = 12) 1 2 (age = 1) input data must match data type. x would be an error for input for age.

cin concatenation okay int age, weight; cin >> age >> weight; Input: cin statement causes program to wait until input is entered. Should precede it with prompt cout << “Please enter age and weight”; handout on cin in Prof Hamel’s section of web site C++ How to program, Harvey Deitel Chapter 11

cin.get Useful when you want to be read whitespace characters i.e write a program to change a single spaced document into a double spaced document. char nextCharacter; cin.get (nextCharacter);

For each question, assume the following declarations: int num1, num2, num3; double real1, real2, real3; Each question is separate. 1) cin >> num1 >> num2 >> num3; INPUT ) cin >> real1 >> real2 >> real3; INPUT ) cin >> num1 >> num2 >> num3; INPUT ) cin >> num1 >> real1 >> num2 >> real2 >> num3 >> real3; INPUT cin Exercises