Programming Forums
User Name Password Register
 

RSS Feed
FORUM INDEX | TODAY'S POSTS | UNANSWERED THREADS | ADVANCED SEARCH

Reply
 
Thread Tools Display Modes
Old Oct 29th, 2004, 10:58 PM   #1
skylinegtr
Newbie
 
Join Date: Oct 2004
Posts: 9
Rep Power: 0 skylinegtr is on a distinguished road
Could someone please help me with getting my program to work. When I try to compile it I receive a list of errors but I don't know how to solve them. Any help would be great.
Thanks

Compiler - Borland C++ Builder 3

#ifndef _BANK_H_
#define _BANK_H_
#ifndef _BANKING_H_
#define _BANKING_H_
#ifndef _DATE_H_
#define _DATE_H_

#include <iostream>
#include <iomanip>
#include <string>
#include <vector>
#include <map>
#include <vector>
#include <iostream>
#include <fstream>

using Chrono:ate;
using std::istream;
using std::ostream;

using std::cout;
using std::cin;
using std::cerr;
using std::endl;
using std::right;
using std::fixed;
using std::setw;
using std::setprecision;
using std::ifstream;
using std::ofstream;
using Bank::Banking;
using Bank::Customer;
using Bank::Account;
using Bank::Money;
using Bank::Customer;
using Bank::Account;
using Bank::Transaction;
using Bank::TransType;
using Bank::TransStatus;
using std::map;
using std::ostream;
using std::endl;
using std::istringstream;


namespace Bank {
using std::string;
using std::vector;
using std::map;
using std::vector;
using std::istream;
using std::ostream;
using std::ifstream;
using std::ofstream;
using std::ostringstream;
using Chrono:ate;

class Money {
public:
Money(long c = 0) : cents&copy; {}
operator long() { return cents; }
long operator-() const { return -cents; }
private:
long cents;
};

inline istream& operator>>(istream& is, Money& m) {
double amt = 0;
is >> amt;
m = Money(static_cast<long>(amt *100));
return is;
}

ostream& operator<<(ostream& os, Money m);

enum TransType {DEPOSIT, WITHDRAWAL, INTEREST};

enum TransStatus {SUCCESS, DATE_BEFORE, NO_FUNDS};

class Transaction {
public:
void setDate(Date d) { date = d; }
Date getDate() const { return date; }
void setType(TransType t) { type = t; }
TransType getType() const { return type; }
void setAmount(Money m) { amt = m; }
Money getAmount() const { return amt; }
Money getValue() const { return type == WITHDRAWAL ? -amt : amt; }
void Save(ofstream&) const;
bool Load(ifstream&);
private:
Date date;
TransType type;
Money amt;
};


class Account; // Forward declaration

class Customer {
public:
// Explicit default constructor
explicit Customer(
unsigned i = NextCustomerNumber
) : num(i) {
if (num >= NextCustomerNumber) {
NextCustomerNumber = num + 1;
}
index[num] = this;
}
~Customer() {
index.erase(num);
}
// Return Customer Number
unsigned GetNumber() const {
return num;
}
// Set Customer Name
void SetName(const string& sn, const string& on) {
sname = sn;
onames = on;
}
// Return Customer Name
string GetName() const {
return onames + ' ' + sname;
}
// Set Customer Address
void SetAddress(
const string& sa,
const string& ta,
unsigned pc
) {
streetAddr = sa;
townAddr = ta;
postcode = pc;
}
// Return Customer Address
string GetAddress() const {
ostringstream out;
out << streetAddr << ", "
<< townAddr << ", "
<< postcode;
return out.str();
}
// Set Customer Date of Birth
void SetDOB(Date d) {
dob = d;
}
// Return Customer Date of Birth
Date GetDOB() const {
return dob;
}
// Add an Account to a Customer
void LinkAccount(Account* aptr) {
accounts.push_back(aptr);
}
Account* GetAccount(unsigned n) const {
if (n < accounts.size() ) {
return accounts[n];
} else {
return 0;
}
}
unsigned NumberOfAccounts() const {
return accounts.size();
}
static Customer* Find(unsigned n) {
map<unsigned, Customer*>::const_iterator it =
index.find(n);
if (it == index.end()) {
return 0;
}
return it->second;
}
static void Restore(ifstream&);
static void Preserve(ofstream&);
static void DeleteAll();
private:
const unsigned num;
static unsigned NextCustomerNumber;
string sname;
string onames;
string streetAddr;
string townAddr;
unsigned postcode;
Date dob;
vector<Account*> accounts;
static map<unsigned, Customer*> index;
void Save(ofstream&) const;
bool Load(ifstream&);
Customer(const Customer&) {} // No copying
};

class Account {
public:
// Explicit default constructor
explicit Account(
unsigned i = NextAccountNumber
) : num(i) {
if (num >= NextAccountNumber) {
NextAccountNumber = num + 1;
}
cust = 0;
intRate = 0;
bal = 0;
accruedInt = 0;
index[num] = this;
}
~Account() {
index.erase(num);
}
// Return Account Number
unsigned GetNumber() const {
return num;
}
void SetRate(double r) { intRate = r; }
double GetRate() const { return intRate; }
Money GetBalance() const { return bal; }
TransStatus AddTransaction(Date d, TransType t, Money amt);
// Credit Interest
TransStatus CreditInterest(Date d);
void SetCustomer(const Customer* c) { cust = c; }
const Customer* GetCustomer() const { return cust; }
void PrintStatement(ostream&) const;
// Find an account
static Account* Find(unsigned n) {
map<unsigned, Account*>::const_iterator it =
index.find(n);
if (it == index.end()) {
return 0;
}
return it->second;
}
static bool CreditAllInterest(Date d);
static void Restore(ifstream&);
static void Preserve(ofstream&);
static void DeleteAll();
private:
const unsigned num;
const Customer* cust;
double intRate;
Money bal;
double accruedInt;
vector<Transaction> translist;
static unsigned NextAccountNumber;
static map<unsigned, Account*> index;
void Save(ofstream&) const;
bool Load(ifstream&);
Account(const Account&) {} // No copying
};

}
#endif


