contoh program class bag 3 (bahasa C)

#include
#include
#include
#include
class Kuliah
{ public:
Kuliah(); // konstruktor 1
Kuliah(char *kd, char *nm); // konstruktor 2
~Kuliah(); // destruktor
void Input(); void Tampil();
private:
char Kode[6]; char Nama_Kuliah[30];
};
Kuliah :: Kuliah () {
cout << "Konstruktor 1 dijalankan !! \n";
strcpy(Kode, " "); strcpy(Nama_Kuliah, " ");
getch();

}
Kuliah :: Kuliah ( char *kd, char *nm ) {
cout << "Konstruktor 2 dijalankan !! \n";
strcpy(Kode, kd ); strcpy(Nama_Kuliah, nm );
getch();}
Kuliah :: ~Kuliah () {
cout << "Destruktor dijalankan !! \n"; }

void Kuliah :: Input () {
cout << "Masukkan Kode Kuliah : "; cin >> Kode;
cout << "Masukkan Nama Kuliah : "; gets(Nama_Kuliah);
}
void Kuliah :: Tampil() {
cout << "Kode Kuliah : " << Kode << endl;
cout << "Nama Kuliah : " << Nama_Kuliah<< endl;
}
void main()
{ // Menciptakan dan Inisialisasi 2 buah objek
Kuliah K1, K2("IF454", "Pemrograman Berorientasi Objek");
clrscr();
// Me nampilkan data
K1. Tampil(); K2. Tampil();
// Memasukkan data baru
K1.Input(); K2.Input();
// Menampilkan data baru
K1. Tampil(); K2. Tampil();
getch();
}
Share this article :

0 comments:

Speak up your mind

Tell us what you're thinking... !

 
Support : Creating Website | Johny Template | Mas Template
Copyright © 2011. My Kampuzzzz - All Rights Reserved
Template Created by Creating Website Inspired by Sportapolis Shape5.com
Proudly powered by Blogger