Please assist or show me how to finish one of the .cpp files in a Banking program with header files

Pages: 12
the previous one continues for all of the savingItemHold.membertypes and checkingItemHold.membertypes.... redundant for me to post even more when this is already extremely annoying

last one:
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
In file included from savingsAccount.h:6:0,
                 from fileOperationImp2.cpp:7:
bankAccount.h:13:10: note: candidate: void bankAccount::setAccountType(int)
     void setAccountType(string accType);
          ^~~~~~~~~~~~~~
bankAccount.h:13:10: note:   no known conversion for argument 1 from ‘std::string {aka std::basic_string}’ to ‘int’
fileOperationImp2.cpp:193:40: error: no matching function for call to ‘savingsAccount::setFirstName(std::string&)’
         tempItem.setFirstName(subString);
                                        ^
In file included from savingsAccount.h:6:0,
                 from fileOperationImp2.cpp:7:
bankAccount.h:14:10: note: candidate: void bankAccount::setFirstName(int)
     void setFirstName(string firstName);
          ^~~~~~~~~~~~
bankAccount.h:14:10: note:   no known conversion for argument 1 from ‘std::string {aka std::basic_string}’ to ‘int’
fileOperationImp2.cpp:197:39: error: no matching function for call to ‘savingsAccount::setLastName(std::string&)’
         tempItem.setLastName(subString);
                                       ^
In file included from savingsAccount.h:6:0,
                 from fileOperationImp2.cpp:7:
bankAccount.h:15:10: note: candidate: void bankAccount::setLastName(int)
     void setLastName(string lastName);
          ^~~~~~~~~~~
bankAccount.h:15:10: note:   no known conversion for argument 1 from ‘std::string {aka std::basic_string}’ to ‘int’
fileOperationImp2.cpp:201:42: error: no matching function for call to ‘savingsAccount::setCompanyName(std::string&)’
         tempItem.setCompanyName(subString);
                                          ^
In file included from savingsAccount.h:6:0,
                 from fileOperationImp2.cpp:7:
bankAccount.h:16:10: note: candidate: void bankAccount::setCompanyName(int)
     void setCompanyName(string companyName);
          ^~~~~~~~~~~~~~
bankAccount.h:16:10: note:   no known conversion for argument 1 from ‘std::string {aka std::basic_string}’ to ‘int’
fileOperationImp2.cpp:205:38: error: no matching function for call to ‘savingsAccount::setAddress(std::string&)’
         tempItem.setAddress(subString);
                                      ^
In file included from savingsAccount.h:6:0,
                 from fileOperationImp2.cpp:7:
bankAccount.h:17:10: note: candidate: void bankAccount::setAddress(int)
     void setAddress(string address);
          ^~~~~~~~~~
bankAccount.h:17:10: note:   no known conversion for argument 1 from ‘std::string {aka std::basic_string}’ to ‘int’
fileOperationImp2.cpp:209:35: error: no matching function for call to ‘savingsAccount::setCity(std::string&)’
         tempItem.setCity(subString);
                                   ^
In file included from savingsAccount.h:6:0,
                 from fileOperationImp2.cpp:7:
bankAccount.h:18:10: note: candidate: void bankAccount::setCity(int)
     void setCity(string city);
          ^~~~~~~
bankAccount.h:18:10: note:   no known conversion for argument 1 from ‘std::string {aka std::basic_string}’ to ‘int’
fileOperationImp2.cpp: In function ‘void saveFieldCheckingAccount(int, std::string, checkingAccount&)’:
fileOperationImp2.cpp:236:42: error: no matching function for call to ‘checkingAccount::setAccountType(std::string&)’
         tempItem.setAccountType(subString);
                                          ^
In file included from savingsAccount.h:6:0,
                 from fileOperationImp2.cpp:7:
bankAccount.h:13:10: note: candidate: void bankAccount::setAccountType(int)
     void setAccountType(string accType);
          ^~~~~~~~~~~~~~
bankAccount.h:13:10: note:   no known conversion for argument 1 from ‘std::string {aka std::basic_string}’ to ‘int’
fileOperationImp2.cpp:244:40: error: no matching function for call to ‘checkingAccount::setFirstName(std::string&)’
         tempItem.setFirstName(subString);
                                        ^
In file included from savingsAccount.h:6:0,
                 from fileOperationImp2.cpp:7:
bankAccount.h:14:10: note: candidate: void bankAccount::setFirstName(int)
     void setFirstName(string firstName);
          ^~~~~~~~~~~~