namespace Bank {
/*** Class for Banking Application ***/
class Banking {
public:
Banking();
// Run the application
void Run();
~Banking();
private:
// Member functions for each menu item
void CreateCustomer();
void CreateAccount();
void ChangeAddress();
void CustomerEnquiry();
void PerformTransaction();
void ProduceStatement();
void EndOfMonth();
};
}
#endif


namespace Chrono {
using std::istream;
using std::ostream;

enum Month {
jan=1, feb, mar, apr, may, jun,
jul, aug, sep, oct, nov, dec
};

class BadDate {}; // For exceptions

class Date {
public:
Date (int dd = 0, Month mm = Month(0), int yy = 0);
int day() const {
return d;
}
Month month() const {
return Month(m);
}
int year() const {
return y;
}
Date operator++(); // prefix
Date operator++(int); // postfix
inline bool EndOfMonth() const;
static void set_default(int dd, Month mm, int yy) {
default_date = Date(dd, mm, yy);
}
private:
int d;
int m;
int y;
static Date default_date;
};

ostream& operator<<(ostream&, Date);

istream& operator>>(istream&, Date&);

inline bool leapYear(int y) {
return !(y%4) && (y%400 || !(y%100));
}

bool operator<(const Date&, const Date&);

int daysBetween(const Date&, const Date&);

int daysInMonth(int mm, int yy);

inline bool Date::EndOfMonth() const {
return d == daysInMonth(m, y);
}
}
#endif


/*** Default date initial value ***/
Date Date::default_date(1, jan, 2001);

