Berikut Adalah Source Code untuk Konstruktor pada PBO C++
#include <iostream.h>
#include <cstring.h>
#include <conio.h>
class Man{
private:
string name;
short age;
public:
Man(string name,short age):name(name), age(age){
}
string getName(){
return this->name;
}
short getAge(){
return this->age;
}
};
int main(){
Man me("Emergency",91);
cout << me.getName() << " : " << me.getAge() << endl ;
getch();
}
#include <iostream.h>
#include <cstring.h>
#include <conio.h>
class Man{
private:
string name;
short age;
public:
Man(string name,short age):name(name), age(age){
}
string getName(){
return this->name;
}
short getAge(){
return this->age;
}
};
int main(){
Man me("Emergency",91);
cout << me.getName() << " : " << me.getAge() << endl ;
getch();
}
ka mana contoh struct di dalam class
BalasHapus