ICT
the blog for ICT
ken013194
暱稱: ホロ
性別: 男
國家: 香港
地區: 葵青區
« March 2015 »
SMTWTFS
1234567
891011121314
15161718192021
22232425262728
293031
最新文章
Text File
Arrays
String Procedures
String Functions
String Operation
文章分類
全部 (23)
Programming Language (23)
訪客留言
最近三個月尚無任何留言
每月文章
日誌訂閱
尚未訂閱任何日誌
好友名單
尚無任何好友
網站連結
尚無任何連結
最近訪客
最近沒有訪客
日誌統計
文章總數: 23
留言總數: 0
今日人氣: 0
累積人氣: 81
站內搜尋
RSS 訂閱
RSS Feed
2009 年 9 月 11 日  星期五   晴天


I/O Statement 分類: Programming Language

High-level Programming Language (Pascal)

Program Input and Output

To be useful, a program needs some means to communicate with the user. They are input statements and output statements.

Input Statements

  • are used to enable the user to input data
  • to get raw data prepared by the user in order to start processing
  • to get responses from the user when there are more than one action which the program can take
  • it is a good practice to include some kinds of prompt whenever input is required
  • there are two input statements in Pascal : read and readln (read as read line)
    • read and readln are predefined input procedures
    • can read different types of data values from the keyboard or data file and assign the data to the corresponding variable(s)
    • the data type to be read must be consistent with the variable(s) declared in variable declaration part (the only exception is that an integer can be assigned to a real-type variable, because an integer is a subset of real numbers)
    • general forms of the input statements

      read (<input list>)
      readln (<input list>)
      readln

      1. where <input list> is a single variable or a list of variables separated by commas
      2. only one string can be included in the input list of read or readln and it must be the last in the list
      3. during data input, data values must be separated by one or more space(s)
      4. execution of these input statements reads values from the standard file input and assigns them to the variables in the <input list>
      5. whenever executes a readln statement it pauses and waits for the required data
      6. after values have been read for all the variables, readln causes an advance to a new input line from which subsequent values will be read
      7. whereas read causes no such advance
      8. the last form of readln with no <input list> terminates input from the current line, so that subsequent input begins on a new line (i.e. program execution is suspended, providing an opportunity for the user to examine the output)

    • type of argument of the input statements

      Type of Argument
      Action of read on the argument
      char
      Assign the next input character to its argument
      integer
      Skip any blank, tab or carriage return, then read an integer that must end with a blank, tab or carriage return. The ending character is not read.
      real
      Same as integer but a real number is read.
      string
      Read all characters up to, but not including the carriage return.

Output Statements

  • provides a method for easily displaying information
  • to output messages or results of a program to the user
  • there are two output statements in Pascal : write and writeln (read as write line)
    • write and writeln are predefined output procedures
    • general forms of the output statements

      write (<output list>)
      writeln (<output list>)
      writeln

      1. where <output list> is a single expression or a list of expressions separated by commas and each of these expressions may be a constant, a variable or a formula
      2. writeln statement will display program results and move the cursor to the beginning of next line
      3. write statements will display program results without moving the cursor to the beginning of next line
      4. the last form of writeln with no output list will cause the cursor to advance to a new line to display a blank line

    • a list of examples

      Action
      Statement
      Output
      12345678901234567
      Printing a number
       Positive integer
       Negative integer
       Real number

      writeln (123);
      writeln (-123);
      writeln (123.0);
       

      123
      -123
       1.230000000E+02
      Printing a character writeln ('A'); A
      Printing a string writeln ('Hello'); Hello
      Printing a list of data items writeln ('A', 'B', 'C');
      writeln ('Hello', 'John');
      writeln (1, '+', 2, 'is ', 3);
      ABC
      HelloJohn
      1+2 is 3
      Printing an expression writeln ('Sum = ', 2 + 6); Sum = 8
      Printing Boolean writeln ('3>2 is ', 3>2); 3>2 is TRUE

       
    • The difference between write and writeln

      Statements
      Output
      123456789012345678901234567
      writeln ('Hello');
      writeln ('Welcome to Pascal Programming');
      Hello
      Welcome to Pascal Programming
      write ('Hello');
      write ('Welcome to Pascal Programming');
      HelloWelcome to Pascal Programming





訪客留言 (返回 ken013194 的日誌)

訪客名稱:
電郵地址: (不會公開)
驗證碼:  按此更新驗證碼 (如看不清楚驗證碼請點擊圖片刷新)
俏俏話: (必需 登入 後才能使用此功能)
[ 開啟多功能編輯器 ]