/*** Date Default Constructor with validation ***/
Date:ate(int dd, Month mm, int yy) {
if (dd == 0) {
dd = default_date.day();
}
if (mm == 0) {
mm = default_date.month();
}
if (yy == 0) {
yy = default_date.year();
}

// Validate the date
if (yy < 1583) {
throw BadDate();
}
if (dd < 1 || dd > daysInMonth(mm, yy)) {
throw BadDate();
}
y = yy;
m = mm;
d = dd;
}

/*** Pre-Increment a date by a day ***/
Date Date::operator++() {
d++;
if (d > daysInMonth(m, y)) {
d = 1;
m++;
if (m > 12) {
m = 1;
y++;
}
}

return *this;
}


/*** Post-Increment a date by a day ***/
Date Date::operator++(int) {
Date temp = *this;;
d++;
if (d > daysInMonth(m, y)) {
d = 1;
m++;
if (m > 12) {
m = 1;
y++;
}
}

return temp;
}

/*** Date input operator overload, format dd/mm/yyy ***/
istream& Chrono::operator>>(istream& is, Date& d) {
int dd;
int mm;
int yy;
char slash;

if (!(is >> dd)) {
return is;
}
if (!is.get(slash)) {
return is;
}
if (slash != '/') {
is.putback(slash);
is.clear(std::ios_base::failbit);
return is;
}
if (!(is >>mm)) {
return is;
}
if (!is.get(slash)) {
return is;
}
if (slash != '/') {
is.putback(slash);
is.clear(std::ios_base::failbit);
return is;
}
if (!(is >> yy)) {
return is;
}
try {
d = Date(dd, Month(mm), yy);
}
catch (BadDate) {
// Set I/O status to fail if date invalid
is.clear(std::ios_base::failbit);
}
return is;
}

/*** Date output operator overload, format dd/mm/yyyy ***/
ostream& Chrono::operator<<(ostream& os, Date d) {
using std::right;
using std::setw;
using std::setfill;

std::ios_base::fmtflags f = os.flags();
char fillchar = os.fill(); // Save fill character

// Formatting ensures all dates output 10 chars wide
os << right << setfill(' ') << setw(2) << d.day() << '/'
<< setfill('0') << setw(2) << d.month() << '/'
<< setw(4) << d.year()
<< setfill(fillchar); // Restore fill character
os.flags(f); // Restore format flags
return os;
}

bool Chrono::operator<(const Date& d1, const Date& d2) {
if (d1.year() < d2.year()) {
return true;
}
if (d1.year() > d2.year()) {
return false;
}
/** Years must be equal ***/
if (d1.month() < d2.month()) {
return true;
}
if (d1.month() > d2.month()) {
return false;
}
/*** Years and months must be equal ***/
return d1.day() < d2.day();
}


/*** Days between two dates ***/
int Chrono::daysBetween(const Date& d1, const Date& d2) {
Date earlier;
Date later;
bool pos = d1 < d2;
if (pos) {
earlier = d1;
later = d2;
} else {
earlier = d2;
later = d1;
}
/** Now we are sure that earlier is before later ***/
int dayCount = 0;
while (earlier < later) {
dayCount++;
earlier++;
}
if (pos) {
return dayCount;
} else {
return -dayCount;
}
}


/*** Days in a particular month ***/
int Chrono::daysInMonth(int mm, int yy) {
int max; // Max days in month

switch (mm) {
case feb:
max = 28 + leapYear(yy);
break;
case apr: case jun: case sep: case nov:
max = 30;
break;
case jan: case mar: case may: case jul: case aug: case oct: case dec:
max = 31;
break;
default:
throw BadDate();
}

return max;
}


/*** Initial value of next customer number ***/
unsigned Customer::NextCustomerNumber = 1000;

/*** Indexes for Customers ***/
map<unsigned, Customer*> Customer::index;

/*** Initial value of next account number ***/
unsigned Account::NextAccountNumber = 100000;

/*** Indexes for Accounts ***/
map<unsigned, Account*> Account::index;

