Minggu, 03 Juli 2011

Jawaban Quiz Pemograman Terstruktur No.3

#include<iostream.h>
#include<conio.h>
#include<stdio.h>
#include<string.h>

struct pegawai
{
  char nik[9];
  char nama[10];
  char kode[15];
  char stat;
  long tnj_klrga;
}peg[20];

void main()
{
  char lg='y';
  int hasil,i,n=0;
  char stat;
  long gaji=0;
  long tunjangan=0;
  long tnj_klrga=0;
  long total_gaji;
  while(lg=='y'||lg=='y')
  {
  clrscr();
  cout<<"Input Data Karyawan\n";
  cout<<".....................\n";
  n++;
  cout<<"NIK ";
      gets(peg[n].nik);
  cout<<"Nama   :";
      gets(peg[n].nama);
  cout<<"Bagian[Persediaan, Administrasi, Keuangan, Penjualan] :";
      gets(peg[n].kode);
  cout<<" Status Karyawan (M=Menikah & B=Belum) : " ;
        stat=getche();
        if (stat=='M'||stat=='m')
        cout<<"\n Tunjangan Keluarga";
        tnj_klrga=0.15*gaji;
  cout<<"\n __________________________\n";
  cout<<"input Lagi[Y/T]:";
     lg=getch();
  }

  clrscr();
  gotoxy(5,3);cout<<"LAPORAN GAJI KARYAWAN\n";
  gotoxy(5,4);cout<<".....................";
  gotoxy(5,5);cout<<"No    NIK  Nama    Bagian  Gaji   Tunjangan  Tunj Klrga  Total Gaji";
  gotoxy(5,6);cout<<"_________________________________________________________________";

  for(i=1;i<=n;i++)
  {
  gotoxy(6,6+i);cout<<i;
  gotoxy(9,6+i);cout<<peg[i].nik;
  gotoxy(15,6+i);cout<<peg[i].nama;
  gotoxy(23,6+i);cout<<peg[i].kode;
  gotoxy(43,6+i);cout<<peg[i].stat;

  hasil=strcmp(peg[i].kode,"Persediaan");
  if (hasil==0)
  gaji=2500000;
  tunjangan=0.35*gaji;

  hasil=strcmp(peg[i].kode,"Administrasi");
  if (hasil==0)
  gaji=2000000;
  tunjangan=0.10*gaji;

  hasil=strcmp(peg[i].kode,"Keuangan");
  if (hasil==0)
  gaji=1500000;
  tunjangan=0.5*gaji;

  hasil=strcmp(peg[i].kode,"Penjualan");
  if (hasil==0)
  gaji=1000000;
  tunjangan=0.025*gaji;

  if (stat=='M'||stat=='m')
        cout<<"\n Tunjangan Keluarga";
        tnj_klrga=0.15*gaji;

  gotoxy(33,6+i);cout<<gaji;
  gotoxy(46,6+i);cout<<tunjangan;
  gotoxy(57,6+i);cout<<tnj_klrga;

  total_gaji = gaji+tunjangan+tnj_klrga;
  gotoxy(65,6+i); cout<<total_gaji;
  }

  gotoxy(5,6+i);cout<<"................................................................";
  getch();
  }

Hasilnya akan seperti ini :
















 
Nama : E S T E R
NPM : 1002247
Kelas : MI.P-1003

Tidak ada komentar:

Posting Komentar