Pascal Programming Today Chapter 2 1 Chapter 2. Pascal Programming Today Chapter 2 2 »Output statements write data to output devices (e.g. VDU). »Two.

Slides:



Advertisements
Similar presentations
Selection Process If … then … else.... Condition Process 2 Process 1 Y.
Advertisements

Chapter 3. Expressions and Interactivity CSC125 Introduction to C++
More Review, with Some New Chapter 3. Review C++ simple data types – Integral and float – Arithmetic operators Expressions and expression evaluation –
James Tam Getting Started With Pascal Programming How are computer programs created What is the basic structure of a Pascal Program Variables in Pascal.
James Tam Getting Started With Pascal Programming What is the basic structure of a Pascal Program Variables in Pascal Performing input and output with.
J. Michael Moore Input and Output (IO) CSCE 110 Drawn from James Tam's material.
The scanf Function The scanf function reads input from the standard input device into one or more variables Example: scanf(“%lf”, &miles); Reads a real.
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.
Data Input and Output Using the Library Software CSC 1401: Introduction to Programming with Java Lecture 4 – Part 1 Wanda M. Kunkle.
Input and Output (IO) CSCE 110 Drawn from James Tam's material.
Chapter 3: Input/Output
Input/Output  Input/Output operations are performed using input/output functions  Common input/output functions are provided as part of C’s standard.
Example in Final Fall 2006 PROGRAM EXAM IMPLICIT NONE INTEGER :: A=3, B=8 REAL :: CALC B = CALC(A, B) A = CALC(A, B) WRITE(*,*) A, B END PROGRAM EXAM a)
CIS 270—Application Development II Chapter 28—Formatted Output.
© Copyright 1992–2004 by Deitel & Associates, Inc. and Pearson Education Inc. All Rights Reserved Streams Streams –Sequences of characters organized.
2/4/2003CSCI 150: Introduction to Computer Science1 Introduction to Computer Science CSCI 150 Section 002 Session 6 Dr. Richard J. Bonneau IONA Technologies.
Fortran 1- Basics Chapters 1-2 in your Fortran book.
Stack Data Structure By : Imam M Shofi. What is stack? A stack is a limited version of an array. A stack is a limited version of an array. New elements,
1 The CONST definition CONST Pi = , City = ‘New York’; Constant identifiers are used when you do not want the value of an identifier to change why.
Pascal Programming Strings, Arithmetic operators and output formatting National Certificate – Unit 4 Carl Smith.
Exposure C++ Chapter VII Program Input and Output.
Lecture 13 Midterm overview When you know a thing, to hold that you know it, and when you do not know a thing, to allow that you do not know it: this is.
Input, Output, and Processing
Computer Programming TCP1224 Chapter 4 Variables, Constants, and Arithmetic Operators.
INFORMATION TECHNOLOGY CSEC CXC 10/25/ PASCAL is a programming language named after the 17th century mathematician Blaise Pascal. Pascal provides.
Chapter 3 Assignment, Formatting, and Interactive Input C++ for Engineers and Scientists Third Edition.
Constants Numeric Constants Integer Constants Floating Point Constants Character Constants Expressions Arithmetic Operators Assignment Operators Relational.
Introduction to Pascal The Basics of Program writing.
Copyright © 2012 Pearson Education, Inc. Publishing as Pearson Addison-Wesley C H A P T E R 2 Input, Processing, and Output.
Chapter 3 Arithmetic Expressions, Function Calls, and Output
CMP 131 Introduction to Computer Programming Violetta Cavalli-Sforza Week 5, Lecture 1 (Monday)
Programming, an introduction to Pascal
INPUT / OUTPUT STATEMENTS
Chapter 3: Assignment, Formatting, and Interactive Input.
1 st semester Basic Pascal Elements อภิรักษ์ จันทร์สร้าง Aphirak Jansang Computer Engineering.
C++ for Engineers and Scientists Second Edition Chapter 3 Assignment, Formatting, and Interactive Input.
Introducing Python CS 4320, SPRING Lexical Structure Two aspects of Python syntax may be challenging to Java programmers Indenting ◦Indenting is.
Chapter 3 – Variables and Arithmetic Operations. Variable Rules u Must declare all variable names –List name and type u Keep length to 31 characters –Older.
Pascal Programming Today Chapter 11 1 Chapter 11.
Assignment statement and Arithmetic operation 1 The major part of data processing.
Chapter-4 Managing input and Output operation.  Reading, processing and writing of data are three essential functions of a computer program.  Most programs.
1 STRINGS String data type Basic operations on strings String functions String procedures.
String Formatting Preparing strings for output. Printing println( arg ) prints its one argument on a line println can be used to print any single value,
S CCS 200: I NTERACTIVE I NPUT Lect. Napat Amphaiphan.
Data Types and Conversions, Input from the Keyboard CS303E: Elements of Computers and Programming.
Chapter 3 Assignment, Formatting, and Interactive Input C++ for Engineers and Scientists Third Edition.
1 Manipulators manipulators are used only in input and output statements endl, fixed, showpoint, setw, and setprecision are manipulators that can be used.
1 More on Readln:numerical values Note: ENTER key counts sends a carriage return and a line feed to the computer definition: “white space”: space, tab,
Data Types and Conversions, Input from the Keyboard If you can't write it down in English, you can't code it. -- Peter Halpern If you lie to the computer,
CMP 131 Introduction to Computer Programming Violetta Cavalli-Sforza Week 5, Lecture 2 (Tuesday)
Lecture 20: C File Processing. Why Using Files? Storage of data in variables and arrays is temporary Data lost when a program terminates. Files are used.
Input and Output Output Prompt: –A message displayed to the user indicating what they are to enter. Should be clear and exact on what you want. write:
1 Lecture Three I/O Formatting and Arithmetic Dr. Sherif Mohamed Tawfik.
Chapter 4 Chapter 4: Variables, Constants, and Arithmetic Operators.
1 Problems with teaching and learning programming Programming Syntax & Logic Problem Solving Skills Authenticity.
Chapter 2 – part b Brent M. Dingle Texas A&M University
C Formatted Input/Output
Topics Designing a Program Input, Processing, and Output
Using the Console.
Data Types and Conversions, Input from the Keyboard
TMF1414 Introduction to Programming
Input and Output Statements
Input/Output Input/Output operations are performed using input/output functions Common input/output functions are provided as part of C’s standard input/output.
INPUT & OUTPUT scanf & printf.
CS111 Computer Programming
Chapter 4 Managing Input and Output Operations
Topics Designing a Program Input, Processing, and Output
Topics Designing a Program Input, Processing, and Output
An Introduction to Programming with C++ Fifth Edition
C++ for Engineers and Scientists Second Edition
Presentation transcript:

Pascal Programming Today Chapter 2 1 Chapter 2

Pascal Programming Today Chapter 2 2 »Output statements write data to output devices (e.g. VDU). »Two output statements in Pascal: –writeln statements –write statements

Pascal Programming Today Chapter 2 3 » writeln statements move the cursor to the beginning of next line after printing but write statements do not.

Pascal Programming Today Chapter 2 4 Syntax of writeln statements writeln(,,..., ) Syntax of write statements write(,,..., )

Pascal Programming Today Chapter 2 5 »Differences between the output of writeln and write statements:

Pascal Programming Today Chapter 2 6 writeln(‘A’, ‘B’, ‘C’) write(‘A’, ‘B’, ‘C’) Output __

Pascal Programming Today Chapter 2 7 writeln(‘A’, ‘B’, ‘C’) write(‘A’, ‘B’, ‘C’) Output A_A_A_A_

Pascal Programming Today Chapter 2 8 writeln(‘A’, ‘B’, ‘C’) write(‘A’, ‘B’, ‘C’) Output AB_

Pascal Programming Today Chapter 2 9 writeln(‘A’, ‘B’, ‘C’) write(‘A’, ‘B’, ‘C’) Output ABC _ ABC_

Pascal Programming Today Chapter 2 10 writeln(‘A’); writeln(‘B’); writeln(‘C’) write(‘A’); write(‘B’); write(‘C’) Output __

Pascal Programming Today Chapter 2 11 writeln(‘A’); writeln(‘B’); writeln(‘C’) write(‘A’); write(‘B’); write(‘C’) Output A_A_ A_A_

