Sei sulla pagina 1di 5

#include <iostream.

h>

#include <fstream.h>

#include <stdlib.h>

#include <conio.h>

#include <stdio.h>

#include <string.h> // strcpy

#include <iomanip.h> //setiosflags

struct dataPeg

char nip[10];

char nama[20];

char gol[5];

} Peg;

main()

int no=0;

long tgp = 0;

long gp;

ifstream PegFile ("datapeg.dat", ios::in);

if (!PegFile)

cerr<<"File could not be opened"<<endl;

exit(1);
}

cout<<"-----------------------------------------------------------"<<endl;

cout <<setiosflags(ios::left)<<setw(5)<<"No"

<<setw(10)<<"NPM"

<<setw(20)<<"Nama Pegawai"

<<setw(15)<<"Golongan"

<<setw(17)<<"Gaji Pokok"<<endl;

cout<<"-----------------------------------------------------------"<<endl;

PegFile.read((char *)&Peg,sizeof(Peg)); // baca record 1

while (!PegFile.eof())

no++;

if (strcmp (Peg.gol, "III/A")== 0)

gp = 2400000;

else

if (strcmp (Peg.gol, "III/B")== 0)

gp = 2600000;

else

if (strcmp (Peg.gol, "III/C")== 0)

gp = 2800000;

else

if (strcmp (Peg.gol, "III/D")== 0)

gp = 3000000;
cout <<setiosflags(ios::left)<<setw (5)<< no

<<setw(10)<<Peg.nip

<<setw(20)<<Peg.nama

<<setw(15)<<setprecision(3)<<setiosflags(ios::showpoint | ios::right)

<< Peg.gol<< setiosflags(ios::right)<<setw(17)<<gp<<endl;

PegFile.read((char*)&Peg, sizeof(Peg)); // baca record berikutnya

cout<<"-----------------------------------------------------------"<<endl;

tgp = tgp + gp;

cout << "Total Gaji : Rp. " << tgp << endl;

PegFile.close();

getch();

}
#include <fstream.h> // ofstream, ifstream

#include <stdlib.h> // exit

#include <conio.h> // clrscr, getch

#include <stdio.h> // gets

struct dataPeg

char nip[10];

char nama[20];

char gol[5];

} Peg;

void main()

ofstream FilePeg ("datapeg.dat", ios::out); // append=menambah

if (!FilePeg)

cerr<<"File tidak dapat dibuka…"<<endl;

exit(1);

char jwb='Y';

cout<<"Input Data Pegawai"<<endl;

while (jwb =='Y' || jwb =='y')

cout << endl;


cout << "NIP : "; gets(Peg.nip);

cout << "Nama : "; gets(Peg.nama);

cout << "Golongan : "; gets(Peg.gol);

FilePeg.write((char*)&Peg, sizeof(Peg)); // oidperintah merekam data

cout << "Ada Data Lagi [Y/T] = "; cin >> jwb;

FilePeg.close();

Potrebbero piacerti anche