Week 9 More Control over INPUT and OUTPUT (I / O).

Slides:



Advertisements
Similar presentations
Lesson 12 Getting Started with Excel Essentials
Advertisements

Introduction to arrays
Input and Output READ WRITE OPEN. FORMAT statement Format statements allow you to control how data are read or written. Some simple examples: Int=2; real=
Chapter 7 Introduction to Procedures. So far, all programs written in such way that all subtasks are integrated in one single large program. There is.
Chapter 3 Program Design And Branching Structures.
C++ Basics March 10th. A C++ program //if necessary include headers //#include void main() { //variable declaration //read values input from user //computation.
Starting Out with C++, 3 rd Edition 1 Chapter 1. Introduction to Computers and Programming.
Chapter 5 Basic I/O Concepts Dr. Ali Can Takinacı İstanbul Technical University Faculty of Naval Architecture and Ocean Engineering İstanbul - Turkey Tel:
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.
Chapter 2: Input, Processing, and Output
1 10/9/06CS150 Introduction to Computer Science 1 for Loops.
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.
Chapter 2 Data Types, Declarations, and Displays
Chapter 8: I/O Streams and Data Files. In this chapter, you will learn about: – I/O file stream objects and functions – Reading and writing character-based.
Graphical Tree-Based Scientific Calculator: CalcuWiz Will Ryan Christian Braunlich.
Chapter Seven Advanced Shell Programming. 2 Lesson A Developing a Fully Featured Program.
Computer Science 1000 Spreadsheets II Permission to redistribute these slides is strictly prohibited without permission.
Objectives You should be able to describe: Data Types
Fortran 1- Basics Chapters 1-2 in your Fortran book.
Computer Science 1000 Digital Circuits. Digital Information computers store and process information using binary as we’ve seen, binary affords us similar.
C How to Program, 6/e © by Pearson Education, Inc. All Rights Reserved.
Intro to Computers Computer Apps 1.
1 Week 2 n Organizational matters n Fortran 90 (subset F): Basics n Example programs in detail.
C++ Programming: From Problem Analysis to Program Design, Second Edition1 Objectives In this chapter you will: Learn about the pointer data type and pointer.
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.
1 More Control over INPUT and OUTPUT (I / O) The interface between the user and the computer Formats and edit descriptors Input editing Output editing.
Introduction to Pascal The Basics of Program writing.
Chapter 2 Pseudocode. Objectives To introduce common words, keywords and meaningful names when writing pseudocode To define the three basic control structures.
Pseudocode Simple Program Design Third Edition A Step-by-Step Approach 2.
Visual Basic Programming
Programming, an introduction to Pascal
INPUT / OUTPUT STATEMENTS
CMP 131 Introduction to Computer Programming Violetta Cavalli-Sforza Week 3, Lecture 1.
VARIABLES AND DATA TYPES Chapter2:part1 1. Objectives: By the end of this section you should: Understand what the variables are and why they are used.
Introducing C++ Programming Lecture 3 Dr. Hebbat Allah A. Elwishy Computer & IS Assistant Professor
FUNCTIONS. Topics Introduction to Functions Defining and Calling a Void Function Designing a Program to Use Functions Local Variables Passing Arguments.
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.
Part:2.  Keywords are words with special meaning in JavaScript  Keyword var ◦ Used to declare the names of variables ◦ A variable is a location in the.
T U T O R I A L  2009 Pearson Education, Inc. All rights reserved Student Grades Application Introducing Two-Dimensional Arrays and RadioButton.
CMP 131 Introduction to Computer Programming Violetta Cavalli-Sforza Week 5, Lecture 2 (Tuesday)
FUNCTIONS. Midterm questions (1-10) review 1. Every line in a C program should end with a semicolon. 2. In C language lowercase letters are significant.
A FIRST BOOK OF C++ CHAPTER 14 THE STRING CLASS AND EXCEPTION HANDLING.
Internet & World Wide Web How to Program, 5/e © by Pearson Education, Inc. All Rights Reserved.
Chapter 2: Data and Expressions. Variable Declaration In Java when you declare a variable, you must also declare the type of information it will hold.
©Brooks/Cole, 2003 Chapter 1 Introduction. ©Brooks/Cole, 2003 Figure 1-1 Data processor model This model represents a specific-purpose computer not a.
Introduction to Computer Programming using Fortran 77.
An Introduction to Programming with C++ Sixth Edition Chapter 5 The Selection Structure.
09/06/ Data Representation ASCII, Binary Denary Conversion, Integer & Boolean data types.
OPERATORS IN C CHAPTER 3. Expressions can be built up from literals, variables and operators. The operators define how the variables and literals in the.
Some of the utilities associated with the development of programs. These program development tools allow users to write and construct programs that the.
ITT_04101 COMPUTER APPLICATIONS Gaper M CIT
Concepts of Database Management, Fifth Edition Chapter 3: The Relational Model 2: SQL.
CCSA 221 Programming in C CHAPTER 3 COMPILING AND RUNNING YOUR FIRST PROGRAM 1 ALHANOUF ALAMR.
Copyright © 2013 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Starting Out with Programming Logic & Design Third Edition by Tony Gaddis.
Week 9 Controling I/O. Today’s program Review of the last quiz Q&A about last weeks topics New topic: I/O formatting.
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.
Chapter 2: Input, Processing, and Output
Chapter 2.3 Binary Logic.
The Selection Structure
Other Kinds of Arrays Chapter 11
INPUT STATEMENTS GC 201.
Introduction to C++ Programming
Variables T.Najah Al_Subaie Kingdom of Saudi Arabia
Problem Solving Skill Area 305.1
Language Constructs Construct means to build or put together. Language constructs refers to those parts which make up a high level programming language.
Chapter 2: Input, Processing, and Output
Digital Circuits.
PYTHON - VARIABLES AND OPERATORS
Presentation transcript:

Week 9 More Control over INPUT and OUTPUT (I / O)

More Control over INPUT and OUTPUT (I / O) The input and output facilities of any programming language are extremely important, because it is through these features of the language that communication between the user and the program is carried out. F, therefore, provides facilities for input and output at two quite different levels. As are given before, list-directed input and output statements that provide the capability for straightforward input from the keyboard and also the output to the display or printer. These list-directed “i/o” - statements, however, allow the user very little control over the source or layout of the input data.

F allows the programmer, to specify exactly how the data will be presented and interpreted, from which of the available input units it is to be read how the results are to be displayed to which of the available output units the results are to be sent. More Control over INPUT and OUTPUT (I / O)

INTERFACE between the USER and the COMPUTER Considering the following 9 – digit input data there are enormous number of possible interpretations : Data : , 2, 3, 4, 5, 6, 7, 8, and , 456, , 0.45, 67, etc.

FORMATS and EDIT DESCRIPTORS An input statement must contain three distinct types of information where the data is to be found where it is to be stored in the computer’s memory how it is to be interpreted Similarly, an output statement must define where the results are currently stored where they are to be sent in what form they are to be displayed.

INPUT EDITING EXAMPLES of INPUT DATA : read “ ( i 3, i 3, i 3 )”, n1, n2, n3 ! n1 = 123, n2 = 456, n5 = 789 read “ ( t 4, i 2, t 8, i 2, t 2, i 4 )”, x, y, z ! x = 45, y = 89, z = 2345 read “ ( f 9.4 )”, real_num ! real_num = read “ ( f 3.1, f 2.2, f 3.0 )”, r1, r2, r3 ! r1 = 12.3, r2 = 0.45, r3 =

EXAMPLE for formatting of real numbers using “ f – edit descriptor “ depending on the two different INPUT DATA : read “ ( f 3.1, f 2.2, f 3.0 )”, s1, s2, s3 DATA 1 DATA s1 contains : s2 contains : s3 contains :

EXAMPLEs for formatting of an input real number in different ways using “ a – edit descriptor “ real number is : – e d E

EXAMPLEs for formatting of an input – character type using “ a – edit descriptor “ character ( len = 10 ) : : ch1 character ( len = 6 ) : : ch2 character ( len = 15 ) : : ch3 Depending on the above-given declaration the formats may have the following forms in read statements : read “ ( a10, a6, a15 )”, ch1, ch2, ch3 or read “ ( a, a, a )”, n1, n2, n3

LOGICAL DATA - INPUT EDITING The edit descriptor is used with logical data, and takes the following form, where upper case “ L” is used to avoid the potential confusion with the digit “ 1 “ that can be caused to human readers by using the lower-case form : L w “ w “ caharacters are used to derive either a “ true “ value, a “ false “ value or an error.

Any of the following are acceptable as representing true :  t  true .T .true.  truthful while the following will all be interpreted as false :  F  False .f.  futile LOGICAL DATA - INPUT EDITING