Pascal Programming Today Chapter 2 12 writeln(‘A’); writeln(‘B’); writeln(‘C’) write(‘A’); write(‘B’); write(‘C’) Output AB_AB_ AB_

Pascal Programming Today Chapter 2 13 writeln(‘A’); writeln(‘B’); writeln(‘C’) write(‘A’); write(‘B’); write(‘C’) Output ABC_ABC_ ABC_

Pascal Programming Today Chapter 2 14 writeln(‘A’, ‘B’); writeln(‘C’, ‘D’); writeln(‘E’) write(‘A’, ‘B’); write(‘C’, ‘D’); write(‘E’) Output __

Pascal Programming Today Chapter 2 15 writeln(‘A’, ‘B’); writeln(‘C’, ‘D’); writeln(‘E’) write(‘A’, ‘B’); write(‘C’, ‘D’); write(‘E’) Output AB _ AB_

Pascal Programming Today Chapter 2 16 writeln(‘A’, ‘B’); writeln(‘C’, ‘D’); writeln(‘E’) write(‘A’, ‘B’); write(‘C’, ‘D’); write(‘E’) Output AB CD _ ABCD_

Pascal Programming Today Chapter 2 17 writeln(‘A’, ‘B’); writeln(‘C’, ‘D’); writeln(‘E’) write(‘A’, ‘B’); write(‘C’, ‘D’); write(‘E’) Output AB CD E _ ABCDE_

Pascal Programming Today Chapter 2 18 writeln(‘A’, ‘B’); writeln; writeln(‘C’, ‘D’); writeln(‘E’) write(‘A’, ‘B’); write; write(‘C’, ‘D’); write(‘E’) Output __

Pascal Programming Today Chapter 2 19 writeln(‘A’, ‘B’); writeln; writeln(‘C’, ‘D’); writeln(‘E’) write(‘A’, ‘B’); write; write(‘C’, ‘D’); write(‘E’) Output AB _ AB_

Pascal Programming Today Chapter 2 20 writeln(‘A’, ‘B’); writeln; writeln(‘C’, ‘D’); writeln(‘E’) write(‘A’, ‘B’); write; write(‘C’, ‘D’); write(‘E’) Output AB _ AB_

Pascal Programming Today Chapter 2 21 writeln(‘A’, ‘B’); writeln; writeln(‘C’, ‘D’); writeln(‘E’) write(‘A’, ‘B’); write; write(‘C’, ‘D’); write(‘E’) Output AB CD _ ABCD_

Pascal Programming Today Chapter 2 22 writeln(‘A’, ‘B’); writeln; writeln(‘C’, ‘D’); writeln(‘E’) write(‘A’, ‘B’); write; write(‘C’, ‘D’); write(‘E’) Output AB CD E _ ABCDE_

Pascal Programming Today Chapter 2 23 »All output items can be formatted to certain field widths by adding a colon ( : ) and a positive integer after them.

Pascal Programming Today Chapter 2 24 Syntax of formatting field widths writeln( :,..., : ) or write( :,..., : )

Pascal Programming Today Chapter 2 25 »If specified field widths are too large, leading blank(s) will be added and the output items will be right-justified. »If specified field widths are insufficient, the field widths will be increased automatically to accommodate the whole item.

Pascal Programming Today Chapter 2 26 writeln(12:6); writeln(35678:7); writeln(1234:2); writeln(98700:5); write(12:6); write(35678:7); write(1234:2); write(98700:5); Output __

Pascal Programming Today Chapter 2 27 writeln(12:6); writeln(35678:7); writeln(1234:2); writeln(98700:5); write(12:6); write(35678:7); write(1234:2); write(98700:5); Output 12 _ 12_

Pascal Programming Today Chapter 2 28 writeln(12:6); writeln(35678:7); writeln(1234:2); writeln(98700:5); write(12:6); write(35678:7); write(1234:2); write(98700:5); Output _ _

Pascal Programming Today Chapter 2 29 writeln(12:6); writeln(35678:7); writeln(1234:2); writeln(98700:5); write(12:6); write(35678:7); write(1234:2); write(98700:5); Output _ _

