Standard Input Output By Muhammad Zidny Nafan Algorithm
Standard Input - Output By: Muhammad Zidny Naf’an Algorithm and Data Structure, UIN Syarif Hidayatullah Jakarta, 2012
Output Command � cout() � printf() � puts() � putchar() Algorithm and Data Structure, UIN Syarif Hidayatullah Jakarta, 2012
cout() � Show the data to screen � We must include header file “iostream. h” � Ex: Algorithm and Data Structure, UIN Syarif Hidayatullah Jakarta, 2012
printf() � Function Data type declaration: printf(“string Integer control”, Float decimal form argument 1, exponential argument 2); decimal and exponential � Use header “stdio. h” Determining format %d %f %e %g Double precission %lf Character %c String %s Unsigned integer %u Long integer %ld Long unsigned integer %lu Unsigned hexadecimal integer %x Unsigned octal integer %o Algorithm and Data Structure, UIN Syarif Hidayatullah Jakarta, 2012
printf() � Ex: Algorithm and Data Structure, UIN Syarif Hidayatullah Jakarta, 2012
puts() � Print the string in the screen � Use “stdio. h” Algorithm and Data Structure, UIN Syarif Hidayatullah Jakarta, 2012
putchar() � Print a character to screen Algorithm and Data Structure, UIN Syarif Hidayatullah Jakarta, 2012
Manipulation Algorithm and Data Structure, UIN Syarif Hidayatullah Jakarta, 2012
endl() � Insert new line Algorithm and Data Structure, UIN Syarif Hidayatullah Jakarta, 2012
ends() � Insert null character Algorithm and Data Structure, UIN Syarif Hidayatullah Jakarta, 2012
dec, oct, hex � Convert number to decimal, octal, and hexadecimal � Use “iomanip. h” Algorithm and Data Structure, UIN Syarif Hidayatullah Jakarta, 2012
setprecission() � Formatting the number of decimal digit that will showed � Use “iomanip. h” 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 Algorithm and Data Structure, UIN Syarif Hidayatullah Jakarta, 2012
setw(int width) � Set variable’s width in screen � User “iomanip. h” Algorithm and Data Structure, UIN Syarif Hidayatullah Jakarta, 2012
setfill(character) � Fill blank from setw with character � Use iomanip. h Algorithm and Data Structure, UIN Syarif Hidayatullah Jakarta, 2012
setiosflags() � Formatting output � Example: Align text in screen (align left or right) � Using “iomanip. h” Algorithm and Data Structure, UIN Syarif Hidayatullah Jakarta, 2012
Algorithm and Data Structure, UIN Syarif Hidayatullah Jakarta, 2012
Input Command � cin � scanf() � gets() � getche() Algorithm and Data Structure, UIN Syarif Hidayatullah Jakarta, 2012
cin � Without formatting input � Use “iostream. h” Algorithm and Data Structure, UIN Syarif Hidayatullah Jakarta, 2012
scanf(“format setting”, &variable) � Input data with formatting Data type Determining format Integer %d Float decimal form exponential %f %e Double precision %lf Character %c String %s Unsigned integer %u Long integer %ld Long unsigned integer %lu Unsigned hexadecimal integer %x Unsigned octal integer %o Algorithm and Data Structure, UIN Syarif Hidayatullah Jakarta, 2012
scanf(“format setting”, variable) � Example: � Use “stdio. h” Algorithm and Data Structure, UIN Syarif Hidayatullah Jakarta, 2012
gets(char[] string) � Input string from keyboard � Use “stdio. h” 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” 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” 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 = (score 1+score 2+ score 3)/3 � Input format: ***** INPUT SCORE ***** Name score 1 score 2 score 3 � Output format: : <input> ***** AVERAGE SCORE ***** Name : <name> score 1 : <score 1> score 2 : < score 2> score 3 : < score 3> Average: <average> Algorithm and Data Structure, UIN Syarif Hidayatullah Jakarta, 2012
- Slides: 25