Wanting to write a ATM program with classes and either linked lists or arrays

Basically I have used codeblocks to generate the functions/classes in my code i know what i want them to do but i cannot figure out how to manipulate the data i have

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
# include <iostream>
# include <fstream>


# define maxlength 5
# define max_acc 10
 using namespace std;

class Account
{
    public:
    
  
        Account();
        virtual ~Account();
        int GetCustomer_ID() { return Customer_ID; }
        void SetCustomer_ID(int val) { Customer_ID = val; }
        int GetAccount_ID() { return Account_ID; }
        void SetAccount_ID(int val) { Account_ID = val; }
        char GetAccount_Type() { return Account_Type; }
        void SetAccount_Type(char val) { Account_Type = val; }
        double GetBalance() { return Balance; }
        void SetBalance(double val) { Balance = val; }
        double GetInterest_Rate() { return Interest_Rate; }
        void SetInterest_Rate(double val) { Interest_Rate = val; }
        
    protected:
    private:
        int Customer_ID;
        int Account_ID;
        char Account_Type;
        double Balance;
        double Interest_Rate;
}Accounts [max_acc];

class Customer
{
    public:
        Customer ();
        ~Customer ();
        int GetCustomer_ID() { return Customer_ID; }
        void SetCustomer_ID(int val) { Customer_ID = val; }
        string GetCustomer_Name() { return Customer_Name; }
        void SetCustomer_Name(string val) { Customer_Name = val; }
        string GetAddress() { return Address; }
        void SetAddress(string val) { Address = val; }
    protected:
    private:
        int Customer_ID;
        string Customer_Name;
        string Address;
}Customers [maxlength];




