Trying to create a programme which takes in info like a bank would.
So I have a class bank, which has two seperate classes in it: account and customer. The customer class keeps getting errors though. help would be kind.
main code.
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
|
#pragma once
#include "stdafx.h"
#include "customer.h"
#include "bank.h"
#include "account.h"
#include <iostream> //
#include <fstream> // ifstream
#include <sstream> // istringstream
#include <iomanip> //
#include "time.h" // clock
#include <fstream> // ifstream
#include <string>
using namespace std;
Bank bank0, bank1;
int _tmain(int argc, _TCHAR* argv[])
{
int t = clock();
ifstream in;
in.open("bank0.txt");
if (in.fail()) {
cout << "unable to open file"<< endl;
getchar();
return 0;
}
cout << "reading bank0.txt...";
while (1) {
string str;
getline(in,str);
if(str=="")
break;
Customer*customer=new Customer();
in >> customer;
bank0.add(customer);
}
while (1)
{
string str;
getline(in,str);
if(str=="")
break;
Account*account=new Account();
in >> account;
bank0.add(account);
}
while (1) {
string str;
getline(in,str);
if(str=="")
break;
Customer*customer=new Customer();
in >> customer;
bank1.add(customer);
}
while (1)
{
string str;
getline(in,str);
if(str=="")
break;
Account*account=new Account();
in >> account;
bank1.add(account);
}
in.close();
cout << "OK" << endl;
cout << "rutime = " << (double) (clock() - t) / CLOCKS_PER_SEC << "s" << endl << endl;
return 0;
}
// eof
|
account header
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23
|
#pragma once
#include "stdafx.h"
#include "customer.h"
#include "bank.h"
#include <iostream> //
#include <fstream> // ifstream
#include <sstream> // istringstream
#include <iomanip> //
#include "time.h" // clock
#include <fstream> // ifstream
#include <string>
using namespace std;
class Account{
public:
int AC_ID;
int C_ID;
int ballance;
Account*next;
Account();
};
istream& operator>>(istream&, Account*);
|
account cpp
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
|
#include "stdafx.h"
#include "stdafx.h"
#include "customer.h"
#include "bank.h"
#include "account.h"
#include <iostream> //
#include <fstream> // ifstream
#include <sstream> // istringstream
#include <iomanip> //
#include "time.h" // clock
#include <fstream> // ifstream
#include <string>
using namespace std;
Account::Account()
{
C_ID=AC_ID=ballance=0;
next=NULL;
}
istream& operator>>(istream& in, Account* account)
{
in>>account->AC_ID>>account->C_ID>>account->ballance;
return in;
}
|
Customer header
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23
|
#pragma once
#include "stdafx.h"
#include "bank.h"
#include "account.h"
#include <iostream> //
#include <fstream> // ifstream
#include <sstream> // istringstream
#include <iomanip> //
#include "time.h" // clock
#include <fstream> // ifstream
#include <string>
using namespace std;
class Customer{
public:
string firstname;
string lastname;
string town;
int C_ID;
Customer*next;
Customer();
};
istream& operator>>(istream&, Customer*);
|
Customer cpp
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
|
#include "stdafx.h"
#include "stdafx.h"
#include "customer.h"
#include "bank.h"
#include "account.h"
#include <iostream> //
#include <fstream> //
#include <sstream> //
#include <iomanip> //
#include "time.h"
#include <fstream>
#include <string>
using namespace std;
Customer::Customer()
{
firstname=lastname=town="";
C_ID=0;
next=NULL;
}
istream& operator>>(istream& in, Customer*customer)
{
in>>customer->C_ID>>customer->lastname>>customer->firstname>>customer->town;
return in;
}
|
Bank header
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
|
#pragma once
#include "stdafx.h"
#include "customer.h"
#include "bank.h"
#include "account.h"
#include <iostream> //
#include <fstream> // ifstream
#include <sstream> // istringstream
#include <iomanip> //
#include "time.h" // clock
#include <fstream> // ifstream
#include <string>
using namespace std;
class Bank
{
public:
Account*AC_header;
Customer*C_header;
Bank();
void add(Customer*);
void add(Account*);
};
|
Banks cpp
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
|
#pragma once
#include "stdafx.h"
#include "bank.h"
#include <string>
using namespace std;
Bank::Bank()
{
C_header=NULL;
AC_header=NULL;
}
void Bank::add(Customer*customer)
{
if (C_header==NULL)
C_header=customer;
else
{
while(C_header->next!=NULL)
C_header=C_header->next;
C_header=customer;
}
}
void Bank::add(Account*account)
{
if (AC_header==NULL)
AC_header=account;
else
{
while(AC_header->next!=NULL)
AC_header=AC_header->next;
AC_header=account;
}
}
|
error log
1>------ Build started: Project: lab10, Configuration: Debug Win32 ------
1>Compiling...
1>Account.cpp
1>c:\documents and settings\byrne\my documents\visual studio 2008\projects\lab10\lab10\bank.h(20) : error C2143: syntax error : missing ';' before '*'
1>c:\documents and settings\byrne\my documents\visual studio 2008\projects\lab10\lab10\bank.h(20) : error C4430: missing type specifier - int assumed. Note: C++ does not support default-int
1>c:\documents and settings\byrne\my documents\visual studio 2008\projects\lab10\lab10\bank.h(20) : error C4430: missing type specifier - int assumed. Note: C++ does not support default-int
1>c:\documents and settings\byrne\my documents\visual studio 2008\projects\lab10\lab10\bank.h(23) : error C2061: syntax error : identifier 'Customer'
1>Bank.cpp
1>Customer.cpp
1>c:\documents and settings\byrne\my documents\visual studio 2008\projects\lab10\lab10\bank.h(20) : error C2143: syntax error : missing ';' before '*'
1>c:\documents and settings\byrne\my documents\visual studio 2008\projects\lab10\lab10\bank.h(20) : error C4430: missing type specifier - int assumed. Note: C++ does not support default-int
1>c:\documents and settings\byrne\my documents\visual studio 2008\projects\lab10\lab10\bank.h(20) : error C4430: missing type specifier - int assumed. Note: C++ does not support default-int
1>c:\documents and settings\byrne\my documents\visual studio 2008\projects\lab10\lab10\bank.h(23) : error C2061: syntax error : identifier 'Customer'
1>lab10.cpp
1>c:\documents and settings\byrne\my documents\visual studio 2008\projects\lab10\lab10\bank.h(20) : error C2143: syntax error : missing ';' before '*'
1>c:\documents and settings\byrne\my documents\visual studio 2008\projects\lab10\lab10\bank.h(20) : error C4430: missing type specifier - int assumed. Note: C++ does not support default-int
1>c:\documents and settings\byrne\my documents\visual studio 2008\projects\lab10\lab10\bank.h(20) : error C4430: missing type specifier - int assumed. Note: C++ does not support default-int
1>c:\documents and settings\byrne\my documents\visual studio 2008\projects\lab10\lab10\bank.h(23) : error C2061: syntax error : identifier 'Customer'
1>c:\documents and settings\byrne\my documents\visual studio 2008\projects\lab10\lab10\lab10.cpp(42) : error C2664: 'void Bank::add(Account *)' : cannot convert parameter 1 from 'Customer *' to 'Account *'
1> Types pointed to are unrelated; conversion requires reinterpret_cast, C-style cast or function-style cast
1>c:\documents and settings\byrne\my documents\visual studio 2008\projects\lab10\lab10\lab10.cpp(62) : error C2664: 'void Bank::add(Account *)' : cannot convert parameter 1 from 'Customer *' to 'Account *'
1> Types pointed to are unrelated; conversion requires reinterpret_cast, C-style cast or function-style cast
1>Generating Code...
1>Build log was saved at "file://c:\Documents and Settings\Byrne\My Documents\Visual Studio 2008\Projects\lab10\lab10\Debug\BuildLog.htm"
1>lab10 - 14 error(s), 0 warning(s)
========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ==========