C++ Class Member Function Create

Description

C++ Class Member Function Create

class MyAccount { 
  public: //from ww w. jav a2s  .  com
    // define a member function deposit() 
    double deposit(double amount) 
    { 
        balance += amount; 
        return balance; 
    } 

    unsigned int accountNumber; 
    double  balance; 
}; 
#include <cstdio> 
#include <cstdlib> 
#include <iostream> 

using namespace std; 

int main(int nNumberofArgs, char* pszArgs[]) { 
    MyAccount s; 
    s.accountNumber = 123456; 
    s.balance = 0.0; 

    cout << "Depositing 10 to account " << s.accountNumber << endl; 
    s.deposit(10); 
    cout << "Balance is " << s.balance << endl; 

    return 0; 
}



PreviousNext

Related