ostream& Bank::operator<<(ostream& os, Money m) {
using std::right;
using std::setw;
using std::setfill;

std::ios_base::fmtflags f = os.flags();
char fillchar = os.fill();

os << right << setfill(' ') << setw(7) << (m / 100) << '.'
<< setfill('0') << setw(2) << m % 100 << setfill(fillchar);
os.flags(f);
return os;
}

void Transaction:ave(ofstream& os) const {
char c;
switch (type) {
case DEPOSIT:
c = 'D';
break;
case WITHDRAWAL:
c = 'W';
break;
case INTEREST:
c = 'I';
break;
}
os << c << ":" << date << ":" << amt << endl;
}

bool Transaction::Load(ifstream& is) {
// About to read a character so clear to end of line
is.ignore(INT_MAX, '\n');
char c;
c = is.get();
switch &copy; {
case 'D':
type = DEPOSIT;
break;
case 'W':
type = WITHDRAWAL;
break;
case 'I':
type = INTEREST;
break;
default:
is.putback&copy;;
return false;
}
is.ignore(); // Separator
is >> date; // No error checking
is.ignore(); // Separator
is >> amt; // No error checking
return true;
}


/*** Restore all customers from a file ***/
void Customer::Restore(ifstream& is) {
unsigned cnum;
while (is >> cnum) {
Customer* c = new Customer(cnum);
if (!c->Load(is)) {
break;
}
}
}

/*** Preserve all customers to a file ***/
void Customer:reserve(ofstream& os) {
for (
map<unsigned, Customer*>::const_iterator it = index.begin();
it != index.end();
it++
) {
it->second->Save(os);
}
}


void Customer:eleteAll() {
for (
map<unsigned, Customer*>::const_iterator it = index.begin();
it != index.end();
it++
) {
delete it->second;
}
}

/*** Save a customer object to a file ***/
void Customer:ave(ofstream& os) const {
os << num << ':'
<< sname << ':'
<< onames << ':'
<< streetAddr << ':'
<< townAddr << ':'
<< postcode << ':'
<< dob << endl;
}

/*** Load a customer's details from a file ***/
bool Customer::Load(ifstream& is) {
/*** NOTE that there is no error checking here ***/
string input;
getline(is, input);
int idx1 = 0;
int idx2 = input.find(":", idx1+1);
sname = input.substr(idx1+1, idx2-idx1-1);
idx1 = idx2;
idx2 = input.find(":", idx1+1);
onames = input.substr(idx1+1, idx2-idx1-1);
idx1 = idx2;
idx2 = input.find(":", idx1+1);
streetAddr = input.substr(idx1+1, idx2-idx1-1);
idx1 = idx2;
idx2 = input.find(":", idx1+1);
townAddr = input.substr(idx1+1, idx2-idx1-1);
istringstream iss(input.substr(idx2+1));
iss >> postcode;
iss.ignore(); // skip separator
iss >> dob;
return true;
}

TransStatus Account::AddTransaction(Date d, TransType t, Money amt) {
// First check date is not before last transaction
if (!translist.empty() && d < translist.back().getDate()) {
return DATE_BEFORE;
}
// For withdrawal, check funds available
if (t == WITHDRAWAL && amt > bal) {
return NO_FUNDS;
}
// Calculate added accrued interest
if (!translist.empty()) {
accruedInt += intRate/365/100 * bal * daysBetween(translist.back().getDate(), d);
}
// Now build and add transaction
Transaction trans;
trans.setDate(d);
trans.setType(t);
trans.setAmount(amt);
translist.push_back(trans);
// Update balance
bal = bal + trans.getValue();
return SUCCESS;
}

