1 / 20

cout untuk menampilkan suatu informasi ke layar monitor. contoh : cout<<“C++”;

Operasi Dasar Input/Output. cout untuk menampilkan suatu informasi ke layar monitor. contoh : cout&lt;&lt;“C++”; untuk pindah baris bisa menggunakan karakter <br>. contoh : cout&lt;&lt;“C++ <br>”;. Operasi Dasar Input/Output. Manipulator

tucker-lee
Télécharger la présentation

cout untuk menampilkan suatu informasi ke layar monitor. contoh : cout&lt;&lt;“C++”;

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. Operasi Dasar Input/Output cout untuk menampilkan suatu informasi ke layar monitor. contoh : cout<<“C++”; untuk pindah baris bisa menggunakan karakter \n. contoh : cout<<“C++ \n”;

  2. Operasi Dasar Input/Output Manipulator Manipulator digunakan untuk mengatur tampilan data. Misalnya untuk mengatur agar suatu nilai ditampilkan dengan lebar 10 karakter.

  3. Operasi Dasar Input/Output

  4. Operasi Dasar Input/Output contoh endl: #include <iostream.h> void main() { cout<<“Pemrograman Berorientasi Objek”<<endl; cout<<“Dengan menggunakan C++”<<endl; } Pemrograman Berorientasi Objek Dengan menggunakan C++

  5. Operasi Dasar Input/Output Contoh setw(): #include <iostream.h> #include <iomanip.h> void main() { int a,b,c; a = 15; b = 155; c = 1423; cout<<“a = “<<setw(4)<<a<<endl; cout<<“b = “<<setw(4)<<b<<endl; cout<<“c = “<<setw(4)<<c<<endl; } a = 15 b = 155 c = 1423

  6. Operasi Dasar Input/Output contoh setfill(): #include <iostream.h> #include <iomanip.h> void main() { float harga; harga = 123.25; cout<<setfill(‘*’); cout<<setw(8)<<harga<<endl; } **123.25

  7. Operasi Dasar Input/Output contoh dec, oct dan hex: #include <iostream.h> #include <iomanip.h> void main() { int nilai = 250; cout<<oct<<nilai<<endl; cout<<hex<<nilai<<endl; cout<<dec<<nilai<<endl; } 372 fa 250

  8. Operasi Dasar Input/Output contoh setbase(): #include <iostream.h> #include <iomanip.h> void main() { int nilai = 250; cout<<setbase(8)<<nilai<<endl; cout<<setbase(16)<<nilai<<endl; cout<<setbase(10)<<nilai<<endl; } 372 fa 250

  9. Operasi Dasar Input/Output setiosflags() digunakan untuk membuat manipulator sejumlah format seperti pada tabel berikut:

  10. Operasi Dasar Input/Output

  11. Operasi Dasar Input/Output contoh ios::left dan ios::right : #include <iostream.h> #include <iomanip.h> void main() { int a = 123; int b = 456; cout<<setw(6)<<a<<setw(6)<<b<<endl; cout<<setiosflags(ios::left); cout<<setw(6)<<a<<setw(6)<<b<<endl; cout<<resetiosflags(ios::left); cout<<setiosflags(ios::right); cout<<setw(6)<<a<<setw(6)<<b<<endl; } 123 456 123 456

  12. Operasi Dasar Input/Output contoh ios::scientific : #include <iostream.h> #include <iomanip.h> void main() { cout<<setiosflags(ios::scientific); cout<<12345.6789; } 1.234568e+02

  13. Operasi Dasar Input/Output contoh ios::fixed : #include <iostream.h> #include <iomanip.h> void main() { cout<<setiosflags(ios::fixed); cout<<123.45; } 123.450000

  14. Operasi Dasar Input/Output contoh ios::showpoint : #include <iostream.h> #include <iomanip.h> void main() { cout<<123.00<<endl; cout<<setiosflags(ios::showpoint); cout<<123.00; } 123 123.00

  15. Operasi Dasar Input/Output contoh ios::uppercase : #include <iostream.h> #include <iomanip.h> void main() { int bil = 26; cout<<hex<<bil<<endl; cout<<setiosflags(ios::uppercase); cout<<hex<<bil; } 1a 1A

  16. Operasi Dasar Input/Output contoh ios::showbase : #include <iostream.h> #include <iomanip.h> void main() { int bil = 45; cout<<hex<<bil<<endl; cout<<setiosflags(ios::showbase); cout<<hex<<bil; } 2d 0x2d

  17. Operasi Dasar Input/Output contoh setprecision() : #include <iostream.h> #include <iomanip.h> void main() { float bil = 123.45; cout<<setiosflags(ios::fixed); cout<<setprecision(0)<<bil<<endl; cout<<setprecision(1)<<bil<<endl; cout<<setprecision(2)<<bil<<endl; cout<<setprecision(3)<<bil<<endl; cout<<setprecision(4)<<bil<<endl; cout<<setprecision(5)<<bil<<endl; cout<<setprecision(6)<<bil<<endl; cout<<setprecision(7)<<bil<<endl; }

  18. Operasi Dasar Input/Output 123 123.4 123.45 123.450 123.4500 123.45000 123.449997 123.4499969

  19. Operasi Dasar Input/Output contoh penggabungan set : #include <iostream.h> #include <iomanip.h> void main() { int bil = 45; cout<<hex<<bil<<endl; cout<<setiosflags(ios::showbase|ios::uppercase); cout<<hex<<bil; } 2d 0x2D

More Related