Hi, I study C++ myself and can't solve a little problem.
I created class konto (account) and it works fine. Now I want to create a class bank which contains several accounts and it should be possible to add a new account and to find a necessary account by number. I am not sure with all these arrays, how to do a class that contains several accounts from another class. I will appreciate smbs help. Please excuse my poor English. Thank you in advance.

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

class konto
{
public:
    konto (char*,int,double,float);
    void skrivut(void);
    void insat(const int &i);
    void uttag(float u);
    void ranteutbet();
   
private:
    int nomer;
    char name[89];
    double saldo;
    float renta;
   
};

konto::konto(char* name,int nomer, double saldo, float renta)
{
    strcpy (konto::name,name);
    konto::nomer=nomer;
    konto::saldo=saldo;
    konto::renta=renta;
   
}

void konto::skrivut(void)
{
    cout<<"name: "<<name<<endl;
    cout<<"nomer: "<<nomer<<endl;
    cout<<"renta%: "<<renta<<endl;
    cout<<"saldo: "<<saldo<<endl<<endl;    
}

void konto::insat(const int &i)
{
    saldo=saldo+i;
   
}

void konto::uttag(float u)
{
    saldo=saldo-u;
}
void konto::ranteutbet()
{
    saldo=saldo+(saldo*2.5/100);

}

class bank
{
};


void main()
{

    konto k ("Namn", 1, 1500, 2.5);

    k.skrivut();
    k.insat(500);
    k.skrivut();
    k.uttag(300);
    k.skrivut();
    k.ranteutbet();
    k.skrivut();



}

You will need to provide a default constructor. Then you can use konto in arrays and other containers.

...
#include <vector>
using namespace std;

...

class konto
{
public:
    konto( char* name = 0, int nomer = 0, double saldo = 0.0, float renta = 0.0 );
    ...
};

konto::konto( char* name, int nomer, double saldo, float renta )
{
    if (name) strcpy( this->name, name );
    else this->name[ 0 ] = '\0';
    this->nomer = nomer;
    this->saldo = saldo;
    this->renta = renta;
}

...

int main()
{
    vector <konto> konten;
    ...
}

Hope this helps.

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.