OUTPUT EDITING The following figure shows the main edit descriptor that are available for output. EXAMPLE for “i” edit descriptor tom = 23 dick = 715 harry = -12 print *, “( i 5, i 5, i 5 )”, tom, dick, harry This statement produce following line of output (where the symbol # represents a space ) : ###23##715##-12

EXAMPLE for “f” edit descriptor : x = y = z = print *, “( f 10.3, f 10.3, f 10.3 )”, x, y, z This statement produce following line of output (where the symbol # represents a space ) : #####3.142## #### OUTPUT EDITING

EXAMPLE : program tabular_output real, parameter : : third = 1.0 / 3.0 real : : x integer : : i do i = 1, 10 x = 1.0 print “( f 15.4, f 15.4, f 15.4 )”, x, sqrt (x), x**third end do end program tabular_output OUTPUT EDITING

In the above-given program the same edit descriptor has been repeated several times. A number, called a “repeat count”, may be placed before the “ i, f, a or L “ – edit descriptors to indicate how many times they are to be repeated. Depending on this, the format could be written more succinctly and İt is possible to write it more clearly. EXAMPLE : print “( i 5, i 5, i 5, f 6.2, f 6.2, f 6.2, f 6.2 )”, x, y, z, d, e, f, g or better print “( 3 i 5, 4 f 6.2 )”, x, y, z, d, e, f, g OUTPUT EDITING

Exercise 2 program test1 integer ::a,b real::c,d read "(i4,t1,i4,t1,f4.1,t1,f4.2)",a,b,c,d print "(i4,a,i5,a,i5,a,f6.2,a,f6.2,a,f8.3)",a,& " minus",b," is",a-b,";",c," minus",d, " is",c-d end program test1

Exercise 3 program test2 character(len=6)::a,b,c read "(a8,t1,a4,t1,a)",a,b,c print "(a10,tr12,a4,tr30,a)",a,b,c print "(a,t10,a,t52,a)",a,b,c end program test2

program five_digit_numbers integer::i integer,dimension(12)::arr arr = (/12345, 23456, 34567, 45678,& 90123, 12340, 24680, 46802,& 13579, 35791, 57913, 69649/) !output for single column format example print*,"Single column of numbers" do i = 1, 12 print "(t8,i2,1x,i5)",i,arr(i) end do !output for four rows of three numbers print "(2/t3,a/)","Four rows of three numbers " print "(t8,i2,1x,3(i5,1x))", 1,arr(1:3) print "(t8,i2,1x,3(i5,1x))", 2,arr(4:6) print "(t8,i2,1x,3(i5,1x))", 3,arr(7:9) print "(t8,i2,1x,3(i5,1x))", 4,arr(10:12) ! a single line of numbers print "(2/t3,a/)", "A single line of numbers " print "(t2,12(i5,1x))", arr end program five_digit_numbers

program multi_record_example real :: a,b a = b = write(unit=6,fmt="(t10,a,3/,a,f6.2,a,f6.2,a"//"& f7.2,2/,a,f10.3)") & "Multi-record example",& " The sum of ",a," and",b," is", a+b,& " Their product is",a*b end program multi_record_example

program railway_time_table integer,parameter::n=5 integer::i real,dimension(n)::arrival,departure integer,dimension(n)::platform character(len=10),dimension(n)::destination arrival=(/9.23, 9.28, 10.41, 10.48, 11.15/) departure=(/9.25, 9.32, 10.53, 10.53, 11.18/) platform=(/2, 1, 3, 2, 1/) destination=(/"Edinburgh"," London","Sheffield",& "Newcastle"," London"/) write(unit=6,fmt="(/a/2x,7('='),3x,9('='),3x,8('='),3x,11('='))") & " Arrival Departure Platform Destination" do i = 1, n write(unit=6,fmt="(3x,f5.2,6x,f5.2,8x,i1,8x,a10)") & arrival(i),departure(i),platform(i),destination(i) end do end program railway_time_table

program test2 character(len=6)::a,b,c print *, " STEPPER... Entering PROGRAM. Press Enter" print*,"program test2" read * print *, " STEPPER... Before READ. Press Enter" print*,"read ""(a8,t1,a4,t1,a)"",a,b,c" read * read "(a8,t1,a4,t1,a)",a,b,c print *, " STEPPER... After READ. Press Enter" read * print "(a8,tr2,a4,tr3,a)",a,b,c print*,"print ""(a8,tr2,a4,tr3,a)"",a,b,c" print *, " STEPPER... After PRINT. Press Enter" read * print "(a,t10,a,tr2,a)",a,b,c print*,"print ""(a,t10,a,tr2,a)"",a,b,c" print *, " STEPPER... After PRINT. Press Enter" read * print *, " STEPPER... Before ENDPROGRAM. Press Enter" print*,"end program test2" read * end program test2