Isengi iseng Teman,, bikin Kodingan Polimorpisme... hhe hhe
Beginilah Source Code nya ::
#include <iostream.h>
#include <conio.h>
#include <string.h>
#include <stdio.h>
class karyawan
{
protected :
string nip;
string nama;
string alamat;
string telepon;
public :
karyawan(string nip,string nama,string alamat,string telepon):
nip(nip),nama(nama),alamat(alamat),telepon(telepon){}
virtual void showAttributes(){}
};
class staff: public karyawan
{
private:
string bagian;
string golongan;
public:
staff(string nip,string nama,string alamat,string telepon,string bagian,string golongan):
karyawan(nip,nama,alamat,telepon),bagian(bagian),golongan(golongan){}
void showAttributes()
{
cout<< " \tSTAFF "<<endl<<"================================"<<endl;
cout << "nip : " << nip <<endl;
cout << "nama : " << nama<<endl;
cout << "alamat : " << alamat<<endl;
cout << "telepon : " << telepon<<endl;
cout << "bagian : " << bagian<<endl;
cout << "golongan : " << golongan<<endl<<endl;
}
};
class direksi: public karyawan
{
private:
string jabatan;
string golongan;
public:
direksi(string nip,string nama,string alamat,string telepon,string jabatan,string golongan):
karyawan(nip,nama,alamat,telepon),jabatan(jabatan),golongan(golongan){}
void showAttributes()
{
cout<< " \tDIREKSI "<<endl<<"================================"<<endl;
cout << "nip : " << nip <<endl;
cout << "nama : " << nama<<endl;
cout << "alamat : " << alamat<<endl;
cout << "telepon : " << telepon<<endl;
cout << "jabtan : " << jabatan<<endl;
cout << "golongan : " << golongan<<endl<<endl;
}
};
int main(){
staff me(" 81040"," Wahid"," Jalan Raya kembangan"," 081324567890"," Administrasi"," III C");
direksi u(" 81041"," Emy"," Jatiluhur"," 081222334455"," Direktur"," IV A");
karyawan* it = &me;
it->showAttributes();
it = &u;
it->showAttributes();
printf("================================");
getch();
}
* telitilah sebelum mencoba,, perhatikan jika anda menemukan error anda harus kritis... error pada Koding tersebut tidak lebih dari 1 jika anda mencoba pada Borland Versi 5.02 . . .
Salam Hangat C++ programmer . . .
Beginilah Source Code nya ::
#include <iostream.h>
#include <conio.h>
#include <string.h>
#include <stdio.h>
class karyawan
{
protected :
string nip;
string nama;
string alamat;
string telepon;
public :
karyawan(string nip,string nama,string alamat,string telepon):
nip(nip),nama(nama),alamat(alamat),telepon(telepon){}
virtual void showAttributes(){}
};
class staff: public karyawan
{
private:
string bagian;
string golongan;
public:
staff(string nip,string nama,string alamat,string telepon,string bagian,string golongan):
karyawan(nip,nama,alamat,telepon),bagian(bagian),golongan(golongan){}
void showAttributes()
{
cout<< " \tSTAFF "<<endl<<"================================"<<endl;
cout << "nip : " << nip <<endl;
cout << "nama : " << nama<<endl;
cout << "alamat : " << alamat<<endl;
cout << "telepon : " << telepon<<endl;
cout << "bagian : " << bagian<<endl;
cout << "golongan : " << golongan<<endl<<endl;
}
};
class direksi: public karyawan
{
private:
string jabatan;
string golongan;
public:
direksi(string nip,string nama,string alamat,string telepon,string jabatan,string golongan):
karyawan(nip,nama,alamat,telepon),jabatan(jabatan),golongan(golongan){}
void showAttributes()
{
cout<< " \tDIREKSI "<<endl<<"================================"<<endl;
cout << "nip : " << nip <<endl;
cout << "nama : " << nama<<endl;
cout << "alamat : " << alamat<<endl;
cout << "telepon : " << telepon<<endl;
cout << "jabtan : " << jabatan<<endl;
cout << "golongan : " << golongan<<endl<<endl;
}
};
int main(){
staff me(" 81040"," Wahid"," Jalan Raya kembangan"," 081324567890"," Administrasi"," III C");
direksi u(" 81041"," Emy"," Jatiluhur"," 081222334455"," Direktur"," IV A");
karyawan* it = &me;
it->showAttributes();
it = &u;
it->showAttributes();
printf("================================");
getch();
}
* telitilah sebelum mencoba,, perhatikan jika anda menemukan error anda harus kritis... error pada Koding tersebut tidak lebih dari 1 jika anda mencoba pada Borland Versi 5.02 . . .
Salam Hangat C++ programmer . . .
Tidak ada komentar:
Posting Komentar