Contoh Program C++ dg Struct Array

#include <iostream.h>
#include <conio.h>
#include <iomanip.h>
//NAMA : Mario Making
//NIM : 12100903
//KELAS PRAKTEK: TI 2C Malam
//TUGAS RESPONSI PEMROGRAMAN SISTEM

struct pegawai{
//prototype fungsi
void input();
void output();
void keluar();
void cetakc(int a,char *teks);

//variable
int nik[25],jabatan[10],gaji;
char nama[10][25],jkl[10],tny;
};

pegawai oke[25];
int i,j;

//fungsi cetak center
void pegawai::cetakc(int a,char *teks)
{gotoxy(40-((strlen(teks)/2)),a);cout<>menu;

switch (menu)
{
case 1:oke[i].input();break;
case 2:oke[i].output();break;
case 3:oke[i].keluar();break;
}

}while(menu!=3);
}

//deklarasi fungsi
void pegawai::input()
{
//perulangan
do{
clrscr();
i++; j++;
cetakc(3,” .:: INPUT DATA PEGAWAI ::. “);
cetakc(4,”+—————————+”);
cetakc(5,”| NIK : |”);
cetakc(6,”| NAMA : |”);
cetakc(7,”| JKL [L/P] : |”);
cetakc(8,”| JABATAN [1,2,3] : |”);
cetakc(9,”+—————————+”);
cetakc(10,”| INPUT DATA LAGI [Y/T]? [ ]|”);
cetakc(11,”+—————————+”);
gotoxy(46,5);cin>>oke[i].nik[i];
gotoxy(46,6);cin>>oke[i].nama[i];
gotoxy(46,7);cin>>oke[i].jkl[i];
gotoxy(46,8);cin>>oke[i].jabatan[i];
gotoxy(52,10);cin>>oke[i].tny;
}while(oke[i].tny==’Y’);
}

//deklarasi fungsi
void pegawai::output(){
long totgj=0,ratgj,max,min;
clrscr();

for (int i=1;i<=j;i++) //perulangan
{
gotoxy(2,2);
cout<<” .:: TAMPIL DATA ::. “;
gotoxy(2,3);
cout<<“+—+——-+—————+————–+———+——–+”;
gotoxy(2,4);
cout<<“|NO | NIK | NAMA PEGAWAI | JKL | JABATAN | GAJI |”;
gotoxy(2,5);
cout<<“+—+——-+—————+————–+———+——–+”;

gotoxy(2,5+i);cout<<“|”;
gotoxy(4,5+i);cout<<i;
gotoxy(6,5+i);cout<<“|”;
gotoxy(8,5+i);cout<<oke[i].nik[i];
gotoxy(14,5+i);cout<<“|”;
gotoxy(19,5+i);cout<<oke[i].nama[i];
gotoxy(30,5+i);cout<<“|”;
gotoxy(32,5+i);cout<<oke[i].jkl[i];
gotoxy(45,5+i);cout<<“|”;
gotoxy(46,5+i);cout<<oke[i].jabatan[i];
gotoxy(55,5+i);cout<<“|”;
gotoxy(64,5+i);cout<<“|”;
gotoxy(46,5+i);
if (oke[i].jabatan[i]==1)
cout<<“Analis”<<endl;
else if(oke[i].jabatan[i]==2)
cout<<“Programer”<<endl;
else if(oke[i].jabatan[i]==3)
cout<<“Desainer”<<endl;

gotoxy(32,5+i);
if (oke[i].jkl[i]<=’L’)
cout<<“Laki-laki”<<endl;
else if(oke[i].jkl[i]<=’P’)
cout<<“Perempuan”<<endl;

gotoxy(57,5+i);
if (oke[i].jabatan[i]==1) {
cout<<“2500000″<<endl;
oke[i].gaji=2500000; }
if (oke[i].jabatan[i]==2) {
cout<<“1500000″<<endl;
oke[i].gaji=1500000; }
if (oke[i].jabatan[i]==3) {
cout<<“1300000″<<endl;
oke[i].gaji=1300000; }
}
min=oke[i].gaji;
for (int i=1;ioke[i].gaji)min=oke[i].gaji;
gotoxy(52,7+i);cout<<“Rp. “<<setw(5) <<min;
max=oke[i].gaji;
for (int i=1;i<=j;i++)
if (max<oke[i].gaji)max=oke[i].gaji;
gotoxy(52,8+i);cout<<“Rp. “<<setw(5) <<max;
for (int i=1;i<=j;i++)
totgj=totgj+oke[i].gaji;
ratgj=totgj/j;

gotoxy(52,9+i);cout<<“Rp. “<<setw(5) <<ratgj;
gotoxy(52,10+i);cout<<“Rp. “<<setw(5)<<totgj;
gotoxy(64,7+i);cout<<“|”;
gotoxy(64,8+i);cout<<“|”;
gotoxy(64,9+i);cout<<“|”;
gotoxy(64,10+i);cout<<“|”;
gotoxy(2,6+i);cout<<“+=============================================================+”;
gotoxy(2,7+i);cout< MINIMUM GAJI : “;
gotoxy(2,8+i);cout< MAKSIMUM GAJI : “;
gotoxy(2,9+i);cout< RATA – RATA GAJI : “;
gotoxy(2,10+i);cout< TOTAL GAJI : “;
gotoxy(2,11+i);cout<<“+=============================================================+”;
getch();
}

//deklarasi fungsi
void pegawai::keluar(){
clrscr();
cetakc(5,”TERIMAKASIH TELAH MENGGUNAKAN PROGRAM INI”);
cetakc(7,”Marioyogya_91@yahoo.com”);
cetakc(9,”~ 2011 ~”);
getch();
clrscr();
cout<<“ENTER Lagi :)”<<endl;
getch();
}

4 thoughts on “Contoh Program C++ dg Struct Array

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s