TUGAS PRAKTIKUM STRUKTUR DATA
"DEFINISI SETPRECISION() DAN SETBASE() BESERTA CONTOH CODINGNYA"
"DEFINISI SETPRECISION() DAN SETBASE() BESERTA CONTOH CODINGNYA"
PROGRAM STUDI INFORMATIKA (S1)
FAKULTAS TEKNIK
UNIVERSITAS MUHAMMADIYAH PROF. DR. HAMKA JAKARTA
2018
1.SETPRECISION()
merupakan suatu fungsi manipulator yang digunakan untuk mengatur jumlah digit decimal yang ingin ditampilakan.
Contoh listing program adalah:
#include <iomanip>
#include <stdio.h>
#include <string.h>
using namespace std;
int main () {
float nilai = 123.45;
cout << setiosflags(ios::fixed);
cout << setprecision(0) << nilai << endl;
cout << setprecision(1) << nilai << endl;
cout << setprecision(2) << nilai << endl;
cout << setprecision(3) << nilai << endl;
cout << setprecision(4) << nilai << endl;
cout << setprecision(5) << nilai << endl;
cout << setprecision(6) << nilai << endl;
cout << setprecision(7) << nilai << endl;
}
Hasil Eksekusi :
2.SETBASE()
Merupakan suatu fungsi manipulator yang digunakan untuk konversi bilangan octal, Decimal, dan Hexadecimal.file yang header yang harus di sertakan iomanip.h.
Contoh listing programnya adalah sbb:
#include <conio.h>
#include <iostream>
#include <iomanip>
using namespace std;
main()
{
int a=250;
cout<<"PENGGUNAAN MANUPULATOR SETBASE()"<<"\n\n";
cout<<"============================"<<"\n";
cout<<"Decimal Octal Hexadecimal"<<endl;
cout<<"============================"<<"\n";
for(a=250;a<=260;a++)
{
cout<<setbase (10)<<a<<" ";
cout<<setbase (8)<<a<<" ";
cout<<setbase (16)<<a<<endl;
}
}

Tidak ada komentar:
Posting Komentar