Pascal Programming Today Chapter 2 30 writeln(12:6); writeln(35678:7); writeln(1234:2); writeln(98700:5); write(12:6); write(35678:7); write(1234:2); write(98700:5); Output _ _

Pascal Programming Today Chapter 2 31 »Real values are normally printed in floating point notation. »Real values will be printed in decimal notation if number of decimal places is specified by adding a colon ( : ) and a positive integer after the field width.

Pascal Programming Today Chapter 2 32 Syntax of specifying number of decimal places of real values writeln( : :,..., : ): )

Pascal Programming Today Chapter 2 33 or write( : :,..., : ): )

Pascal Programming Today Chapter 2 34 writeln(-12.34); writeln(12.34:4); writeln(12.34:7); writeln(12.34:7:3); writeln(12.34:7:1); write(-12.34); write(12.34:4); write(12.34:7); write(12.34:7:3); write(12.34:7:1); Output __

Pascal Programming Today Chapter 2 35 writeln(-12.34); writeln(12.34:4); writeln(12.34:7); writeln(12.34:7:3); writeln(12.34:7:1); write(-12.34); write(12.34:4); write(12.34:7); write(12.34:7:3); write(12.34:7:1); Output E+01 _ E+01_

Pascal Programming Today Chapter 2 36 writeln(-12.34); writeln(12.34:4); writeln(12.34:7); writeln(12.34:7:3); writeln(12.34:7:1); write(-12.34); write(12.34:4); write(12.34:7); write(12.34:7:3); write(12.34:7:1); Output E E+01 _ E E+01_

Pascal Programming Today Chapter 2 37 writeln(-12.34); writeln(12.34:4); writeln(12.34:10); writeln(12.34:7:3); writeln(12.34:7:1); write(-12.34); write(12.34:4); write(12.34:10); write(12.34:7:3); write(12.34:7:1); Output E E E+01 _ E E E+01_

Pascal Programming Today Chapter 2 38 writeln(-12.34); writeln(12.34:4); writeln(12.34:10); writeln(12.34:7:3); writeln(12.34:7:1); write(-12.34); write(12.34:4); write(12.34:10); write(12.34:7:3); write(12.34:7:1); Output E E E _ E E E _

Pascal Programming Today Chapter 2 39 writeln(-12.34); writeln(12.34:4); writeln(12.34:10); writeln(12.34:7:3); writeln(12.34:7:1); write(-12.34); write(12.34:4); write(12.34:10); write(12.34:7:3); write(12.34:7:1); Output E E E _ E E E _

Pascal Programming Today Chapter 2 40 Syntax of readln statements readln(,,..., ) » readln statements receive data and store them into the variables listed in the parentheses relative to their position.

Pascal Programming Today Chapter 2 41 »Input statements receive data from input devices (e.g. keyboard).

Pascal Programming Today Chapter 2 42 Syntax of readln statements readln(,,..., ) » readln statements receive data and store them into the variables listed in the parentheses relative to their position.

Pascal Programming Today Chapter 2 43 »The program will pause and wait for input in the execution of readln statements. »If number of input data is more than the number of variables in readln statements, the exceeded input will be lost.

Pascal Programming Today Chapter 2 44 »If there are insufficient input, the program will pause to wait for the required input.

Pascal Programming Today Chapter 2 45 readln(A,B,C); writeln(‘A=’,A,’ B=‘,B,’ C=‘,C); Output A=1 B=2 C=3 _ Input _

Pascal Programming Today Chapter 2 46 readln(A,B,C); writeln(‘A=’,A,’ B=‘,B,’ C=‘,C); Output A=1 B=2 C=3 _ Input _ The fourth data will be lost.

Pascal Programming Today Chapter 2 47 readln(A,B,C); writeln(‘A=’,A,’ B=‘,B,’ C=‘,C); Output 1 2 _ Input 1 2 _ Waiting for the third item.

Pascal Programming Today Chapter 2 48 readln(A,B,C); writeln(‘A=’,A,’ B=‘,B,’ C=‘,C); Output Invalid numeric format _ Input F 1 2 _

Pascal Programming Today Chapter 2 49 readln(A,B,C); writeln(‘A=’,A,’ B=‘,B,’ C=‘,C); Output A=1 B=2 C=3 _ Input 123_123_