Berikut adalah contoh kode program C++ untuk aplikasi penghitungan gaji karyawan
C++
#include <iostream>
using namespace std;
// Deklarasi struktur data karyawan
struct Karyawan {
string nama;
int jamKerja;
int gajiPerJam;
};
// Fungsi untuk menghitung gaji karyawan
int hitungGaji(Karyawan karyawan) {
int totalGaji = karyawan.jamKerja * karyawan.gajiPerJam;
return totalGaji;
}
int main() {
// Input data karyawan
Karyawan karyawan;
cout << "Masukkan nama karyawan: ";
cin >> karyawan.nama;
cout << "Masukkan jumlah jam kerja: ";
cin >> karyawan.jamKerja;
cout << "Masukkan gaji per jam: ";
cin >> karyawan.gajiPerJam;
// Hitung gaji karyawan
int gaji = hitungGaji(karyawan);
// Output gaji karyawan
cout << "Gaji " << karyawan.nama << " adalah: " << gaji << endl;
return 0;
}
C++Contoh lain
C++
#include <iostream>
#include <conio.h>
#include <windows.h>
using namespace std;
void perusahaan () {
SetConsoleTitle("PROGRAM GAJI KARYAWAN INDONESIA");
cout<<"\n===================================================================\n";
cout<<"\n PROGRAM GAJI INDONESIA \n";
cout<<"\n===================================================================\n";
cout<<" SLIP GAJI KARYAWAN ";
cout<<"\n===================================================================\n\n\n";
}
void menu() {
SetConsoleTitle("PROGRAM GAJI KARYAWAN INDONESIA");
cout<<"\n DIVISI INDONESIA \n";
cout<<"\n===================================================================\n\n\n";
cout<<"\n 1. Divisi Personalia \n";
cout<<"\n 2. Divisi Accounting \n";
cout<<"\n 3. Divisi Marketing \n";
cout<<"\n 4. Divisi Produksi \n";
cout<<"\n 5. SELESAI \n";
cout<<endl;
cout<<"Pilih Divisi : ";
}
main()
{
SetConsoleTitle("PROGRAM GAJI KARYAWAN EPOSTLAB INDONESIA");
char pilih(2),ulang,staff[20];
int pilihan;
int gol,SK,JK;
long int gaji,tot_tunjangan,gaji_bersih;
double status,keluarga,ht,asuransi,lembur,tot_potongan;
char NAMA[30],NIK[30];
cout<<" Staff Admin :";
cin>>staff;
cout<<"\n===================================================================\n";
cout<<"\n PROGRAM GAJI INDONESIA \n";
cout<<"\n===================================================================\n";
cout<<" SLIP GAJI KARYAWAN ";
cout<<"\n===================================================================\n\n\n";
cout<<"\n MASUK PROGRAM [Y]/[N] : ";
cin>>pilih;
if(pilih=='y')
{
menu();
}
else
{
goto exit;
}
do {
system ("cls");
perusahaan ();
menu();
cin >> pilihan;
cout<<"\n________________________________________________________________________\n";
if ((pilihan == 0) || (pilihan >= 6)) {
cout <<" Input lagi : Input 1-5" << endl;
} else {
switch (pilihan) {
case 1:
system("cls");
cout<<"\n===================================================================\n";
cout<<"\n PROGRAM GAJI INDONESIA \n";
cout<<"\n===================================================================\n";
cout<<" D I V I S I P E R S O N A L I A ";
cout<<"\n===================================================================\n\n\n";
cout<<"\t\t\t\t\t\t Staff Admin : "<<staff;
cout<<"\n________________________________________________________________________\n";
cout<<"\n Nama Karyawan : ";
cin>>NAMA;
cout<<"\n NIK : ";
cin>>NIK;
cout<<endl;
cout<<"\n-----------------------------------------------------------------------\n";
cout<<"\n Jabatan Dalam Perusahaan "<<endl;
cout<<"\n-----------------------------------------------------------------------\n";
cout<<"\n 1.Mandor "<<endl;
cout<<"\n 2.Staff "<<endl;
cout<<"\n 3.Kepala Cabang "<<endl;
cout<<"\n 4.Manager "<<endl;
cout<<"\n Pilih Jabatan 1--4 :";
cin>>gol;
if (gol == 1){
gaji = 2500000;
}else if (gol == 2){
gaji = 3000000;
}else if (gol == 3){
gaji = 3500000;
}else if (gol == 4){
gaji = 4000000;
}else{
gaji = 0;
}
cout<<"\n-----------------------------------------------------------------------\n";
cout<<"\n Status Karyawan "<<endl;
cout<<"\n-----------------------------------------------------------------------\n";
cout<<"\n 1.Lajang "<<endl;
cout<<"\n 2.Menikah Belum Punya Anak "<<endl;
cout<<"\n 3.Menikah Anak Satu "<<endl;
cout<<"\n 4.Menikah Anak Dua "<<endl;
cout<<"\n Pilih Status 1--4 : ";
cin>>SK;
if (SK == 1){
status = 0;
}else if (SK == 2){
status = 0.05;
}else if (SK == 3){
status = 0.1;
}else if (SK == 4){
status = 0.15;
}else{
status = 0;
}
cout<<"\n Jumlah Jam Kerja : ";
cin>>JK;
system("cls");
cout<<"\n===================================================================\n";
cout<<"\n PROGRAM GAJI INDONESIA \n";
cout<<"\n===================================================================\n";
cout<<" D I V I S I P E R S O N A L I A ";
cout<<"\n===================================================================\n\n\n";
cout<<"\t\t\t\t\t\t Staff Admin : "<<staff;
cout<<"\n________________________________________________________________________\n";
cout<<"\nNama Karyawan :"<<NAMA;
cout<<"\nID Karyawan :"<<NIK;
cout<<"\n===================================================================\n\n\n";
cout<<"\n_________________________________________\n";
cout<<" (o) Gaji Pokok : Rp. "<<gaji<<",00";
cout<<"\n_________________________________________\n";
keluarga=gaji*status;
ht=0.05*gaji;
asuransi=0.03*gaji;
if (JK<=170){
lembur=0;
}else{
lembur=(gaji/170)*(JK-170);
}
tot_tunjangan=keluarga+ht+asuransi+lembur;
cout<<"\n\n (o) Tunjangan-Tunjangan\n\n";
cout<<"\n - Keluarga : Rp. "<<keluarga<<",00";
cout<<"\n - Hari Tua : Rp. "<<ht<<",00";
cout<<"\n - Asuransi : Rp. "<<asuransi<<",00";
cout<<"\n - Lembur : Rp. "<<lembur<<",00";
cout<<"\n_________________________________________\n";
cout<<" (o) Total Tunjangan : Rp. "<<tot_tunjangan<<",00";
cout<<"\n_________________________________________\n";
cout<<"\n\n\n (o) Potongan-Potongan\n\n";
ht=0.05*gaji;
asuransi=0.03*gaji;
tot_potongan=ht+asuransi;
gaji_bersih=gaji+tot_tunjangan-tot_potongan;
cout<<"\n - Hari Tua : Rp. "<<ht<<",00";
cout<<"\n - Asuransi : Rp. "<<asuransi<<",00";;
cout<<"\n_________________________________________\n";
cout<<" (o) Total Potongan : Rp. "<<tot_potongan<<",00";
cout<<"\n_________________________________________\n";
cout<<" (o) Gaji Bersih : Rp. "<<gaji_bersih<<",00";
cout<<"\n_________________________________________\n";
cout<<endl;
cout<<endl;
break;
case 2:
system ("cls");
cout<<"\n===================================================================\n";
cout<<"\n PROGRAM GAJI INDONESIA \n";
cout<<"\n===================================================================\n";
cout<<" D I V I S I A C C O U N T I N G ";
cout<<"\n===================================================================\n\n\n";
cout<<"\t\t\t\t\t\t Staff Admin : "<<staff;
cout<<"\n________________________________________________________________________\n";
cout<<"\n Nama Karyawan : ";
cin>>NAMA;
cout<<"\n NIK : ";
cin>>NIK;
cout<<endl;
cout<<"\n-----------------------------------------------------------------------\n";
cout<<"\n Jabatan Dalam Perusahaan "<<endl;
cout<<"\n-----------------------------------------------------------------------\n";
cout<<"\n 1.Mandor "<<endl;
cout<<"\n 2.Staff "<<endl;
cout<<"\n 3.Kepala Cabang "<<endl;
cout<<"\n 4.Manager "<<endl;
cout<<"\n Pilih Jabatan 1--4 :";
cin>>gol;
if (gol == 1){
gaji = 2500000;
}else if (gol == 2){
gaji = 3000000;
}else if (gol == 3){
gaji = 3500000;
}else if (gol == 4){
gaji = 4000000;
}else{
gaji = 0;
}
cout<<"\n-----------------------------------------------------------------------\n";
cout<<"\n Status Karyawan "<<endl;
cout<<"\n-----------------------------------------------------------------------\n";
cout<<"\n 1.Lajang "<<endl;
cout<<"\n 2.Menikah Belum Punya Anak "<<endl;
cout<<"\n 3.Menikah Anak Satu "<<endl;
cout<<"\n 4.Menikah Anak Dua "<<endl;
cout<<"\n Pilih Status 1--4 : ";
cin>>SK;
if (SK == 1){
status = 0;
}else if (SK == 2){
status = 0.05;
}else if (SK == 3){
status = 0.1;
}else if (SK == 4){
status = 0.15;
}else{
status = 0;
}
cout<<"\n Jumlah Jam Kerja : ";
cin>>JK;
system("cls");
cout<<"\n===================================================================\n";
cout<<"\n PROGRAM GAJI INDONESIA \n";
cout<<"\n===================================================================\n";
cout<<" D I V I S I A C C O U N T I N G ";
cout<<"\n===================================================================\n\n\n";
cout<<"\t\t\t\t\t\t Staff Admin : "<<staff;
cout<<"\n________________________________________________________________________\n";
cout<<"\nNama Karyawan :"<<NAMA;
cout<<"\nID Karyawan :"<<NIK;
cout<<"\n===================================================================\n\n\n";
cout<<"\n_________________________________________\n";
cout<<" (o) Gaji Pokok : Rp. "<<gaji<<",00";
cout<<"\n_________________________________________\n";
keluarga=gaji*status;
ht=0.05*gaji;
asuransi=0.03*gaji;
if (JK<=170){
lembur=0;
}else{
lembur=(gaji/170)*(JK-170);
}
tot_tunjangan=keluarga+ht+asuransi+lembur;
cout<<"\n\n (o) Tunjangan-Tunjangan\n\n";
cout<<"\n - Keluarga : Rp. "<<keluarga<<",00";
cout<<"\n - Hari Tua : Rp. "<<ht<<",00";
cout<<"\n - Asuransi : Rp. "<<asuransi<<",00";
cout<<"\n - Lembur : Rp. "<<lembur<<",00";
cout<<"\n_________________________________________\n";
cout<<" (o) Total Tunjangan : Rp. "<<tot_tunjangan<<",00";
cout<<"\n_________________________________________\n";
cout<<"\n\n\n (o) Potongan-Potongan\n\n";
ht=0.05*gaji;
asuransi=0.03*gaji;
tot_potongan=ht+asuransi;
gaji_bersih=gaji+tot_tunjangan-tot_potongan;
cout<<"\n - Hari Tua : Rp. "<<ht<<",00";
cout<<"\n - Asuransi : Rp. "<<asuransi<<",00";;
cout<<"\n_________________________________________\n";
cout<<" (o) Total Potongan : Rp. "<<tot_potongan<<",00";
cout<<"\n_________________________________________\n";
cout<<" (o) Gaji Bersih : Rp. "<<gaji_bersih<<",00";
cout<<"\n_________________________________________\n";
cout<<endl;
cout<<endl;
break;
case 3:
system ("cls");
cout<<"\n===================================================================\n";
cout<<"\n PROGRAM GAJI INDONESIA \n";
cout<<"\n===================================================================\n";
cout<<" D I V I S I M A R K E T I N G ";
cout<<"\n===================================================================\n\n\n";
cout<<"\t\t\t\t\t\t Staff Admin : "<<staff;
cout<<"\n________________________________________________________________________\n";
cout<<"\n Nama Karyawan : ";
cin>>NAMA;
cout<<"\n NIK : ";
cin>>NIK;
cout<<endl;
cout<<"\n-----------------------------------------------------------------------\n";
cout<<"\n Jabatan Dalam Perusahaan "<<endl;
cout<<"\n-----------------------------------------------------------------------\n";
cout<<"\n 1.Mandor "<<endl;
cout<<"\n 2.Staff "<<endl;
cout<<"\n 3.Kepala Cabang "<<endl;
cout<<"\n 4.Manager "<<endl;
cout<<"\n Pilih Jabatan 1--4 :";
cin>>gol;
if (gol == 1){
gaji = 2500000;
}else if (gol == 2){
gaji = 3000000;
}else if (gol == 3){
gaji = 3500000;
}else if (gol == 4){
gaji = 4000000;
}else{
gaji = 0;
}
cout<<"\n-----------------------------------------------------------------------\n";
cout<<"\n Status Karyawan "<<endl;
cout<<"\n-----------------------------------------------------------------------\n";
cout<<"\n 1.Lajang "<<endl;
cout<<"\n 2.Menikah Belum Punya Anak "<<endl;
cout<<"\n 3.Menikah Anak Satu "<<endl;
cout<<"\n 4.Menikah Anak Dua "<<endl;
cout<<"\n Pilih Status 1--4 : ";
cin>>SK;
if (SK == 1){
status = 0;
}else if (SK == 2){
status = 0.05;
}else if (SK == 3){
status = 0.1;
}else if (SK == 4){
status = 0.15;
}else{
status = 0;
}
cout<<"\n Jumlah Jam Kerja : ";
cin>>JK;
system("cls");
cout<<"\n===================================================================\n";
cout<<"\n PROGRAM GAJI INDONESIA \n";
cout<<"\n===================================================================\n";
cout<<" D I V I S I M A R K E T I N G ";
cout<<"\n===================================================================\n\n\n";
cout<<"\t\t\t\t\t\t Staff Admin : "<<staff;
cout<<"\n________________________________________________________________________\n";
cout<<"\nNama Karyawan :"<<NAMA;
cout<<"\nID Karyawan :"<<NIK;
cout<<"\n===================================================================\n\n\n";
cout<<"\n_________________________________________\n";
cout<<" (o) Gaji Pokok : Rp. "<<gaji<<",00";
cout<<"\n_________________________________________\n";
keluarga=gaji*status;
ht=0.05*gaji;
asuransi=0.03*gaji;
if (JK<=170){
lembur=0;
}else{
lembur=(gaji/170)*(JK-170);
}
tot_tunjangan=keluarga+ht+asuransi+lembur;
cout<<"\n\n (o) Tunjangan-Tunjangan\n\n";
cout<<"\n - Keluarga : Rp. "<<keluarga<<",00";
cout<<"\n - Hari Tua : Rp. "<<ht<<",00";
cout<<"\n - Asuransi : Rp. "<<asuransi<<",00";
cout<<"\n - Lembur : Rp. "<<lembur<<",00";
cout<<"\n_________________________________________\n";
cout<<" (o) Total Tunjangan : Rp. "<<tot_tunjangan<<",00";
cout<<"\n_________________________________________\n";
cout<<"\n\n\n (o) Potongan-Potongan\n\n";
ht=0.05*gaji;
asuransi=0.03*gaji;
tot_potongan=ht+asuransi;
gaji_bersih=gaji+tot_tunjangan-tot_potongan;
cout<<"\n - Hari Tua : Rp. "<<ht<<",00";
cout<<"\n - Asuransi : Rp. "<<asuransi<<",00";;
cout<<"\n_________________________________________\n";
cout<<" (o) Total Potongan : Rp. "<<tot_potongan<<",00";
cout<<"\n_________________________________________\n";
cout<<" (o) Gaji Bersih : Rp. "<<gaji_bersih<<",00";
cout<<"\n_________________________________________\n";
cout<<endl;
cout<<endl;
break;
case 4:
system ("cls");
cout<<"\n===================================================================\n";
cout<<"\n PROGRAM GAJI INDONESIA \n";
cout<<"\n===================================================================\n";
cout<<" D I V I S I P R O D U K S I ";
cout<<"\n===================================================================\n\n\n";
cout<<"\t\t\t\t\t\t Staff Admin : "<<staff;
cout<<"\n________________________________________________________________________\n";
cout<<"\n Nama Karyawan : ";
cin>>NAMA;
cout<<"\n NIK : ";
cin>>NIK;
cout<<endl;
cout<<"\n-----------------------------------------------------------------------\n";
cout<<"\n Jabatan Dalam Perusahaan "<<endl;
cout<<"\n-----------------------------------------------------------------------\n";
cout<<"\n 1.Mandor "<<endl;
cout<<"\n 2.Staff "<<endl;
cout<<"\n 3.Kepala Cabang "<<endl;
cout<<"\n 4.Manager "<<endl;
cout<<"\n Pilih Jabatan 1--4 :";
cin>>gol;
if (gol == 1){
gaji = 2500000;
}else if (gol == 2){
gaji = 3000000;
}else if (gol == 3){
gaji = 3500000;
}else if (gol == 4){
gaji = 4000000;
}else{
gaji = 0;
}
cout<<"\n-----------------------------------------------------------------------\n";
cout<<"\n Status Karyawan "<<endl;
cout<<"\n-----------------------------------------------------------------------\n";
cout<<"\n 1.Lajang "<<endl;
cout<<"\n 2.Menikah Belum Punya Anak "<<endl;
cout<<"\n 3.Menikah Anak Satu "<<endl;
cout<<"\n 4.Menikah Anak Dua "<<endl;
cout<<"\n Pilih Status 1--4 : ";
cin>>SK;
if (SK == 1){
status = 0;
}else if (SK == 2){
status = 0.05;
}else if (SK == 3){
status = 0.1;
}else if (SK == 4){
status = 0.15;
}else{
status = 0;
}
cout<<"\n Jumlah Jam Kerja : ";
cin>>JK;
system("cls");
cout<<"\n===================================================================\n";
cout<<"\n PROGRAM GAJI INDONESIA \n";
cout<<"\n===================================================================\n";
cout<<" D I V I S I P R O D U K S I ";
cout<<"\n===================================================================\n\n\n";
cout<<"\t\t\t\t\t\t Staff Admin : "<<staff;
cout<<"\n________________________________________________________________________\n";
cout<<"\nNama Karyawan :"<<NAMA;
cout<<"\nID Karyawan :"<<NIK;
cout<<"\n===================================================================\n\n\n";
cout<<"\n_________________________________________\n";
cout<<" (o) Gaji Pokok : Rp. "<<gaji<<",00";
cout<<"\n_________________________________________\n";
keluarga=gaji*status;
ht=0.05*gaji;
asuransi=0.03*gaji;
if (JK<=170){
lembur=0;
}else{
lembur=(gaji/170)*(JK-170);
}
tot_tunjangan=keluarga+ht+asuransi+lembur;
cout<<"\n\n (o) Tunjangan-Tunjangan\n\n";
cout<<"\n - Keluarga : Rp. "<<keluarga<<",00";
cout<<"\n - Hari Tua : Rp. "<<ht<<",00";
cout<<"\n - Asuransi : Rp. "<<asuransi<<",00";
cout<<"\n - Lembur : Rp. "<<lembur<<",00";
cout<<"\n_________________________________________\n";
cout<<" (o) Total Tunjangan : Rp. "<<tot_tunjangan<<",00";
cout<<"\n_________________________________________\n";
cout<<"\n\n\n (o) Potongan-Potongan\n\n";
ht=0.05*gaji;
asuransi=0.03*gaji;
tot_potongan=ht+asuransi;
gaji_bersih=gaji+tot_tunjangan-tot_potongan;
cout<<"\n - Hari Tua : Rp. "<<ht<<",00";
cout<<"\n - Asuransi : Rp. "<<asuransi<<",00";;
cout<<"\n_________________________________________\n";
cout<<" (o) Total Potongan : Rp. "<<tot_potongan<<",00";
cout<<"\n_________________________________________\n";
cout<<" (o) Gaji Bersih : Rp. "<<gaji_bersih<<",00";
cout<<"\n_________________________________________\n";
cout<<endl;
cout<<endl;
case 5:
exit;
break;
default:
break;
}
}
if (pilihan == 5) {
break;
} else {
cout <<"\n\n KEMBALI KE MENU ? Y/T : " ;
cin >> ulang;
}
}while (ulang == 'Y' || ulang == 'y');
exit:
{
system("cls");
cout<<endl<<endl;
{
return 0;
}
}
getch();
}
C++Silakan gunakan kode di atas untuk membuat aplikasi penghitungan gaji karyawan lengkap dengan penjelasan fungsi yang digunakan.
Leave a Reply