int main ()
{

ifstream myfile ("customers.dat");

    if (myfile.is_open())
  {
    while ( myfile.good() )
    {  for (int n = 0; n <max_acc; n++)
    {
      myfile >> Customers[n]. SetCustomer_ID;
      myfile >> Customers[n].SetCustomer_Name;
      myfile >> Customers[n].SetAddress;
      myfile >> Accounts[n].SetAccount_Type ;
      myfile >> Accounts [n].SetAccount_ID;

           }

      myfile.close();}


this is to show the basis of what i am doing though i will need to add alot to this i know how to do the basic calculations etc.

Inside my Data there I am meant to input up until X then ignore X and process the next customer and accounts.

Simon Templar
63 Ninth Ave, Castlecrag
S
123456
0.00
X
Mata Hari
20 Wattle Ave, Doonside
K
937568
0.00
S
246890
0.00
C
917355
0.00
X
James Bond
C/- MI6, London
C
293567
0.00
X
Napolean Solo
Delflorios, New York City
S
337761
0.00
C
846579
0.00
X

There is a copy of the sample data Now Where X is i want to ignore that and Add the customer information to an Array or Linked List whichever is easier to implement

ie so that i can enter a customer number and view the associated accounts and account balances

with a loop which will simulate program exit when a varaible pin = 9999 so ie each customer should have the ability to choose any 4 digit number except for 9999 for their pin number or be able to type 9999 to exit i was thinking of using a switch statement on the Accounttype ie S,C,K etc including the balance operations while pin! = 9999 or allowing then to press a button ie X to exit

Which would make pin = 9999 so i know i need to declare that and remove a few of my functions as i have 1 extra Getter which is not necessary unless i can call specifically the Account information and the customer information separately.

Any Help on this is greatly Appriciated and my Apologies in advance for the length of my Post.

Multiple operations on the one account should be possible and multiple accounts/customers should be able to be dealt with. Each operation should generate a transaction which is appended to a fresh transaction file. Use a different file name and provide a facility for entering the file name when processing transactions. A PIN of - 9999 should be used to quit the machine Hint: It is suggested that your ATM class contain a customer object (and possibly a bank account object) or pointers to these so you can load a customer’s data in order to generate the transactions.


Using a menu containing
1 Withdraw Cash 2 Deposit 3 Show balance 4 Quit (ie pin = -9999 return 0)

Would run this on the selected account and adjust balance accordingly and generate output files so a

file << "CutomerID.txt" for example would be required i think i can write this part really it is correctly entering the data is what i am struggling with i think i would like to use linked lists though i have never done that before

Again i think a set of while loops to accomodate function such as where account type = 'C' for Checking no interest is to be applied so a set of loops to clacluate the correct interest etc is needed i can write this though i would need to know how to get the code once it is entered

I am thinking where the id entred in a cin matches the stores value for customer and the id matches the value for the account get the account type C etc for the others get the balance for that account then perform the transactions and save to file ie customerid(Random number).txt

Can you help me possibly achieve this


So any help is greatly appriciated
Last edited on
before you get too carried away:

1. The constructors and destructor for both the Customer and Acoount classes needs code (you only have declarations for them at the moment.)

2. The following lines are all errors for one reason or another:
1
2
3
4
5
      myfile >> Customers[n]. SetCustomer_ID;
      myfile >> Customers[n].SetCustomer_Name;
      myfile >> Customers[n].SetAddress;
      myfile >> Accounts[n].SetAccount_Type ;
      myfile >> Accounts [n].SetAccount_ID;



My apologies for not replying i had not had email notifictaion of your post hopefully you can help me through this as i am really struggling.

I thought i needed constructors and destructors and i knew that my Myfile were wrong


For my Constructors basically
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
Account :: SetCustomer_ID

for Loop 
{myfile >> Customers[n].customerID};

Account :: SetBalance 

{ myfile >> Customers[n].balance
}


customer:setcustname 

{
myfile >> Customers[n].Customer Name 
}



I have ued this on arrays when i knew the format of the data as it is not always identical i don't know how to set te function to pull in the data correctly though. we will use the above set of data for testing purposes.


if there is an error there i would be grateful as i haven't used functions before i have procedurally done this type of functions ie while and if's mainly


I will provide an outline of what i expect the functions to do

ie Set ID etc Reads in from Textfile as listed for customer "Customer.txt"

I will be adding an additional class with Deposit and withdrawal and Interest functions called ATM

I am Stuck on how to get the data into a linked list ideally as i have never used one so nay help on that would also be greatly appreciated

for most of the myfile i am assuming it is because the initial declarations are Void I am happy to change that as that was what was generated by codeblocks
Last edited on
I am still trying though i am completly stuck on the basics here

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
# include <iostream>
# include <fstream>
# include <string>
# define maxlength 5
# define max_acc 10
 using namespace std;

class Account 
{
    public:
        Account();
        virtual ~Account();
        int GetCustomer_ID() { return Customer_ID; }
        void SetCustomer_ID(int val) { Customer_ID = val; }
        int GetAccount_ID() { return Account_ID; }
        void SetAccount_ID(int val) { Account_ID = val; }
        char GetAccount_Type() { return Account_Type; }
        void SetAccount_Type(char val) { Account_Type = val; }
        double GetBalance() { return Balance; }
        void SetBalance(double val) { Balance = val; }
        double GetInterest_Rate() { return Interest_Rate; }
        void SetInterest_Rate(double val) { Interest_Rate = val; }
    protected:
    private:
        int Customer_ID;
        int Account_ID;
        char Account_Type;
        double Balance;
        double Interest_Rate;
}Accounts [max_acc];

class Customer
{
    public:
       // Don't think I need Customer ();
      //don't need virtual functions  ~Customer ();
        int GetCustomer_ID() { return Customer_ID; }
 // Want to pull in int value ofr customer ID i don't know how to call this or what i need to change       void SetCustomer_ID(int val) { Customer_ID = val; }
        string GetCustomer_Name() { return Customer_Name; }
        void SetCustomer_Name(string val) { Customer_Name = val; }
        string GetAddress() { return Address; }
        void SetAddress(string val) { Address = val; }
    protected:
    private:
        int Customer_ID;
        string Customer_Name;
        string Address;
}Customers [maxlength];

Customer.SetCustomer_ID(int)
{
       ifstream myfile ("customers.dat");

    if (myfile.is_open())
  {
    while ( myfile.good() )
    {  for (int n = 0; n <maxlength; n++)
    {
      myfile >> Customers [n].Customer_ID;
      }                  


int main ()
{
void Customer::SetCustomer_ID(int)
{
ifstream myfile ("customers.dat");

    if (myfile.is_open())
  {
    while ( myfile.good() )
    {  for (int n = 0; n <maxlength; n++)
    {
      myfile >> Customers [n].Customer_ID;cout<<flush;
      myfile >> Customers[n].Customer_Name;
      myfile >> Customers[n].Address;
      myfile >> Accounts[n].Account_Type;
      myfile >> Accounts[n].Account_ID;

           }

      myfile.close();}

}



{

system ("pause");
return 0;


}
}


I am sure there are errors in the functions can someone help me and go through this step by step

All functions here were generated by codelocks i don't know how to call them or use them corectly and i am in a panic
any help is appriciated
Last edited on
Topic archived. No new replies allowed.