LAB D SORE Latihan C++ Class, Class Array, Struct, Struc Array
ESH/DONI
Latihan Class Biasa #include<stdio.h> #include
#include class pesawat { public: char nama[30],*napes; int beli,kode,harga; long int jumlah,total,ppn,diskon; }; main() { clrscr(); pesawat tiket; cout<<" Travel AL-Mukti"<<endl; cout<<"=============================================="<<endl; cout<<"Nama Penumpang :";gets(tiket.nama); cout<<"Kode Pesawat [1/2/3/4]:";cin>>tiket.kode; cout<<"Jumlah Tiket :";cin>>tiket.beli; if(tiket.kode==1) {tiket.napes="Lion Air"; tiket.harga=200000; } else if(tiket.kode==2) {tiket.napes="Adam Air"; tiket.harga=300000; } else if(tiket.kode==3) {tiket.napes="Star Air"; tiket.harga=350000; } else {tiket.napes="Batavia Air"; tiket.harga=255000; } cout<<"Nama Pesawat :"<5) tiket.diskon=tiket.jumlah*5/100; else 1 Akademi Manajemen Informatika dan Komputer Bina Sarana Informatika
LAB D SORE Latihan C++ Class, Class Array, Struct, Struc Array
ESH/DONI
tiket.diskon=0; cout<<"Diskon :"<
Layout Class Biasa
2 Akademi Manajemen Informatika dan Komputer Bina Sarana Informatika
LAB D SORE Latihan C++ Class, Class Array, Struct, Struc Array
ESH/DONI
Latihan Ke 1 Class Array
DAFTAR GAJI PEGAWAI PT.MAKMUR ``````````````````````````````````````````````````````````````````````````````````````````````````````````````````````````````````` Input Jumlah Karyawan : Data Karyawan Ke 1 NIP : Nama Pegawai : Golongan : Jabatan : Gaji Pokok : Tunjangan Jabatan : REKAPITULASI DAFTAR GAJI PEGAWAI PT. MAKMUR ``````````````````````````````````````````````````````````````````````````````````````````````````````````````````````````````````` NIP NAMA GOLONGAN JABATAN GAJI TUNJANGAN PPH GAJI PEGAWAI POKOK JABATAN BERSIH ```````````````````````````````````````````````````````````````````````````````````````````````````````````````````````````````````
``````````````````````````````````````````````````````````````````````````````````````````````````````````````````````````````````` JUMLAH SELURUH GAJI :Rp.
Ketentuan Soal : Golongan 1 2
Jabatan Tetap Honorer
Gaji Pokok 3000000 2500000
Tunjangan Jabatan 10% dari Gaji Pokok Tidak dapat tunjangan
PPH = 10% dari Gaji Pokok Gaji Bersih =Gaji Pokok+Tunjangan Jabatan-PPH
3 Akademi Manajemen Informatika dan Komputer Bina Sarana Informatika
LAB D SORE Latihan C++ Class, Class Array, Struct, Struc Array
ESH/DONI
Listing Program: #include<stdio.h> #include #include #include class gaji { public: char nip[10],nama[20],*jab; long int jum_total,gapok,tunjab,pph,gaji_bersih; int gol; }; main() { int i,j; float jum_total; gaji pegawai[10]; cout<<" DAFTAR GAJI PEGAWAI "<<endl; cout<<" PT. MAKMUR "<<endl; cout<<"========================================="<<endl; cout<<"input jumlah pegawai :";cin>>j; for (i=1;i<=j;i++) { cout<<"data pegawai ke-"<>pegawai[i].nip; cout<<"NAMA :";gets(pegawai[i].nama); cout<<"Gol [1/2] :";cin>>pegawai[i].gol; if(pegawai[i].gol==1) {pegawai[i].jab="Tetap"; pegawai[i].gapok=3000000; pegawai[i].tunjab=pegawai[i].gapok*10/100; } else {pegawai[i].jab="Honorer"; pegawai[i].gapok=2500000; pegawai[i].tunjab=0; } cout<<"Jabatan :"<
LAB D SORE Latihan C++ Class, Class Array, Struct, Struc Array
ESH/DONI
cout<<"================================================================="<<endl; cout<<"NIP Nama Golongan Jabatan Gaji Tunjangan PPH Gaji "<<endl; cout<<" Pegawai Pokok Jabatan Bersih"<<endl; cout<<"================================================================="<<endl; for(i=1;i<=j;i++) { cout<<setiosflags(ios::left)<<setw(12)<
5 Akademi Manajemen Informatika dan Komputer Bina Sarana Informatika
LAB D SORE Latihan C++ Class, Class Array, Struct, Struc Array
ESH/DONI
Latihan Ke 2 Class Array #include<stdio.h> #include #include #include class penginapan { public: char kode[5],*nama[5]; int harga[5],lama[5]; long int bayar[5]; }; main() { char lagi; float total; int i,j; penginapan hotel; awal: clrscr(); cout<<" PENGINAPAN HOTEL HANDA YANNA "<<endl; cout<<"=================================================================="<<endl ; cout<<"Masukan jumlah data =";cin>>j; for (i=1;i<=j;i++) { cout<<"data penyewa ke- :"<>hotel.kode[i]; if (hotel.kode[i]=='A'||hotel.kode[i]=='a') {hotel.nama[i]="Angel"; hotel.harga[i]=500000; 6 Akademi Manajemen Informatika dan Komputer Bina Sarana Informatika
LAB D SORE Latihan C++ Class, Class Array, Struct, Struc Array
ESH/DONI
} else if (hotel.kode[i]=='B'||hotel.kode[i]=='b') {hotel.nama[i]="Bunga"; hotel.harga[i]=255000; } else {hotel.nama[i]="Cantik"; hotel.harga[i]=350000; } cout<<"nama kamar :"<>hotel.lama[i]; hotel.bayar[i]=hotel.lama[i]*hotel.harga[i]; cout<<"total bayar :"<>lagi; if(lagi=='Y'||lagi=='y') goto awal; else goto akhir; akhir: getch(); } 7 Akademi Manajemen Informatika dan Komputer Bina Sarana Informatika
LAB D SORE Latihan C++ Class, Class Array, Struct, Struc Array
ESH/DONI
Layout Ke 2 Class Array
8 Akademi Manajemen Informatika dan Komputer Bina Sarana Informatika
LAB D SORE Latihan C++ Class, Class Array, Struct, Struc Array
ESH/DONI
Latihan Struct Biasa #include<stdio.h> #include #include main() { struct { char nim[10],nama[20]; float nilai; } mahasiswa; clrscr(); cout<<"masukan NIM :";cin>>mahasiswa.nim; cout<<"masukan Nama :";gets(mahasiswa.nama); cout<<"masukan Nilai:";cin>>mahasiswa.nilai; clrscr(); cout<<"NIM :"<<mahasiswa.nim<<endl; cout<<"Nama :"<<mahasiswa.nama<<endl; cout<<"Nilai :"<<mahasiswa.nilai<<endl; getch(); }
Layout Struct Biasa
9 Akademi Manajemen Informatika dan Komputer Bina Sarana Informatika
LAB D SORE Latihan C++ Class, Class Array, Struct, Struc Array
ESH/DONI
Latihan Struct Array
#include<stdio.h> #include #include #include main() { int i,j; const upah=40000; char bulan[25],lagi; float total_jam,total_lem; struct { char nik[9],nama[25]; int jml_jam; float upah_lem,total_gaji; } pegawai[5]; clrscr(); cout<<"masukkan jumlah data :";cin>>j; for (i=1;i<=j;i++) { awal: clrscr(); cout<<"data pegawai ke- :"<>pegawai[i].nik; cout<<"Nama karyawan :";gets(pegawai[i].nama); cout<<"jumlah jam lembur :";cin>>pegawai[i].jml_jam; cout<<endl; } clrscr(); cout<<" DAFTAR LEMBUR KARYAWAN "<<endl; cout<<endl; cout<<"Bulan = ";cin>>bulan; cout<<"===================================================================="<<e ndl; cout<<"No. NIK Nama Upah jumlah total gaji "<<endl; cout<<" lembur jam lembur "<<endl; cout<<"====================================================================="<< endl; for (i=1;i<=j;i++) { cout<<setiosflags(ios::left)<<setw(5)<
LAB D SORE Latihan C++ Class, Class Array, Struct, Struc Array
ESH/DONI
cout<<setiosflags(ios::left)<<setw(15)<>lagi; if (lagi=='Y'||lagi=='y') goto awal; else goto akhir; akhir: getch(); }
"<<"RP."<
Layout Struct Array
11 Akademi Manajemen Informatika dan Komputer Bina Sarana Informatika
LAB D SORE Latihan C++ Class, Class Array, Struct, Struc Array
ESH/DONI
12 Akademi Manajemen Informatika dan Komputer Bina Sarana Informatika