bankAccount.h:14:10: note:   no known conversion for argument 1 from ‘std::string {aka std::basic_string}’ to ‘int’
fileOperationImp2.cpp:248:39: error: no matching function for call to ‘checkingAccount::setLastName(std::string&)’
         tempItem.setLastName(subString);
                                       ^
In file included from savingsAccount.h:6:0,
                 from fileOperationImp2.cpp:7:
bankAccount.h:15:10: note: candidate: void bankAccount::setLastName(int)
     void setLastName(string lastName);
          ^~~~~~~~~~~
bankAccount.h:15:10: note:   no known conversion for argument 1 from ‘std::string {aka std::basic_string}’ to ‘int’
fileOperationImp2.cpp:252:42: error: no matching function for call to ‘checkingAccount::setCompanyName(std::string&)’
         tempItem.setCompanyName(subString);
                                          ^
In file included from savingsAccount.h:6:0,
                 from fileOperationImp2.cpp:7:
bankAccount.h:16:10: note: candidate: void bankAccount::setCompanyName(int)
     void setCompanyName(string companyName);
          ^~~~~~~~~~~~~~
bankAccount.h:16:10: note:   no known conversion for argument 1 from ‘std::string {aka std::basic_string}’ to ‘int’
fileOperationImp2.cpp:256:38: error: no matching function for call to ‘checkingAccount::setAddress(std::string&)’
         tempItem.setAddress(subString);
                                      ^
In file included from savingsAccount.h:6:0,
                 from fileOperationImp2.cpp:7:
bankAccount.h:17:10: note: candidate: void bankAccount::setAddress(int)
     void setAddress(string address);
          ^~~~~~~~~~
bankAccount.h:17:10: note:   no known conversion for argument 1 from ‘std::string {aka std::basic_string}’ to ‘int’
fileOperationImp2.cpp:260:35: error: no matching function for call to ‘checkingAccount::setCity(std::string&)’
         tempItem.setCity(subString);
                                   ^
In file included from savingsAccount.h:6:0,
                 from fileOperationImp2.cpp:7:
bankAccount.h:18:10: note: candidate: void bankAccount::setCity(int)
     void setCity(string city);
          ^~~~~~~
bankAccount.h:18:10: note:   no known conversion for argument 1 from ‘std::string {aka std::basic_string}’ to ‘int
Looking at the first error:

1
2
bankAccount.h:13:25: error: ‘string’ has not been declared
     void setAccountType(string accType);


Either #include <string> hasn't been included at the top of the code - or using namespace std or using std::string has not been specified - in which case string should be std::string.

It's not good practice to have using... in header files.

Fixing this first error will also fix many of the other errors.

Long lists of errors like these are what you get when you don't code the program in parts with compiling and testing each part as you go. No part should ideally be longer than about 20 - 30 lines. Repeat - code. compile, fix compile errors, test, fix test errors - Until part works. Then repeat for the next code part... This way you're only got the last code additions to compile/test/fix and when the last code part is added, the program as a whole should work.
The large number of compiler errors are caused by a very small number of problems. See my first post on how to fix the "string" errors you're getting. Since the prof said you can't modify the .h files, I guess you should make the changes to the .cpp files. Or send him/her an email saying that the header files have compilation errors and send the examples.

It's unconscionable that the prof gave you header files that don't even compile. Frankly I'm not surprised that they didn't get their funding.

Okay, once you get through the errors in the header files, the code is very close to running correctly. Here are some of the things I found:

You need to implement bankAccount::getAccountType() const and bankAccount::deposit(). Also, bankAccount::withdraw currently adds money instead of subtracting it.

That will get everything to compile (at least it did for me). Time to test the code.

There's an old saying: "garbage in, garbage out." That means if your input data is bad or your code that reads the input is bad, then the output will be wrong, even if all the processing code is correct. So I'd start by adding this temporary code right after the readFile() in main():
1
2
    writeFile(fd.outSavingFile, fd.outCheckingFile, Caccounts, Saccounts, count);
    return 0;


