#include
class data
{
private :
int nilai;
public :
void setNilai(int n)
{
nilai=n;
}
int getNilai(){ return nilai;}
};
void main()
{
data obj[5];
int i,temp;
for(i=0;i<5;i++) { cout << "Nilai : "; cin >> temp;
obj[i].setNilai(temp);
}
for(i=0;i<5;i++)
{
cout << "Nilai ke- " << i << ":" << obj[i].getNilai() << endl;
}
/*obj[0].setNilai(100);
cout << "Nilai : " << obj[0].getNilai();*/
cin.get();
cin.get();
}
sumber : http://www.kaskus.us/showthread.php?t=1215259
thanks bray
BalasHapus