Moving data between classes in a program

I have a program which is meant to simulate some aspects of a banking system by using classes. It doesn't quite seem to make sense the way functions are grouped but I was given a guideline so I have to live with it.

The basic premise is that when started the program will call one function to initialise and display some data, then a second which will open a file and then itself call functions from three other classes to act on the data using the file and display the result.

What I'm struggling with is making sure that the right information is passed in the right way through all of the functions. So if I post the code hopefully some kind souls can help me untangle it and also point out all the other mistakes I've made.

EDIT: Sorry an idea of flow might help. Here's the order the functions need to run in:

setUpAccount
getBalance
readRecord
findAccount
applyTrans - addDeposit
- subWithdraw
- addInterest
... and then repeat until eof, then
getBalance

I'm supposed to be using a fourth class of functions, Process, to drive the other three, thus cutting down on instructions in the main().
Last edited on
And here's the program. Or can of worms perhaps. Or Gordian knot. You get the idea.

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
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
#include <iostream>
#include <fstream>

using namespace std;

class SavingsAccount
{
 public:
        void addDeposit(float, float)
        {
             float deposit;
             float balance;
             
             balance = (balance + deposit);
             return balance;
        }
        
        void subWithdraw(float, float)
        {
             float withdraw;
             float balance;
             
             balance = (balance - withdraw);
             return balance;
        }
        
        void addInterest(float)
        {
             float newRate;
             
             intRate = newRate;
             return intrate;
        }

        float getBalance()
        {
             cout << balance << endl;
        }

        bool matchAccount(int, int)
        {
             int accNo;
             int matchNo;
             
             while (accNo != matchNo)
                   return false;
        }
        
 private:
         int accNo;
         double balance;
         float intRate;
};

class Customer
{
 public:
        Customer c;
        SavingsAccount s;
        Transaction t;
        
        void createCust(string, string, int)
        {
             cout << "This routine allows staff to enter new customer data." << endl;
             
             cout << "Enter the customer details as follows:" << endl;
             cout << "first name, last name [Return] address [Return] account number [Return]." << endl;
             cin >> name;
             cin >> address;
             cin >> saveAcntNo;
        }
        
        bool searchAccounts(int)
        {
             while (accountNo != accNo)
                   return false;
        }
        
        void applyTrans(char)
        {
             Transaction t;
             
             switch(t.transType)
               {
                case 'C':
                  SavingsAccount.addDeposit(SavingsAccount.balance, );
                  Transaction.readRecord();
                  break;
                case 'D':
                  SavingsAccount.subWithdraw();
                  Transaction.readRecord();
                  break;
                case 'I':
                  SavingsAccount.addInterest();
                  Transaction.readRecord();
                  break;
               }
        }

 private:
         string name;
         string address;
         int saveAcntNo;
};

class Transaction
{
 public:
        void readRecord(ifstream)
        {
             float line1;
             float line2;
             char line3;
             if (!inFile.eof())
                   {
                         inFile >> line1;
                         inFile >> line2;
                         inFile >> line3;
                         
                         Transaction.findAccount(line1);
                   }
             else
                   {
                         s.getBalance();
                   }
        }
        
        int findAccount(s.accNo, t.saveAcntNo)
        {
             SavingsAccount s;
             Transaction t;
             
             if (s.accNo == t.saveAcntNo)
                Customer.applyTrans();
             else
                (s.accNo++; t.findAccount());
        }

 private:
         int accountNo;
         float amount;
         char transType;
};

class Process
{
 public:
        void setUpAccounts()
        {
             SavingsAccount accnts[7] = 
             {SavingsAccount(123456,0.0,0.05),
             {SavingsAccount(246890,0.0,0.05),
             {SavingsAccount(293567,0.0,0.05),
             {SavingsAccount(337761,0.0,0.05),
             {SavingsAccount(846579,0.0,0.05),
             {SavingsAccount(917355,0.0,0.05),
             {SavingsAccount(937568,0.0,0.05)};
        }
        
        processAll()
        {
                   SavingsAccount s;
                   Customer c;
                   Transaction t;
                   Process p;
                   
                   s.setUpAccounts();
                   s.getBalance();
                   t.readRecord(ifstream);
                   t.findAccount();
                   c.applyTrans();
        }
};

int main()
{
      ifstream inFile;
      inFile.open("trans.dat");
      
      Process p;
      
      p.processAll();

      system("pause");
      
}
Sorry to bump, but can noone help me with this?
closed account (zb0S216C)
Firstly, a void return type indicates that the method returns nothing. In SavingsAccount, getBalance( ) returns a float but doesn't return anything. Secondly, in Customer, you create an instance of Transaction before it's even declared. Thirdly, all of your methods' arguments have no identifiers. Without the identifiers, your arguments are useless. Fourthly, processAll( ) hasn't been given a return type. In function: readRecord( ), inFile has not been declared.

There're probably more errors but I was skimming through.
Last edited on
See this is one of my main problems, I was given a list of the functions and variables in each class and told to develop the program from that. So because I'm not very good, I just did what made sense even though I didn't understand why they would be void. I assumed that I'd misunderstood how a void function worked. I'm trying to fix that up now, for example float getbalance().
Topic archived. No new replies allowed.