TransStatus Account::CreditInterest(Date d) {
// First check date is not before last transaction
if (!translist.empty() && d < translist.back().getDate()) {
return DATE_BEFORE;
}
// Calculate added accrued interest
if (!translist.empty()) {
accruedInt += intRate/365/100 * bal * daysBetween(translist.back().getDate(), d);
}
// Now build and add transaction
Transaction trans;
trans.setDate(d);
trans.setType(INTEREST);
// Must round the accrued interest to nearest cent
trans.setAmount(static_cast<long>(accruedInt+0.5));
translist.push_back(trans);
// Update balance and reset accrued interest
bal = bal + trans.getAmount();
accruedInt = 0;
return SUCCESS;
}

void Account:rintStatement(ostream& os) const {
os << "Account Number: " << num << " Customer: " << cust->GetName() << endl;
os << "Date Transaction Amount Balance" << endl;
// Calulate starting balance
Money runningBal = bal;
for (
vector<Transaction>::const_iterator it = translist.begin();
it != translist.end();
it++
) {
runningBal = runningBal - it->getValue();
}
// Now output in sequence
for (
vector<Transaction>::const_iterator it = translist.begin();
it != translist.end();
it++
) {
os << it->getDate();
switch (it->getType()) {
case DEPOSIT:
os << " Deposit ";
break;
case WITHDRAWAL:
os << " Withdrawal ";
break;
case INTEREST:
os << " Interest ";
break;
}
os << it->getAmount() << " ";
runningBal = runningBal + it->getValue();
os << runningBal << endl;
}
}

bool Account::CreditAllInterest(Date d) {
bool status = true;
for (
map<unsigned, Account*>::const_iterator it = index.begin();
it != index.end();
it++
) {
if (it->second->CreditInterest(d) != SUCCESS) {
status = false;
}
}
return status;
}

/*** Restore all accounts from a file ***/
void Account::Restore(ifstream& is) {
unsigned anum;
while (is >> anum) {
Account* a = new Account(anum);
if (!a->Load(is)) {
break;
}
}
}

/*** Presereve all accounts to a file ***/
void Account:reserve(ofstream& os) {
for (
map<unsigned, Account*>::const_iterator it = index.begin();
it != index.end();
it++
) {
it->second->Save(os);
}
}

/*** Delete all accounts ***/
void Account:eleteAll() {
for (
map<unsigned, Account*>::const_iterator it = index.begin();
it != index.end();
it++
) {
delete it->second;
}
}

/*** Save an account to a file ***/
void Account:ave(ofstream& os) const {
os << num << ":"
<< cust->GetNumber() << ":"
<< intRate << ":"
<< bal << ":"
<< accruedInt << endl;
// Now save the transactions
for (
vector<Transaction>::const_iterator it = translist.begin();
it != translist.end();
it++
) {
it->Save(os);
}
}

/*** Load an account from a file ***/
bool Account::Load(ifstream& is) {
/*** NOTE: No error checking ***/
is.ignore(); // skip separtor
unsigned cnum;
is >> cnum;
Customer* c = Customer::Find(cnum);
c->LinkAccount(this);
cust = c;
is.ignore();
is >> intRate;
is.ignore();
is >> bal;
is.ignore();
is >> accruedInt;
// Now input transactions
Transaction trans;
while (trans.Load(is)) {
translist.push_back(trans);
}
return true;
}

namespace Bank {
// Helper function to select a customer
Customer* SelectCustomer();

// Help function to select an account
Account* SelectAccount(const Customer*);

// File names
const char* CustomersFile = "customers.txt";
const char* AccountsFile = "accounts.txt";
}

/*** Constructor loads the data from files ***/
Banking::Banking() {
ifstream c(CustomersFile);
if (!c) {
cerr << "No customers file, assuming no initial data" << endl;
} else {
Customer::Restore&copy;;
c.close();
}
ifstream a(AccountsFile);
if (!a) {
cerr << "No accounts file, assuming no initial data" << endl;
} else {
Account::Restore(a);
a.close();
}
}