This will make the program read the input file and write saving_account.csv and checking_account.csv. Check those files against bankData.csv and make sure they are correct (they won't be :) ). Fix the code as needed. Actually, I'll help you with one of the harder ones to find: bankAccount::setLastName() has a bug.

Once you have that working, remove the temporary code from main() and start testing the program. You will find some more problems, but they are easy to fix.

If you get stuck for more than an hour, post the problem in a reply.
So I fixed it all except for this strange issue? Not sure it doesn't come up as an error, only an extension after a warning:

1
2
3
4
5
6
7
8
[groovyjack@bruce AS3]$ g++ *.cpp -std=c++11 -Wall -Wpedantic -o ast3
fileOperationImp.cpp: In function ‘bool getNextField(std::string&, int&, std::string&)’:
fileOperationImp.cpp:123:25: warning: comparison of integer expressions of different signedness: ‘int’ and ‘std::basic_string<char>::size_type’ {aka ‘long unsigned int’} [-Wsign-compare]
  123 |   for (int i = index; i < line.size(); i++)
      |                       ~~^~~~~~~~~~~~~
/opt/rh/devtoolset-9/root/usr/libexec/gcc/x86_64-redhat-linux/9/ld: /tmp/ccuaUYTr.o: in function `readFile(std::basic_ifstream<char, std::char_traits<char> >&, std::vector<checkingAccount, std::allocator<checkingAccount> >&, std::vector<savingsAccount, std::allocator<savingsAccount> >&, int&)':
fileOperationImp.cpp:(.text+0x283): undefined reference to `saveFieldSavingAccount(int, std::string, savingsAccount&)'
collect2: error: ld returned 1 exit status


Any idea what it means? It's not creating the ast3 file which is the program I'm supposed to run through various checking and savings accounts withdrawals and deposits etc

Here is the code in question with the warning:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
bool getNextField(string &line, int &index, string &subString)
{
  for (int i = index; i < line.size(); i++)
    {
      if (line[i] != ',')
        {
          subString += line[i];
          index++;
        }
      else if (line[i] == ',')
        {
          index++;
          return true;
        }
    }
  return false;
}


here is the readfile function it says has the undefined reference from:
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
void readFile(ifstream &inFile, vector<checkingAccount> &Caccount, vector<savingsAccount> &Saccount, int &cou\
nt)
{
  checkingAccount checkingItemHold = {};
  savingsAccount savingItemHold = {};
  string lineFromDataBaseFile;

  while(getline(inFile, lineFromDataBaseFile))
    {
      int fieldNumber = 0;
      int index = 0;
      for (int i = 0; i < 11; i++)
        {
          string individualDataElementFromLineRead = "";
          getNextField(lineFromDataBaseFile, index, individualDataElementFromLineRead);
          saveFieldCheckingAccount(fieldNumber, individualDataElementFromLineRead, checkingItemHold);
          saveFieldSavingAccount(fieldNumber, individualDataElementFromLineRead, savingItemHold);
          fieldNumber++;

          individualDataElementFromLineRead = "";
        }
      if (checkingItemHold.getAccountType() == "Checking")
        {
          Caccount.push_back(checkingItemHold);
          count++;
        }

      if (savingItemHold.getAccountType() == "Saving")
        {
          Saccount.push_back(savingItemHold);
          count++;
        }
      fieldNumber = 0;
    }
}


and the saveFieldSavingsAccount function it says the undefined reference is in relation to:
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
void saveFieldSavingsAccount(int fieldNumber, string subString, savingsAccount &tempItem)
{
  if (fieldNumber == 0)
    {
      tempItem.setAccountType(subString);
    }
  else if (fieldNumber == 1)
    {
      tempItem.setAccountNumber(stringConvertInt(subString));
    }
  else if (fieldNumber == 2)
    {
      tempItem.setFirstName(subString);
    }
  else if (fieldNumber == 3)
    {
      tempItem.setLastName(subString);
    }
  else if (fieldNumber == 4)
    {
      tempItem.setCompanyName(subString);
    }
  else if (fieldNumber == 5)
    {
      tempItem.setAddress(subString);
    }
  else if (fieldNumber == 6)
    {
      tempItem.setCity(subString);
    }
  else if (fieldNumber == 7)
    {
      tempItem.setPhone1(stringConvertInt(subString));
    }
  else if (fieldNumber == 8)
    {
      tempItem.setPhone2(stringConvertInt(subString));
    }
  else if (fieldNumber == 9)
    {
      tempItem.setBalance(stringConvertDouble(subString));
    }
}
Last edited on
The warning is about signed/unsigned:
1
2
  for (std::string::size_type i = index; i < line.size(); i++)
    {
will remove the warning. Or use std::size_t.

The missing function is saveFieldSavingAccount(...). You implemented saveFieldSavingsAccount(...). Note the additional s.
Registered users can post here. Sign in or register to post.
Pages: 12