Hi there,
leatorres87 wrote: |
---|
* I've never worked with a struct within a class. Therefore, i don't know how to call this struct from the main programm. In a similar way, it is the first time i work with a head, source file. I don't know how to call both of this from the main programm |
A struct within a class can be accessed using the scope resolution (::) operator :
1 2 3 4 5 6 7 8 9
|
class Foo
{
public:
struct Bar{};
Bar b;
}
//create a new Bar():
Foo::Bar some_bar;
|
You should
#include "BankKonto.h"
in the file where you have your main() function.
Then make sure that you compile the BankKonto.cpp file together with the main.cpp file (or make sure they are in the same project in your IDE). For g++ for instance one would do:
g++ -o my_application main.cpp BankKonto.cpp |
leatorres87 wrote: |
---|
* I don't even know how to start doing a tranfer from one guy's account to the other. |
Let's have a look at the bankaccount class:
1 2 3 4 5 6 7 8 9 10 11 12 13 14
|
class bankKonto{
public:
struct client{
char name;
unsigned accountNumber;
unsigned bankCode;
float balance;
int maximumWithdraw;
};
private:
client x;
bankKonto(){};
};
|
First off - it seems weird to me that BankAccount contains the blueprint for a client.
A client typically owns a bankaccount, not the other way around.
It's also strange that "client" contains information that actually belongs to the account, such as the balance and maximumWithDraw.
Anyway - making a transfer between two clients "sender" and "receiver', would involve that you decrease the senders "float balance", and add the same amount to the receivers balance. This is simplistic off course, in reality one would have a fail-over mechanism in case the process fails at any point, so the sender wouldn't just loose their money, or the receiver wouldn't get they money if the sender didn't have it.
Some more tips in general:
- Revise the design of the bankaccount and client class, something more natural would be:
1 2 3 4 5 6 7 8 9 10 11 12 13
|
struct bankaccount
{
unsigned accountNumber;
unsigned bankCode;
float balance;
int maximumWithdraw;
};
struct client
{
std::string name;
bankaccount account;
};
|
This way a client could even be extended to own multiple accounts if necessary (by creating an array of accounts).
- Try to stick to using one language in your code. It doesn't have to be English necessarily, but mixing German and Spanish will get anyone looking at your code confused quite easily.
Hope that gets you on your way.
Please do let us know if you have any further questions.
All the best,
NwN