/*** Run the banking application ***/
void Banking::Run() {
// Menu definition
static const string Prompts[] = {
"Create a new customer",
"Create a new account",
"Change a customer's address",
"Customer enquiry",
"Perform a transaction",
"Produce a statement",
"End of Month Processing",
"Exit"
};
const static unsigned MENU_ITEMS = sizeof(Prompts)/sizeof(string);

cout << "Welcome to the Banking Application" << endl;

while (true) {
cout << "\nMain Menu" << endl;
for (unsigned i = 0; i < MENU_ITEMS; i++) {
cout << right << setw(2) << i + 1 << ". "
<< Prompts[i] << endl;
}
cout << "Enter choice: ";
unsigned choice = 0;
if (!(cin >> choice)) {
cin.clear();
cin.ignore(INT_MAX, '\n');
// Allow default to catch
}
switch (choice) {
case 1:
CreateCustomer();
break;
case 2:
CreateAccount();
break;
case 3:
ChangeAddress();
break;
case 4:
CustomerEnquiry();
break;
case 5:
PerformTransaction();
break;
case 6:
ProduceStatement();
break;
case 7:
EndOfMonth();
break;
case 8:
// Exit
return;
default:
cout << "Invalid choice!" << endl;
}
}
}

/*** Create a new customer ***/
void Banking::CreateCustomer() {
Customer* c = new Customer;
cout << "Customer number " << c->GetNumber() << " created" << endl;
string surname;
cin.ignore(INT_MAX, '\n');
cout << "Enter Customer Surname: ";
getline(cin, surname);
string othernames;
cout << "Enter Customer Other Names: ";
getline(cin, othernames);
c->SetName(surname, othernames);
string street;
cout << "Enter Customer No. & Street: ";
getline(cin, street);
string town;
cout << "Enter Customer Town: ";
getline(cin, town);
unsigned postcode;
cout << "Enter Customer Postcode: ";
while (!(cin >> postcode)) {
cout << "Invalid postcode, try again: ";
cin.clear();
cin.ignore(INT_MAX, '\n');
}
c->SetAddress(street, town, postcode);
Date d;
cout << "Enter Customer Date of Birth (dd/mm/yyyy): ";
while (!(cin >> d)) {
cout << "Invalid date, try again: ";
cin.clear();
cin.ignore(INT_MAX, '\n');
}
c->SetDOB(d);
cout << "Cutomer details recorded!" << endl;
}

/*** Create a new account ***/
void Banking::CreateAccount() {
Customer* c;
if ((c = SelectCustomer()) == 0) {
return;
}
Account* a = new Account;
cout << "Account number " << a->GetNumber() << " created" << endl;
double rate;
cout << "Enter Interest Rate: ";
while (!(cin >> rate) || rate > 100.0) {
cout << "Invalid rate, try again: ";
cin.clear();
cin.ignore(INT_MAX, '\n');
}
a->SetRate(rate);
a->SetCustomer&copy;;
c->LinkAccount(a);
cout << "Account details recorded!" << endl;
}

/*** Change a customer's address ***/
void Banking::ChangeAddress() {
Customer* c;
if ((c = SelectCustomer()) == 0) {
return;
}
cout << "Customer's address is currently " << c->GetAddress() << endl;
string street;
cout << "Enter Customer No. & Street: ";
getline(cin, street);
string town;
cout << "Enter Customer Town: ";
getline(cin, town);
unsigned postcode;
cout << "Enter Customer Postcode: ";
while (!(cin >> postcode)) {
cout << "Invalid postcode, try again: ";
cin.clear();
cin.ignore(INT_MAX, '\n');
}
c->SetAddress(street, town, postcode);
cout << "Address changed!" << endl;
}

