DOC PREVIEW
TAMU CSCE 110 - Input and Output
Type Lecture Note
Pages 29

This preview shows page 1-2-3-27-28-29 out of 29 pages.

Save
View full document
View full document
Premium Document
Do you want full access? Go Premium and unlock all 29 pages.
Access to all documents
Download any document
Ad free experience
View full document
Premium Document
Do you want full access? Go Premium and unlock all 29 pages.
Access to all documents
Download any document
Ad free experience
View full document
Premium Document
Do you want full access? Go Premium and unlock all 29 pages.
Access to all documents
Download any document
Ad free experience
View full document
Premium Document
Do you want full access? Go Premium and unlock all 29 pages.
Access to all documents
Download any document
Ad free experience
View full document
Premium Document
Do you want full access? Go Premium and unlock all 29 pages.
Access to all documents
Download any document
Ad free experience
View full document
Premium Document
Do you want full access? Go Premium and unlock all 29 pages.
Access to all documents
Download any document
Ad free experience
Premium Document
Do you want full access? Go Premium and unlock all 29 pages.
Access to all documents
Download any document
Ad free experience

Unformatted text preview:

Input and Output (IO)OutputSlide 3Output ExampleOutput the Contents Of Variables And ConstantsOutput Variables And Constants ExampleMixed OutputMixed Output ExampleAutomatic Output FormattingManual Output FormattingFormatting OutputSlide 12Slide 13Slide 14InputInput ExampleRead & ReadlnRead Vs. ReadlnRead: Effect On The Keyboard BufferRead: Effect On The Keyboard BufferReadln: Effect On The Keyboard BufferReadln: Effect On The Keyboard BufferSlide 23Slide 24Read ExampleReadln ExampleGeneral Rule Of ThumbSlide 28Another Use For ReadlnJ. Michael MooreInput and Output (IO)CSCE 110Drawn from James Tam's materialJ. Michael MooreOutput•Displaying information on screen•Done via the write and writeln statements–Write: displays the output ______________ (the cursor remains on the line)–Writeln: displays the output ____________ _____ (the _______ moves to __________)J. Michael MooreOutput•Format (literal string of characters):write ('a message'); ORwriteln ('a message');J. Michael MooreOutput Exampleprogram outputExample1 (output);begin write('line1'); writeln('line2'); write('line3');end.Style conventionOr is it?•You can find an copy of this program and the compiled version in the course directory:/pub/courses/csce110/J. Michael MooreOutput the Contents Of Variables And Constants•Format: write(<name of variable> or <constant>); or writeln (<name of variable> or <constant>);J. Michael MooreOutput Variables And Constants Exampleprogram outputExample2 (output);const ACONSTANT = 888;begin var num : integer; num := 7; writeln(ACONSTANT); writeln(num);end.•You can find an copy of this program and the compiled version in the course directory:/pub/courses/csce110/J. Michael MooreMixed Output•It's possible to display literal strings of characters and the contents of variables and constants with a single write or writeln statement.•Format: write('message', <name of variable>, 'message'…);OR writeln('message', <name of variable>, 'message'…);J. Michael MooreMixed Output Exampleprogram outputExample3 (output);const ACONSTANT = 888;begin var num : integer; num := 7; writeln('ACONSTANT: ', ACONSTANT); writeln('num=', num);end.•You can find an copy of this program and the compiled version in the course directory:/pub/courses/csce110/J. Michael MooreAutomatic Output Formatting•Automatic formatting of output–Field width: The computer will insert enough spaces to ______________________________ _______________.–Decimal places: For ____ numbers the data will be displayed in _____________________ form.1 These values can be set to any non-negative integer (zero or greater).J. Michael MooreManual Output Formatting•Format:write or writeln (<data>:<Field width for data1>:<Number decimal places for real data1>);•Examples: var num : real; num := 12.34; writeln(num); writeln(num:5:2);1 These values can be set to any non-negative integer (zero or greater).J. Michael MooreFormatting Output•If the field width doesn't match the actual size of the field–Field width too small – extra spaces will be added for ___________ variables but not for _______________________________.–Examples: var num : integer; num := 123456; writeln(num:3); writeln('123456':3);J. Michael MooreFormatting Output•If the field width doesn't match the actual size of the field–Field width too large – the data will be _______ justified (extra spaces will be put ___________ the data).–Examples: var num : integer; num := 123; writeln(num:6); writeln('123':6);J. Michael MooreFormatting Output•If the number of decimal places doesn't match the actual number of decimal places.–Set the ______________________ less than the _____________________________ – the number will be ______________________.–Example One: var num : real; num := 123.4567; writeln (num:6:2);J. Michael MooreFormatting Output•If the number of decimal places doesn't match the actual number of decimal places.–Set the ____________________ greater than the _____________________________ – the number _____________________________. –Example Two: var num : real; num := 123.4567; writeln(num:12:6);J. Michael MooreInput•The computer program getting information from the user•Done via the read and readln statements•Format:read (<name of variable to store the input>); OR readln (<name of variable to store the input>);J. Michael MooreInput Exampleprogram inputExampleOne (input, output);begin var num : integer; write('Enter an integer: '); readln (num); end.Normally Style…J. Michael MooreRead & Readln•Reads each ______ entered and matches it to the corresponding ____________. –e.g., read (num) –If num is an integer then the read statement will try to read an integer value from the user's keyboard input.J. Michael MooreRead Vs. Readln•Read –If the user ______________________ before hitting enter, the _______________________ ____________________.•Readln–Any _______________ before (and including) the enter key ________________________.J. Michael MooreRead: Effect On The Keyboard Bufferprogram getInput (input, output);begin var num : integer; write('Enter an integer: '); read(num);end.Pascal programKeyboard: user types in 27 and hits enterJ. Michael MooreRead: Effect On The Keyboard Bufferprogram getInput (input, output);begin var num : integer; write('Enter an integer: '); read(num);end.Pascal program2 7 <EOL>1Keyboard controller: determines which keys were pressed and stores the values in the keyboard buffer 1 When the user presses the enter key it is stored as the EOL (end-of-line) marker. The EOL marker signals to the Pascal program that the information has been typed in and it will be processed.Y YNNote: after the read statement has executed the pointer remains at the EOL marker.RAM27numJ. Michael MooreReadln: Effect On The Keyboard Bufferprogram getInput (input, output);begin var num : integer; write('Enter an integer: '); readln(num);end.Pascal programKeyboard: user types in 27 and hits enterJ. Michael MooreReadln: Effect On The Keyboard Bufferprogram getInput (input, output);begin var num : integer; write('Enter an integer: '); readln(num);end.Pascal program2 7 <EOL>1Keyboard controller: determines which keys were pressed and stores the values in the keyboard buffer 1 When the user presses the enter key it is stored as the EOL (end-of-line) marker. The EOL marker signals to the Pascal program that


View Full Document

TAMU CSCE 110 - Input and Output

Type: Lecture Note
Pages: 29
Documents in this Course
06-IO

06-IO

29 pages

21-OOP

21-OOP

8 pages

key

key

6 pages

21-OOP

21-OOP

8 pages

Load more
Download Input and Output
Our administrator received your request to download this document. We will send you the file to your email shortly.
Loading Unlocking...
Login

Join to view Input and Output and access 3M+ class-specific study document.

or
We will never post anything without your permission.
Don't have an account?
Sign Up

Join to view Input and Output 2 2 and access 3M+ class-specific study document.

or

By creating an account you agree to our Privacy Policy and Terms Of Use

Already a member?