Skip to content

Instantly share code, notes, and snippets.

@krysseltillada
Last active August 29, 2015 14:24
Show Gist options
  • Save krysseltillada/c81fe3930534c6ffc1f0 to your computer and use it in GitHub Desktop.
Save krysseltillada/c81fe3930534c6ffc1f0 to your computer and use it in GitHub Desktop.
static member
#include <iostream>
class Account
{
public:
Account () = default;
Account (std::string n, int id, double m) :
name (n) , id_no (id), money (m) { }
void modify_prime (double);
void update ();
Account &display (Account &);
private:
static double prime_rate;
std::string name;
int id_no = 0;
double money = 0;
};
double Account::prime_rate = 2.3;
void Account::modify_prime (double mp) {
prime_rate = mp;
update ();
}
void Account::update () {
money = money * prime_rate;
}
Account &Account::display (Account &obj) {
std::cout << "name: " << obj.name << std::endl
<< "id no: " << obj.id_no << std::endl
<< "prime rate: " << obj.prime_rate << std::endl
<< "money: " << obj.money << std::endl;
return obj;
}
int main ()
{
Account account1("kryssel", 223334, 22);
account1.modify_prime(3.4);
account1.display(account1);
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment