+ All Categories
Home > Documents > Standard Input - Output

Standard Input - Output

Date post: 23-Feb-2016
Category:
Upload: nibaw
View: 44 times
Download: 0 times
Share this document with a friend
Description:
Standard Input - Output. By: Muhammad Zidny Naf’an. Output Command. cout() printf() puts() putchar(). cout(). Show the data to screen We must include header file “iostream.h” Ex:. printf(). Function declaration: printf(“string control”, argument1, argument2); Use header header - PowerPoint PPT Presentation
Popular Tags:
25
Standard Input - Output By: Muhammad Zidny Naf’an Algorithm and Data Structure, UIN Syarif Hidayatullah Jakarta, 2012
Transcript
Page 1: Standard Input - Output

Algorithm and Data Structure, UIN Syarif Hidayatullah Jakarta, 2012

Standard Input - Output

By: Muhammad Zidny Naf’an

Page 2: Standard Input - Output

Algorithm and Data Structure, UIN Syarif Hidayatullah Jakarta, 2012

Output Command cout() printf() puts() putchar()

Page 3: Standard Input - Output

Algorithm and Data Structure, UIN Syarif Hidayatullah Jakarta, 2012

cout() Show the data to screen We must include header file “iostream.h” Ex:

Page 4: Standard Input - Output

Algorithm and Data Structure, UIN Syarif Hidayatullah Jakarta, 2012

printf() Function

declaration:printf(“string control”, argument1, argument2);

Use header header“stdio.h”

Data type Determining

formatInteger %dFloat decimal form exponential decimal and exponential

%f%e%g

Double precission %lfCharacter %cString %sUnsigned integer %uLong integer %ldLong unsigned integer %luUnsigned hexadecimal integer

%x

Unsigned octal integer %o

Page 5: Standard Input - Output

Algorithm and Data Structure, UIN Syarif Hidayatullah Jakarta, 2012

printf() Ex:

Page 6: Standard Input - Output

Algorithm and Data Structure, UIN Syarif Hidayatullah Jakarta, 2012

puts() Print the string in the screen Use “stdio.h”

Page 7: Standard Input - Output

Algorithm and Data Structure, UIN Syarif Hidayatullah Jakarta, 2012

putchar() Print a character to screen

Page 8: Standard Input - Output

Algorithm and Data Structure, UIN Syarif Hidayatullah Jakarta, 2012

Manipulation

Page 9: Standard Input - Output

Algorithm and Data Structure, UIN Syarif Hidayatullah Jakarta, 2012

endl() Insert new line

Page 10: Standard Input - Output

Algorithm and Data Structure, UIN Syarif Hidayatullah Jakarta, 2012

ends() Insert null character

Page 11: Standard Input - Output

Algorithm and Data Structure, UIN Syarif Hidayatullah Jakarta, 2012

dec, oct, hex Convert number to decimal, octal, and

hexadecimal Use “iomanip.h”

Page 12: Standard Input - Output

Algorithm and Data Structure, UIN Syarif Hidayatullah Jakarta, 2012

setprecission() Formatting the number of decimal digit that

will showed Use “iomanip.h”

Page 13: Standard Input - Output

Algorithm and Data Structure, UIN Syarif Hidayatullah Jakarta, 2012

setbase(base number) To convert decimal, hexadesimal, and octal. Base number: 10 for decimal, 8 for octal, 16 for

hexdecimal

Page 14: Standard Input - Output

Algorithm and Data Structure, UIN Syarif Hidayatullah Jakarta, 2012

setw(int width) Set variable’s width in screen User “iomanip.h”

Page 15: Standard Input - Output

Algorithm and Data Structure, UIN Syarif Hidayatullah Jakarta, 2012

setfill(char character) Fill blank from setw with character Use iomanip.h

Page 16: Standard Input - Output

Algorithm and Data Structure, UIN Syarif Hidayatullah Jakarta, 2012

setiosflags() Formatting output Example: Align text in screen (align left or

right) Using “iomanip.h”

Page 17: Standard Input - Output

Algorithm and Data Structure, UIN Syarif Hidayatullah Jakarta, 2012

Page 18: Standard Input - Output

Algorithm and Data Structure, UIN Syarif Hidayatullah Jakarta, 2012

Input Command cin scanf() gets() getch() getche()

Page 19: Standard Input - Output

Algorithm and Data Structure, UIN Syarif Hidayatullah Jakarta, 2012

cin Without formatting input Use “iostream.h”

Page 20: Standard Input - Output

Algorithm and Data Structure, UIN Syarif Hidayatullah Jakarta, 2012

scanf(“format setting”, &variable) Input data with formatting

Data type Determining

formatInteger %dFloat decimal form exponential

%f%e

Double precision %lfCharacter %cString %sUnsigned integer %uLong integer %ldLong unsigned integer %luUnsigned hexadecimal integer

%x

Unsigned octal integer %o

Page 21: Standard Input - Output

Algorithm and Data Structure, UIN Syarif Hidayatullah Jakarta, 2012

scanf(“format setting”, variable) Example: Use “stdio.h”

Page 22: Standard Input - Output

Algorithm and Data Structure, UIN Syarif Hidayatullah Jakarta, 2012

gets(char[] string) Input string from keyboard Use “stdio.h”

Page 23: Standard Input - Output

Algorithm and Data Structure, UIN Syarif Hidayatullah Jakarta, 2012

getch() Stands for get character and echo Input one character, and we aren’t need push

“enter” button to execute, and character will not be showed in screen

Use “conio.h”

Page 24: Standard Input - Output

Algorithm and Data Structure, UIN Syarif Hidayatullah Jakarta, 2012

getch() Stands for get character and echo Input one character, and we aren’t need push

“enter” button to execute, and character will be showed in screen

Use “conio.h”

Page 25: Standard Input - Output

Algorithm and Data Structure, UIN Syarif Hidayatullah Jakarta, 2012

Exercise Write the program to count average from a

student’s score. The are 3 scores. Average Formula = (score1+score2+

score3)/3 Input format:

Output format:

********** INPUT SCORE ********* Name : <input> score 1 : <input> score 2 : <input> score 3 : <input>

********** AVERAGE SCORE ********* Name : <name> score 1 : <score1> score 2 : < score2> score 3 : < score3> Average: <average>


Recommended