Input and Output Statements

Slides:



Advertisements
Similar presentations
Write a program step by step. Step 1: Problem definition. Given the coordinate of two points in 2-D space, compute and print their straight distance.
Advertisements

C++ Basics March 10th. A C++ program //if necessary include headers //#include void main() { //variable declaration //read values input from user //computation.
What is a pointer? First of all, it is a variable, just like other variables you studied So it has type, storage etc. Difference: it can only store the.
Chapter 3. Expressions and Interactivity CSC125 Introduction to C++
CPS120: Introduction to Computer Science INPUT/OUTPUT.
Fortran 4- Reading and Writing from Data Files Chapter 4 of your Fortran book.
Programming Logic and Design Fourth Edition, Introductory
COSC 120 Computer Programming
ME1107 Computing Y Yan
Input and output. Input streams n there are two ways of handling I/o n list-directed –done using default settings –PRINT*, num –READ*, num n formatted.
1 Key Concepts:  Why C?  Life Cycle Of a C program,  What is a computer program?  A program statement?  Basic parts of a C program,  Printf() function?
1 Key Concepts:  Data types in C.  What is a variable?  Variable Declaration  Variable Initialization  Printf()  Scanf()  Working with numbers in.
Formatted Output What we know: write(*,*) x print *, x General Form: write (unit, format, options) list unit = * : write to the monitor format = *: no.
Engineering H192 - Computer Programming The Ohio State University Gateway Engineering Education Coalition Lect 6P. 1Winter Quarter I/O in C Lecture 6.
Chapter 5 Input / Output. 2 Control over input & output  The input and output are basically facilitates a communication between the user and the program.
How to Program in C++ CHAPTER 3: INPUT & OUTPUT INSTRUCTOR: MOHAMMAD MOJADDAM.
Chapter 8 Arrays and Strings
Pseudocode.
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.
Basic Elements of C++ Chapter 2.
CS102 Introduction to Computer Programming
Chapter 5: Data Input and Output Department of Computer Science Foundation Year Program Umm Alqura University, Makkah Computer Programming Skills
Fortran 1- Basics Chapters 1-2 in your Fortran book.
Copyright © 2012 Pearson Education, Inc. Publishing as Pearson Addison-Wesley C H A P T E R 2 Input, Processing, and Output.
Copyright © 2009 Pearson Education, Inc. Publishing as Pearson Addison-Wesley STARTING OUT WITH Python Python First Edition by Tony Gaddis Chapter 2 Input,
Input, Output, and Processing
Constants Numeric Constants Integer Constants Floating Point Constants Character Constants Expressions Arithmetic Operators Assignment Operators Relational.
Property of Jack Wilson, Cerritos College1 CIS Computer Programming Logic Programming Concepts Overview prepared by Jack Wilson Cerritos College.
Introduction to C Programming Chapter 2 : Data Input, Processing and Output.
An Object-Oriented Approach to Programming Logic and Design Chapter 1 An Overview of Computers and Logic.
Structure of a C program Preprocessor directive (header file) Program statement } Preprocessor directive Global variable declaration Comments Local variable.
Copyright © 2012 Pearson Education, Inc. Publishing as Pearson Addison-Wesley C H A P T E R 2 Input, Processing, and Output.
INPUT / OUTPUT STATEMENTS
CSC141 Introduction to Computer Programming Teacher: AHMED MUMTAZ MUSTEHSAN Lecture - 6.
CSC 1010 Programming for All Lecture 3 Useful Python Elements for Designing Programs Some material based on material from Marty Stepp, Instructor, University.
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.
CMP 131 Introduction to Computer Programming Violetta Cavalli-Sforza Week 5, Lecture 2 (Tuesday)
Program Development Cycle 1.Edit program 2.Compile program - translates it from C to machine language 3. Run/execute your program. 4. If not satisfied,
Scott Marino MSMIS Kean University MSAS5104 Programming with Data Structures and Algorithms Week 1 Scott Marino.
CCSA 221 Programming in C INPUT AND OUTPUT OPERATIONS IN C – PART 1 1.
Chapter 1: Introduction to Computers and Programming.
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 Every program takes some data as input and generate processed data as out put . It is important to know how to provide the input data and.
Basic concepts of C++ Presented by Prof. Satyajit De
C++ First Steps.
C++ Basic Input and Output (I/O)
Chapter Topics The Basics of a C++ Program Data Types
Topics Designing a Program Input, Processing, and Output
© 2016 Pearson Education, Ltd. All rights reserved.
CPS120: Introduction to Computer Science
CPS120: Introduction to Computer Science
Basic Elements of C++.
Getting Started with C.
Chapter 2 part #3 C++ Input / Output
Basic Elements of C++ Chapter 2.
Chapter 11 Introduction to Programming in C
Chapter 3 The DATA DIVISION.
Structured Program Design
Chapter 11 Introduction to Programming in C
Chapter 3: Input/Output
Topics Designing a Program Input, Processing, and Output
Topics Designing a Program Input, Processing, and Output
Topics Introduction to Value-returning Functions: Generating Random Numbers Writing Your Own Value-Returning Functions The math Module Storing Functions.
Data Groupings: File File: a group of related records
Topics Designing a Program Input, Processing, and Output
Topics Designing a Program Input, Processing, and Output
Chapter 2 part #3 C++ Input / Output
Getting Started With Coding
Presentation transcript:

