Thread: need help with a program

Threaded View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Registered User
    Join Date
    Aug 2011
    Posts
    2

    need help with a program

    create c++ programm that defines a class to represent a bank account.
    Data members should include the depositor’s name, the account number(use a string), and the balance.
    Member functions should allow the following:
    1)Creating an object and initializing it.
    2)Displaying the depositor’s name, account number, and balance.
    3)Depositing an amount of money given by an argument.
    4)Withdrawing an amount of money given by an argument.

    having trouble with the member funtion ShowInfo() which has to output DepositorName, AccountNumber, and Balance


    Code:
    #include <cstring>
    #include <iostream>
    
    using namespace std;
    
    class BankAccount
    {
    private:
            std::string DepositorName;
            std::string AccountNumber;
            double Balance;
    public:
            BankAccount();
            BankAccount(std::string depname, std::string acnum, double bal );
            ~BankAccount();  //destructor
            void ShowInfo() const;
            void Deposit(double depamount);
            void Withdraw(double amount);
    };
    
    //non-defualt constructor
    BankAccount::BankAccount(std::string depname, std::string acnum,  double bal)
    {
               DepositorName = depname;
               AccountNumber = acnum;
               Balance = bal;
    }
    
    //destructor
    BankAccount::~BankAccount()
    {
    }
    
    void BankAccount::Withdraw(double amount)
    {
            if (amount < 0)
                  std::cout << "\nPlease enter positive number for the amount to withdraw.";
            else
                    Balance -= amount;
    }
    
    
    void BankAccount::Deposit(double depamount)
    {
              if (depamount < 0)
                   std::cout << "\nPlease enter positive number for  the amount to deposit.";
              else
                      Balance+=depamount;
    }
    
    
    void BankAccount::ShowInfo() const
    {
    	
    	cout << DepositorName;
    	cout << AccountNumber;
        cout << Balance;
    }
    
    
    
    int main()
    {
    	BankAccount somename("some name", "08973541", 60000);
    
    	somename.ShowInfo();
    
    	somename.Deposit(15000);
    
    	somename.ShowInfo();
    
    	somename.Withdraw(30000);
    
    	somename.ShowInfo();
    }
    Last edited by K13; 08-08-2011 at 10:22 PM.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Replies: 1
    Last Post: 03-03-2009, 04:47 PM
  2. Replies: 5
    Last Post: 08-16-2007, 11:43 PM
  3. Replies: 18
    Last Post: 11-13-2006, 01:11 PM
  4. making a program leave a msg for background program when it closes
    By superflygizmo in forum Windows Programming
    Replies: 2
    Last Post: 02-06-2006, 07:44 PM
  5. Math Equation Program (I can't find the problem with my program!)
    By masked_blueberr in forum C Programming
    Replies: 14
    Last Post: 07-06-2005, 11:53 AM