misstj555 45 Junior Poster in Training

Hello. I have to write a code that models a bank account using "C++". It must complete the following functions:

(1) Make a withdrawal and deposit
(2) change account owner
(3) find balance on account
(4) create new account

However, I can not write all my code in one file but must use "Object Oriented Programming" to do this (it is more efficient). Unlike java (which I am more familiar with), to do this I must create one ".cpp" file, one .h" file and a test file in "C++". I don't think I have the correct idea when it comes to "Object Oriented Programming" in "C++". In fact, I typed the "implementation" of the code in the header file which I think might be incorrect. Also, I have to use "assert" to set the "pre-conditions" in my code. Can anyone tell me if I need better "assert" statements or if I am even using it correctly? Also, how would I get these codes to run together?

Here is the file that defines the program

#include<iostream>
#include<stdio.h>
#include<string.h>
using namespace std;

class theBank
{
private:
    char nameOwner[20];
    int accountNum;
    double balance;

public:
    void initialStatus();
    void deposit();
    void withdraw();
    void printInfo();
};

Here is the file that creates the implementation of the program

#include<iostream>
#include<stdio.h>
#include<string.h>

//functions of bank class

/**************** With regards to the actual bank ******************/
void theBank :: initialStatus()
{
cout<<"New Account Created......"<<endl; //Tells user there is a new account
count<<endl;

cout<<"\n Type the name of Account Owner: "<<endl; //Type name of account owner
//gets name of account owner
cin.get(nameOwner,19,''); //Note: the number "19" is here because the array in "BankClass" is initalzed with the number "20" but in c++, can only hold 19 charater.

cout<<"\n Type in the Account Number: "<<endl; //Tells the user to type in account number
cin>>accountNum; //Allows user to type in account number

cout<<"How much do you want to Deposit?: "<<endl; //Tells user type in how much they need to deposit
cin >>balance; //Allows user to type in how much they want to deposit.
}
/**************** With regards to the actual bank ******************/

/**************** With regards to depositing money******************/
void theBank :: deposit(){
double additionalMoney;

cout <<"Deposit" <<endl;
cout<<"How much do you want to Deposit? "<<endl; //Tells user type in how much they need to deposit
cin>>addition; //Added money to the account
balance = balance + additionalMoney; //Will calculate the new balance
}
/**************** With regards to depositing money******************/

/**************** With regards to withdrawing money******************/
void theBank :: withdraw(){
double deductionOfMoney; 
cout<<"Withdrawl"<<endl;
cout<<"How much do you want to Withdrawl? "<<endl; //Tells user type in how much they need to withdrawl
cin>>withdrawl; //Subtracted money to the account
balance = balance - withdrawl;
}
/**************** With regards to withdrawing money******************/

/**************** With regards to printing the information ******************/
void theBank :: printInfo(){
cout<<"Details regarding the Account";
cout<<"Account Owner         : "<<name<<endl;
cout<<"Number on Account     : "<<acno<<endl;
cout<<"Current Balance       : $"<<balance<<endl;
/**************** With regards to printing the information ******************/

}

Here is the test file

#include<iostream>
#include<stdio.h>
#include<string.h>

int main()
{
    theBank user; //Initialzes "user" with "the bank" class information
    int chooseFunction = 1; //Allow user to chose if they want to make a depoit, withdrawl etc..
    while (chooseFunction != 0){
        //Tells user how to navigate through "Switch case"
        cout<<"Press 1 to create a new account"<<endl;
        cout<<"Press 2 to make a deposit"<<endl;
        cout<<"Press 3 to make a withdrawl"<<endl;
        cout<<"Press 4 to see account information"<<endl;
        cout<<"\n Press 0 exit"<<endl;

        case 0:
            user.printInfo(); //Shows account information before user exits program
            cout<<"Now Exiting Program."<<endl;
            return EXIT_SUCESS;
            break;
        case 1:
            user.initialStatus(); //Shows information on account currently
            break;
        case 2:
            user.deposit(); //Allows user to make a deposit.
            break;
        case 3:
            user.withdrawl(); //Allows user to make a withdrawl
        case 4:
            user.printInfo(); //Allows account informaion to be printed
        default:
            cout<<"Invailed Input"<<endl;
    }
}

I am not trying to get "free answers" online. I simply want to understand "object oriented programming" and make sure my code is setting the right "pre-conditions" using the "assert" line of code. Thank You.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.