Input and Output Statements FORTRAN has always included a comprehensive set of I/O instructions. Can be used with standard input and output devices such as keyboards, terminal screens, printers, etc. Can be used to read and write files managed by the host OS. Basic instructions: READ – reads input from a standard input device or a specified device or file. WRITE – writes data to a standard output device (screen) or to a specified device or file. FORMAT – defines the input or output format. Advanced instructions Used to manipulate files maintained by the OS file manager. Often dependent on features in a particular OS or computer.

READ Statement Format controlled READ: Syntax: READ(dev_no, format_label) variable_list Read a record from dev_no using format_label and assign results to variables in variable_list Ex: READ(5,1000) A,B,C 1000 FORMAT(3F12.4) Device numbers 1-7 are defined as standard I/O devices and 1 is the keyboard, but 5 is also commonly taken as the keyboard (used to be card reader) Each READ reads one or more lines of data and any remaining data in a line that is read is dropped if not translated to one of the variables in the variable_list. Variable_list can include implied DO such as: READ(5,1000)(A(I),I=1,10)

READ Statement – cont’d List-directed READ Syntax: READ*, variable_list Read enough variables from the standard input device (usually a keyboard) to satisfy variable_list input items can be integer, real or character. characters must be enclosed in ‘ ‘. input items are separated by commas. input items must agree in type with variables in variable_list. as many records (lines) will be read as needed to fill variable_list and any not used in the current line are dropped. each READ processes a new record (line). Ex: READ*,A,B,K – read line and look for floating point values for A and B and an integer for K. Some compilers support: Syntax: READ(dev_num, *) variable_list Behaves just like above.

WRITE Statement Format controlled WRITE Syntax: WRITE(dev_no, format_label) variable_list Write variables in variable_list to output dev_no using format specified in format statement with format_label Ex: WRITE(6,1000) A,B,KEY 1000 FORMAT(F12.4,E14.5,I6) Device number 6 is commonly the printer but can also be the screen (standard screen is 2) Each WRITE produces one or more output lines as needed to write out variable_list using format statement. Variable_list can include implied DO such as: WRITE(6,2000)(A(I),I=1,10) Output: |----+----o----+----o----+----o----+----| 1234.5678 -0.12345E+02 12

WRITE Statement – cont’d List directed WRITE Syntax: PRINT*, variable_list Write variables in variable_list to standard output device using format appropriate to variable type. Variables are separated by either spaces or commas, depending on system used. Ex: PRINT*,‘X=‘,X,’Y=‘,Y,’N=‘,N Output: X= 4.56, Y= 15.62, N= 4