Programming Forums
User Name Password Register
 

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

Reply
 
Thread Tools Display Modes
Old Oct 24th, 2004, 9:46 AM   #1
skylinegtr
Newbie
 
Join Date: Oct 2004
Posts: 9
Rep Power: 0 skylinegtr is on a distinguished road
I have just finished making a simple c++ banking program but now I have to add new accounts to it which I am having trouble with. If someone could please give me some tips on how to do it would be great as it is the last thing I need to do.

Here are the files to my program

Bank Program

I need to add a few more account types but the one I am having difficulty with is the Term Deposit Account.

It does not allow withdrawals prior to a certain number of days after the most recent deposit. Interest is accrued when a deposit is made but is only credited to the account when a withdrawal is made. There is a minimum transaction amount and minimum balance.

Thanks for your help
skylinegtr is offline   Reply With Quote
Old Oct 24th, 2004, 10:00 AM   #2
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
Virus check turns out clean.
thechristelegacy is offline   Reply With Quote
Old Oct 25th, 2004, 10:06 AM   #3
Berto
Programming Guru
 
Join Date: Aug 2004
Posts: 1,022
Rep Power: 6 Berto is on a distinguished road
Send a message via AIM to Berto Send a message via MSN to Berto
good to see you tested it for a virus, but didnt look at the code :-p oh and i will look at it when i get home from work.
__________________
"Put your hand on a hot stove for a minute, and it seems like an hour. Sit with a pretty girl for an hour, and it seems like a minute. THAT'S relativity."

- Albert Einstein
Berto is offline   Reply With Quote
Old Oct 26th, 2004, 11:39 PM   #4
skylinegtr
Newbie
 
Join Date: Oct 2004
Posts: 9
Rep Power: 0 skylinegtr is on a distinguished road
Thanks for your replies. But can someone please give me anything on how to solve it. I've gotten so close to finishing this program and its just this one thing I need help with.

Thanks
skylinegtr is offline   Reply With Quote
Old Oct 27th, 2004, 12:00 AM   #5
kurifu
Expert Programmer
 
kurifu's Avatar
 
Join Date: Jul 2004
Location: Halifax, Nova Scotia (Canada)
Posts: 784
Rep Power: 5 kurifu is on a distinguished road
Send a message via ICQ to kurifu Send a message via MSN to kurifu
I would check it for you if I could run Windows, sorry... perhaps you could explain a bit how the code works and I could help you from a bit more of a directive position?
__________________
Clifford Matthew Roche <geek@cliffordroche.com>
Web Hosting: http://www.crd-hosting.com
Consulting: http://www.crdev-consulting.com
kurifu is offline   Reply With Quote
Old Oct 27th, 2004, 12:18 AM   #6
skylinegtr
Newbie
 
Join Date: Oct 2004
Posts: 9
Rep Power: 0 skylinegtr is on a distinguished road
Here are all the files. Thanks for your help.


MAIN.C

/* Main program driver - trivial


*/
#include "banking.h"

int main() {
Bank::Banking ba;
ba.Run();
return 0;
}



BANKING HEADER FILE

/* banking.h - Header for the banking application

*/
#ifndef _BANKING_H_
#define _BANKING_H_

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


CHRONO HEADER FILE

/* chrono.h - Header file for date/time handling module


*/
#ifndef _DATE_H_
#define _DATE_H_
#include <iostream>
#include <string>

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



BANKING.C

/* bank.c - Implementation of Banking functionality


*/
#include "bank.h"
#include <iomanip>
#include <sstream>

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;

/*** 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;
}



BANKING.C

/* banking.c - Core Banking application


*/
#include <iostream>
#include <iomanip>
#include <fstream>
#include <string>
#include <map>
#include "banking.h"
#include "bank.h"
#include "chrono.h"

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;

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();
}



CHRONO.c

/* chrono.c - Implementation of date/time module

*/
#include <iostream>
#include <iomanip>
#include "chrono.h"
using Chrono:ate;
using std::istream;
using std::ostream;

/*** 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;
}
skylinegtr 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 6:44 AM.

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