/*** Customer enquiry ***/
void Banking::CustomerEnquiry() {
Customer* c;
if ((c = SelectCustomer()) == 0) {
return;
}
cout << "Address: " << c->GetAddress() << endl;
cout << "Date of Birth: " << c->GetDOB() << endl;
if (c->NumberOfAccounts() == 0) {
cout << "No Accounts" << endl;
} else {
cout << "Accounts:" << endl;
for (unsigned i = 0; i < c->NumberOfAccounts(); i++) {
Account* a = c->GetAccount(i);
cout << "Account No. "
<< a->GetNumber()
<< " Interest Rate: "
<< setw(5) << fixed << setprecision(2) << a->GetRate() << "% "
<< "Balance: "
<< a->GetBalance()
<< endl;
}
}
}

/*** Perform a transaction ***/
void Banking:erformTransaction() {
Customer* c;
if ((c = SelectCustomer()) == 0) {
return;
}
Account* a;
if ((a = SelectAccount&copy == 0) {
return;
}
Date d;
cout << "Enter Transaction date (dd/mm/yyyy): ";
while (!(cin >> d)) {
cout << "Invalid date, try again: ";
cin.clear();
cin.ignore(INT_MAX, '\n');
}
char cmd;
TransType t;
// We're going to read a single char so clear the input buffer
cin.ignore(INT_MAX, '\n');
cout << "Deposit or Withdrawal (D or W): ";
cmd = cin.get();
switch (cmd) {
case 'D':
case 'd':
t = DEPOSIT;
break;
case 'W':
case 'w':
t = WITHDRAWAL;
break;
default:
cout << "Unknown transaction type!" << endl;
return;
}
Money amt;
cout << "Enter amount: ";
while (!(cin >> amt)) {
cout << "Invalid amount, try again: ";
cin.clear();
cin.ignore(INT_MAX, '\n');
}
switch (a->AddTransaction(d, t, amt)) {
case SUCCESS:
cout << "Transaction completed!" << endl;
break;
case DATE_BEFORE:
cout << "Transaction date before last transaction!" << endl;
break;
case NO_FUNDS:
cout << "Insufficient funds!" << endl;
break;
}
}

/*** Produce a statement ***/
void Banking:roduceStatement() {
Customer* c;
if ((c = SelectCustomer()) == 0) {
return;
}
Account* a;
if ((a = SelectAccount&copy == 0) {
return;
}
a->PrintStatement(cout);
}

/*** End of Month Processing ***/
void Banking::EndOfMonth() {
Date d;
cout << "Enter End of Month Date (dd/mm/yyyy): ";
while (!(cin >> d)) {
cout << "Invalid date, try again: ";
cin.clear();
cin.ignore(INT_MAX, '\n');
}
if (!d.EndOfMonth()) {
cout << "Not the end of a month!" << endl;
return;
}
if (!Account::CreditAllInterest(d)) {
cout << "Error encounted: not all accounts processed successfully!" << endl;
}
}

/*** Allow the user to select a customer ***/
Customer* Bank:electCustomer() {
Customer* c;
unsigned num;
cout << "Enter customer number: ";
while (!(cin >> num)) {
cout << "Invaid number, try again: ";
cin.clear();
cin.ignore(INT_MAX, '\n');
}
if ((c = Customer::Find(num)) == 0) {
cout << "Customer not found!" << endl;
} else {
cout << "Customer found: " << c->GetName() << endl;
}
cin.ignore(INT_MAX, '\n');
return c;
}

/*** Allow the user to select an account ***/
Account* Bank:electAccount(const Customer* c) {
if (c->NumberOfAccounts() == 0) {
cout << "No Accounts" << endl;
return 0;
} else {
cout << "Accounts:" << endl;
for (unsigned i = 0; i < c->NumberOfAccounts(); i++) {
cout << setw(2) << i + 1 << ". "
<< c->GetAccount(i)->GetNumber() << endl;
}
unsigned choice;
cout << "Select account: ";
while (!(cin >> choice) || choice > c->NumberOfAccounts()) {
cout << "Invalid choice, try again: ";
cin.clear();
cin.ignore(INT_MAX, '\n');
}
return c->GetAccount(choice - 1);
}
}

/*** Destructor deletes all customers ***/
Banking::~Banking() {
ofstream c(CustomersFile);
if (!c) {
cerr << "Unable to open customers file for saving" << endl;
} else {
Customer:reserve&copy;;
c.close();
}
ofstream a(AccountsFile);
if (!a) {
cerr << "Unable to open accounts file for saving" << endl;
} else {
Account:reserve(a);
a.close();
}
Customer:eleteAll();
Account:eleteAll();
}


int main() {
Bank::Banking ba;
ba.Run();
return 0;
}
skylinegtr is offline   Reply With Quote
Old Oct 30th, 2004, 12:31 AM   #2
Benoit
Expert Programmer
 
Benoit's Avatar
 
Join Date: Sep 2004
Location: Ontario, Canada
Posts: 579
Rep Power: 5 Benoit is on a distinguished road
Start by looking for the first error in the code and fixing it....a single error can cause more errors in a program
__________________
Johnny was a chemist's son but Johnny is no more, for what Johnny thought was H2O was H2SO4
Benoit is offline   Reply With Quote
Old Oct 30th, 2004, 1:44 AM   #3
tempest
Programming Guru
 
tempest's Avatar
 
Join Date: Oct 2004
Posts: 1,041
Rep Power: 6 tempest is on a distinguished road
Send a message via ICQ to tempest Send a message via AIM to tempest Send a message via Yahoo to tempest
Dude, what language did you write it in... C++/C/Java/Python i cant tell...
__________________

tempest is offline   Reply With Quote
Old Oct 30th, 2004, 3:27 AM   #4
Benoit
Expert Programmer
 
Benoit's Avatar
 
Join Date: Sep 2004
Location: Ontario, Canada
Posts: 579
Rep Power: 5 Benoit is on a distinguished road
That's C++. no?
__________________
Johnny was a chemist's son but Johnny is no more, for what Johnny thought was H2O was H2SO4
Benoit is offline   Reply With Quote
Old Oct 30th, 2004, 11:28 AM   #5
thechristelegacy
Expert Programmer
 
thechristelegacy's Avatar
 
Join Date: Jul 2004
Location: Somerset, Pa
Posts: 708
Rep Power: 5 thechristelegacy is on a distinguished road
Send a message via AIM to thechristelegacy Send a message via MSN to thechristelegacy
I'd hope it were C++ since it is in the c++ section of the forum
thechristelegacy is offline   Reply With Quote
Old Oct 31st, 2004, 5:47 PM   #6
skylinegtr
Newbie
 
Join Date: Oct 2004
Posts: 9
Rep Power: 0 skylinegtr is on a distinguished road
Yes, sorry for not saying but it is in C++.

Thanks for your replies.
skylinegtr is offline   Reply With Quote
Old Oct 31st, 2004, 6:45 PM   #7
tempest
Programming Guru
 
tempest's Avatar
 
Join Date: Oct 2004
Posts: 1,041
Rep Power: 6 tempest is on a distinguished road
Send a message via ICQ to tempest Send a message via AIM to tempest Send a message via Yahoo to tempest
Dude, tell me the truth. Did you guess at most of this code when you wrote it? If so, i mean its ok, we've all done it.
__________________

tempest is offline   Reply With Quote
Old Nov 15th, 2004, 7:43 AM   #8
CaveSnow
Newbie
 
Join Date: Nov 2004
Posts: 3
Rep Power: 0 CaveSnow is on a distinguished road
I have had a glance at the code, although I haven't examined all of it;
First of all:
#ifndef
Must be followed by an
#endif

So try to correct that in the begining of your proggie....
CaveSnow is offline   Reply With Quote
Reply

Bookmarks

« Previous Thread in Forum | Next Thread in Forum »

Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump




DaniWeb IT Discussion Community
All times are GMT -5. The time now is 4:00 AM.

Powered by vBulletin® Version 3.7.0, Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Copyright ©2007 DaniWeb® LLC