Followers

Sunday, 10 February 2013

Name Class

class NamaKelas
{
AccessModifier1:
tipeData1 variable1;
tipeData2 variable2;
fungsi1();
...

AccessModifier2:
tipeData2 variable3;
...
}objeck1,objek2,dst;

AccessModified bisa berupa private, protected, public. Objek instans tidak harus ada (objek1,objek2,dst).

#include<iostream>
#include<string>
using namespace std;

class AkunBank
{
private:
double noAkun;
string nama;
double saldo;
public:
void baca()
{
cout<<"\nMasukkan Nomor Akun: "; cin>>noAkun;cin.ignore();
cout<<"\nMasukkan nama : "; getline(cin,nama);
cout<<"\nMasukkan saldo : "; cin>>saldo;
}
void print()
{
cout<<"\n----------------------------------------\n";
cout<<"\nMomor Akun : "<<noAkun<<endl;
cout<<"\nnama : "<<nama<<endl;
cout<<"\nsaldo : "<<saldo<<endl;
}
void tambahSaldo()
{
double saldo;
cout<<"Masukkan jumlah untuk ditambahkan ke saldo : ";cin>>saldo;
this->saldo+=saldo;
}
void penarikan();
};

void AkunBank::penarikan()
{
double saldo;
cout<<"\nMasukkan jumlah yang akan ditarik : ";cin>>saldo;
this->saldo-=saldo;
}

int main()
{
AkunBank x;
x.baca();
x.tambahSaldo();
x.penarikan();
x.print();
}

TRANSLATE

Radio Music Player Free Online