multiple files


so my bankacct.cpp and mainbankacct.cpp are not compiling . when its in one file it does.
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
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
  bankacct.h
#include <iostream>
#include <string>
using namespace std;

class Bank_Account		//name of the class
{
private:
  string name;			//attributes to the private so its protected
  int acct_num;
  int pin_num;
  double Balance;

public:

  void setName (string);	//for name to store
  string getName ();		//for name to store and retrive name
  void setAcctnum (int);	//account num to store
  int getAcctnum ();		//acct num for retrive acct number
  double getBalance ();		//retrieve the balance
  void setPIN (int);		// to store number
  bool checkPIN (int n);	// receives a PIN number as parameter, returns TRUE if it matches the PIN in the object
  void deposit (double);	// Receives amount of money to deposit.If this amount is valid (positive) then + to balance. Otherwise do nothing. No return value.
  void withdraw (double);	// Receives amount of money to withdraw. If this amount is valid(positive) then make sure there are funds to cover the withdrawl.
  //If so then subtract from balance. If not enough money then printthe message b Insufficent fundsb  and make no changes. No return value


    Bank_Account ()
  {
    acct_num = 12345;
    name = "Bruce Wayne";
    Balance = 400;		//balance needed to intialized
    pin_num = 5995;
  }

  Bank_Account (double B, string n, int p, int ac_no)
  {
    Balance = B;
    name = n;
    pin_num = p;
    acct_num = ac_no;
  }

  void print_details ()
  {
    cout << acct_num << " " << name << " " << pin_num << " " << Balance <<
      endl;
  }

};






  bankacct.cpp
#include <iostream>
#include <string>
#include "bankacct.h"
using namespace std;

void Bank_Account::setName (string Bname)
{
  name = Bname;
}

string Bank_Account::getName ()
{
  return name;
}

void Bank_Account::setAcctnum (int AN)
{
  acct_num = AN;
}

int Bank_Account::getAcctnum ()
{
  return acct_num;
}

double Bank_Account::getBalance ()
{
  return Balance;
}

void Bank_Account::setPIN (int a)
{
  pin_num = a;
}

bool Bank_Account::checkPIN (int n)
{
  if (n == pin_num)
    return true;
  return false;
}

void Bank_Account::deposit (double a)
{
  if (a <= 0)
    return;
  Balance += a;
}

void Bank_Account::withdraw (double a)
{
  if (a <= 0)
    return;

  if (a > Balance)
    {
      cout << "insufficient funds" << endl;
      return;
    }
  Balance -= a;
}

int findAccount (Bank_Account * obj[], int size, int ac_num)
{
  for (int i = 0; i < 5; i++)
    {
      if (obj[i]->getAcctnum () == ac_num)
	return i;
    }
  return -1;
}

int get_account (Bank_Account * obj[], int size)
{
  int res;
  cout << "Welcome to my Bank!!" << endl;
  cout << "please enter your account number or 0 to quit:";
  cin >> res;
  if (res == 0)
    return -1;
  int index = findAccount (obj, 5, res);
  if (index == -1)
    return -1;
  else
    {
      int try_count = 0;
      int max_try_count = 3;
      int input;
      cout << "Enter PIN:";
      do
	{
	  cin >> input;
	  if (obj[index]->checkPIN (input))
	    {
	      cout << "Welcome " << obj[index]->getName () << endl;
	      return index;
	    }
	  else
	    {
	      try_count++;
	      cout << "Invalid PIN, re-enter:";
	    }

	}
      while (try_count < max_try_count);
    }
  return -1;
}

mainbankacct.cpp
int main ()
{
  Bank_Account *obj_array[5];
  Bank_Account *obj = new Bank_Account (1000, "Barry  Allen", 1231, 1);
  obj_array[0] = obj;

  obj = new Bank_Account (10002, "Bruce Wayne", 1232, 2);
  obj_array[1] = obj;
  obj = new Bank_Account (10003, "Clark Kent", 1233, 3);
  obj_array[2] = obj;
  obj = new Bank_Account (10004, "Princess Diana", 1433, 4);
  obj_array[3] = obj;
  obj = new Bank_Account (10005, "Thaal Sinestro", 1453, 5);
  obj_array[4] = obj;

  // for(int i=0;i<5;i++)
  //   obj_array[i]->print_details();

  //cout << findAccount(obj_array,5,4)<<endl;
  //cout << findAccount(obj_array,5,6)<<endl;

  int ac = get_account (obj_array, 5);
  if (ac != -1)
    {
      char res;
      while (true)
	{
	  cout << "D(eposit) / W(ithdrawl) / Q(uit):" << endl;
	  cin >> res;
	  if (res == 'Q' || res == 'q')
	    {
	      cout << "Good Bye " << obj_array[ac]->getName () << endl;
	    }
	  else if (res == 'W' || res == 'w')
	    {
	      double amt;
	      cout << "Enter withdrawl amount:";
	      cin >> amt;
	      obj_array[ac]->withdraw (amt);	//obj_array[ac]->
	      cout << "Your balance is: $" << obj_array[ac]->
		getBalance () << endl;
	    }
	  else if (res == 'D' || res == 'd')
	    {
	      double amt;
	      cout << "Enter deposit amount:";
	      cin >> amt;
	      obj_array[ac]->deposit (amt);
	      cout << "Your balance is: $" << obj_array[ac]->
		getBalance () << endl;
	    }
	  else
	    {
	      cout << "invalid response" << endl;
	    }
	}
    }

  return 0;

}
so my bankacct.cpp and mainbankacct.cpp are not compiling

Then your compiler will be giving you messages explaining precisely which lines are causing it to fail, and precisely what the problem is with those lines.

I assume that you completely understand those error messages, and how to use the information they give you to fix the problems, because otherwise you would have shared them with us.
You to include bankacct.h in your main file as well.
Is it really necessary to use pointers ?
Topic archived. No new replies allowed.