-1

I want to create a bank program in C++ that will store customer information (maybe in a text file or some sort) like:

name
account type
account number
account balance
deposit and withdraw functions
edit account
delete account
show all account.

Class bankAccounts
{
   private:
string customerName
char accType
int accountNo
double accBalance
   public:
bankAccounts()
~bankAccounts()
displayAccount()
depositAccount()
withdrawAccount()
deleteAccount()
showAccounts()

how would i use the constructor? maybe to set the balance and accountnum to 0. how could i do this and also how would i implement other functions?

cadaniluk
  • 15,027
  • 2
  • 39
  • 67
jeremyo
  • 71
  • 10
  • Steps to success: 1. [Learn how to ask](http://stackoverflow.com/tour) a [good question](http://stackoverflow.com/help/how-to-ask). 2. Learn how classes work in C++, including constructors/destructors, inheritance, polymorphism, and all related stuff. 3. Think. **Write code**. If it doesn't work, rewrite or ask a **specific question** here on Stack Overflow. **Note** that I'm not being sarcastic here but rather helpful indeed. – cadaniluk Dec 12 '15 at 20:44

1 Answers1

0

Here's how. Create a Parameterized Constructor and pass the values you want to be assigned to the object as arguments.

#include <iostream>
#include <string>

class bankAccounts
{
private:
    std::string customerName;
    char accType;
    int accountNo;
    double accBalance;

public:
    bankAccounts();

    bankAccounts(std::string cn ,char act, int acno, double accB) //Parameterized constructor
    {
        customerName =cn;
        accType=act;
        accountNo=acno;
        accBalance=accB;
    }

    //Implement your functions inside/ outside the class

    // displayAccount();
    // depositAccount();
    // withdrawAccount();
    // deleteAccount();
    // showAccounts();

};


int main()
{
    std::string customerName;
    char accType;
    int accountNo;
    double accBalance;
    std::cin>>customerName>>accType>>accountNo>>accBalance;//get your data
    bankAccounts B(customerName, accType, accountNo, accBalance);
    //object B has all attributes you wanted

    //Enjoy :)

    return 0;
} 
gabbar0x
  • 4,046
  • 5
  • 31
  • 51
  • Won't compile, sorry. – cadaniluk Dec 12 '15 at 20:58
  • Wasn't meant to. Just gave an overview. Hold on – gabbar0x Dec 12 '15 at 21:01
  • I do and I will but only if your program compiles. As it stands, it doesn't. Function declarations without a return type are only allowed in < C99 and not at all in C++. And why use `string` but `std::cin`? The namespace specifier annoys me. – cadaniluk Dec 12 '15 at 21:09
  • Yes done. I'm sorry I'm currently not working with my editor :P – gabbar0x Dec 12 '15 at 21:13
  • Looks OK now but rather use an initializer list as common in C++. – cadaniluk Dec 12 '15 at 21:15
  • 'initializer list`? I'm sorry i dont understand – gabbar0x Dec 12 '15 at 21:15
  • Yes, but it shows the OP and any subsequent reader bad habits. I wouldn't say that a fine program's only requirement is to compile and work but also to be readable and maintainable. – cadaniluk Dec 12 '15 at 21:20
  • why use std::string if i have included it in my program #include . surely there is no need to use std::string. it confuses me everytime i see it. – jeremyo Dec 12 '15 at 22:45
  • Besides, the C++ string is a part of the std namespace – gabbar0x Dec 12 '15 at 22:47
  • still doesnt compile. i am using the header file with my class, cpp file for implementation and a main. ive included the header file in my main and also include header file in the cpp file. – jeremyo Dec 12 '15 at 23:00