So, when I run the program and try to list all the information I get an interesting error message that pops up:

-----

Debug Assertion Failed!

Program: ...ocuments\Programs\C + +
Programs\Checkbook\Debug\Checkbook.exe
File: f:\dd\vctools\crt_bld\self_x86\crt\src\tccpy_s.inl
Line: 19

Expression: (((_Src))) != NULL

-----

Though I have an idea that it probably has something to do with the if statement
regarding the list function, but I don't really get what's wrong with it. Also, I need a little help with the balance function. its suppose to keep track of how much money is left in the balance. So depositing would add money to the current balance and writing a check would decrease from the current balance. I was hinted of using strings to integers but I have no idea where to start, Thanks for any help. Below is my code:

*Also there's suppose to be a text file which the program reads and writes to, name it Checkbook.txt

Checkbook.h

#ifndef _CHECKBOOK_H_
#define _CHECKBOOK_H_

#define _CRT_SECURE_NO_WARNINGS

#include <iostream>
#include <fstream>
#include <stdlib.h>
#include "Check.h"
using namespace std;

class Checkbook
{
	private:
		fstream	file;

	public:
			Checkbook()	// constructor opens the file
			{
				// input and output stream
				file.open("Checkbook.txt", ios::in | ios::out | ios::app);
				if (!file.good())
				{
					cerr << "ERROR: unable to open \"Checkbook.txt\"\n";
					exit(1);
				}

			}

			~Checkbook()	// destructor flushes and closes the file
			{
				file.flush();
				file.close();
			}

		
		char menu();
		void interactive();
		void list();
		int read(Check stack[]);
		void newDeposit();
		void newDeposit(char* date, char* amount);
		void newCheck();
		void newCheck(char* checkNo, char* date, char* recipient, char* amount);
		//void balance();
		void print(Check* entry) { entry->printCheck(); }

};

#endif

Check.h

#ifndef _CHECK_
#define _CHECK_

#include <iostream>
#include <iomanip>
#include <string>
using namespace std;

enum sizes { FIELD = 20, DATE = 20, RECIPIENT = 50, AMOUNT = 50  };	// the sizes of card fields

class Check
{
	private:
			char checkNo[FIELD];
			char date[DATE];
			char recipient[RECIPIENT];
			char amount[AMOUNT];

	public:
			Check()
			{
				checkNo[0] = '\0';
				date[0] = '\0';
				recipient[0] = '\0';
				amount[0] = '\0';
			}

			Check(char* c, char* d, char* r, char* a)
			{
				strcpy_s(checkNo, c);
				strcpy_s(date, d);
				strcpy_s(recipient, r);
				strcpy_s(amount, a);
			}

			Check(char* line)
			{
				strcpy_s(checkNo, strtok(line, ":"));
				strcpy_s(date, strtok(NULL, ":"));
				strcpy_s(recipient, strtok(NULL, ":"));
				strcpy_s(amount, strtok(NULL, ":"));
			}

			void printCheck()
			{
				cout << setw(FIELD) << checkNo;
				cout << setw(DATE) << date;
				cout << setw(RECIPIENT) << recipient;
				cout << setw(AMOUNT) << amount;
			}

};

#endif

Checkbook.cpp

#define _CRT_SECURE_NO_WARNINGS

#include <iostream>
#include <fstream>
#include <cstring>
#include "Checkbook.h"
#include "Check.h"
using namespace std;

int main(int argc, char* argv[])
{
	Checkbook checkbook;

	if (argc == 1)						
		checkbook.interactive();

	else if (argc == 2 && !strcmp(argv[1], "-l"))
		checkbook.list();

	else if (argc == 2 && strcmp(argv[1], "deposit"))
		checkbook.newDeposit(argv[2], argv[3]);

	else if (argc == 5)
		checkbook.newCheck(argv[1], argv[2], argv[3], argv[4]);	

	else
		cerr << "USAGE: Checkbook | Checkbook -1 | Checkbook deposit <date> <amount> | Checkbook <checkNo> <date> <recipient> <amount> \n";

	return 0;
} 

char Checkbook::menu()
{
	system("cls");

	cout << "C\t Create a new check \n";
	cout << "D\t Enter a new deposit \n";
	cout << "L\t List all current entries \n";
	cout << "B\t Balance checkbook \n";
	cout << "Q\t Quit \n";

	cout << "\n\nCommand: ";

	char command;
	cin >> command;
	cin.ignore();						// discard the new line

	return command;
}

void Checkbook::interactive()
{
	while (true)
	{
		char operation = menu();

		switch (operation)
		{
			case 'c' :				// search
			case 'C' :
				newCheck();
				system("pause");
				break;

			case 'd' :				// search
			case 'D' :
				newDeposit();
				system("pause");
				break;

			case 'l' :				// enter
			case 'L' :
				list();
				system("pause");
				break;

			case 'b' :				// list
			case 'B' :
				//balance();
				system("pause");
				break;

			case 'q' :				// quit
			case 'Q' :
				exit(0);

			default:
				cerr << "Unknown option: " << operation << endl;
				break;
		}

	}

}

void Checkbook::newDeposit()
{
	char date[DATE];
	char amount[AMOUNT];

	cout << "Please enter date the check was written: ";
		cin.getline(date, DATE);

	cout << "Please enter the amount: $";
		cin.getline(amount, AMOUNT);

	newDeposit(date, amount);
}

void Checkbook::newDeposit(char* date, char* amount)
{
	file.clear();						
	file.seekp(0, ios::end);				

	file << "Deposit" << ": " << date << ": " << "-" << ": " << "$ " << amount << endl;

	file.flush();
}

void Checkbook::newCheck()
{
	char checkNo[FIELD];
	char date[DATE];
	char recipient[RECIPIENT];
	char amount[AMOUNT];

	cout << "Please enter the check number: ";
		cin.getline(checkNo, FIELD);

	cout << "Please enter date the check was written: ";
		cin.getline(date, DATE);

	cout << "Please enter the recipient: ";
		cin.getline(recipient, RECIPIENT);

	cout << "Please enter the amount: $";
		cin.getline(amount, AMOUNT);

	newCheck(checkNo, date, recipient, amount);
}

void Checkbook::newCheck(char* checkNo, char* date, char* recipient, char* amount)
{
	file.clear();						
	file.seekp(0, ios::end);				

	file << checkNo << ": " << date << ": " << recipient << ": " << "$" << amount << endl;

	file.flush();
}

void Checkbook::list()
{
	Check list[100];
	int	count = read(list);

	for (int i = 0; i < count; i++)
		print(&list[i]);
}

int Checkbook::read(Check stack[])
{
	file.clear();			
	file.seekg(0);						

	int	count = 0;
	char line[100];

	while (file.getline(line, 100))
	{
		stack[count] = Check(line);
		count++;
	}

	return count;
}

Did you open your code in VS 2010 and it was created in VS 2008? That was what I found for the assertion error. You need to import your project so it is not dependent on the old DLLs.

As far as the other functions go, please take a crack at them first and we can help you with whatever issues come up.

I took snippets of code that was probably made in VS 2008. I'm currently using VS 2010, should i rewrite the entire program in VS 2010?

No, probably best to start a whole new project in VS 2010 and copy/paste the code into it. Make sure precompiled headers are off.

>> Debug Assertion Failed!
>> Expression: (((_Src))) != NULL

This interesting error message pops up because you are passing a NULL pointer as a second argument ( _Src ) to strcpy_s() -- you have to be careful not to do that. This NULL pointer is likely to originate from one of the strtok() calls.

Run the program in the Debugger and hit Retry/Break when the assertion occurs, then, view Call Stack and you'll be able to navigate to the offending line of your code.

So I'm sort of stuck on the balance function. For the balance function I'm thinking somewhere in the text file, keep track of a balance. What I'm trying to do for that balance function is to basically have it return just that portion of the text file that has the balance.I don't have too much experience with reading from files, so I don't know too much. I'm also stuck trying to think of a way in which the balance can be accessed by the add_to_balance and subtract_from_balance function, maybe a global variable or something. The add, subtract, and balance functions are at the bottom of the Checkbook.cpp. There's a call to the add_to_balance function in the newDeposit function, I commented the function and function call out so there's no compiling errors. Any advice to what kind of things I could do?

Checkbook.h

#ifndef _CHECKBOOK_H_
#define _CHECKBOOK_H_

#define _CRT_SECURE_NO_WARNINGS

#include <iostream>
#include <fstream>
#include <stdlib.h>
#include "Check.h"
using namespace std;

class Checkbook
{
	private:
		fstream	file;

	public:
			Checkbook()	// constructor opens the file
			{
				// input and output stream
				file.open("Checkbook.txt", ios::in | ios::out | ios::app);
				if (!file.good())
				{
					cerr << "ERROR: unable to open \"Checkbook.txt\"\n";
					exit(1);
				}

			}

			~Checkbook()	// destructor flushes and closes the file
			{
				file.flush();
				file.close();
			}

		char menu();
		void interactive();

		void newDeposit();
		void newDeposit(char* date, char* amount);

		int read(Check stack[]);
		void newCheck();
		void newCheck(char* checkNo, char* date, char* recipient, char* amount);
		void list();
		void print(Check* entry) { entry->printCheck(); }

		double balance();
		double add_to_balance(double deposit);
		double subtract_from_balance(double check);
};

#endif

Check.h

#ifndef _CHECK_
#define _CHECK_

#include <iostream>
#include <iomanip>
#include <string>
using namespace std;

enum sizes { FIELD = 20, DATE = 20, RECIPIENT = 50, AMOUNT = 50  };	// the sizes of card fields

class Check
{
	private:
			char checkNo[FIELD];
			char date[DATE];
			char recipient[RECIPIENT];
			char amount[AMOUNT];

	public:
			Check()
			{
				checkNo[0] = '\0';
				date[0] = '\0';
				recipient[0] = '\0';
				amount[0] = '\0';
			}

			Check(char* c, char* d, char* r, char* a)
			{
				strcpy_s(checkNo, c);
				strcpy_s(date, d);
				strcpy_s(recipient, r);
				strcpy_s(amount, a);
			}

			Check(char* line)
			{
				strcpy_s(checkNo, strtok(line, ":"));
				strcpy_s(date, strtok(NULL, ":"));
				strcpy_s(recipient, strtok(NULL, ":"));
				strcpy_s(amount, strtok(NULL, ":"));
			}

			void printCheck()
			{
				cout << checkNo << ": " << date << ": " << recipient << ": " << "$ " << amount << endl << endl;
			}
};

#endif

Checkbook.cpp

#define _CRT_SECURE_NO_WARNINGS

#include <iostream>
#include <fstream>
#include <cstring>
#include <strstream>	
#include "Checkbook.h"
#include "Check.h"
using namespace std;

int main()
{
	Checkbook checkbook;

	checkbook.menu();

	return 0;
}

char Checkbook::menu()
{
	system("cls");

	cout << "C\t Create a new check \n";
	cout << "D\t Enter a new deposit \n";
	cout << "L\t List all current entries \n";
	cout << "B\t Balance checkbook \n";
	cout << "Q\t Quit \n";

	cout << "\n\nCommand: ";

	char command;
	cin >> command;
	cin.ignore();						// discard the new line

	return command;
}

void Checkbook::interactive()
{
	while (true)
	{
		char operation = menu();

		switch (operation)
		{
			case 'c' :				// search
			case 'C' :
				newCheck();
				system("pause");
				break;

			case 'd' :				// search
			case 'D' :
				newDeposit();
				system("pause");
				break;

			case 'l' :				// enter
			case 'L' :
				list();
				system("pause");
				break;

			case 'b' :				// list
			case 'B' :
				//balance();
				system("pause");
				break;

			case 'q' :				// quit
			case 'Q' :
				exit(0);

			default:
				cerr << "Unknown option: " << operation << endl;
				break;
		}

	}

}

void Checkbook::newDeposit()
{
	char date[DATE];
	char amount[AMOUNT];

	cout << "Please enter date the check was written: ";
		cin.getline(date, DATE);

	cout << "Please enter the amount: $";
		cin.getline(amount, AMOUNT);

	newDeposit(date, amount);
}

void Checkbook::newDeposit(char* date, char* amount)
{
	file.clear();						
	file.seekp(0, ios::end);				

	istrstream n1(amount);
	double temp;

	n1 >> temp;

	//add_to_balance(temp);

	file << "Deposit" << " : " << date << " : " << "-" << " : " << "$" << amount << endl;

	file.flush();
}

void Checkbook::newCheck()
{
	char checkNo[FIELD];
	char date[DATE];
	char recipient[RECIPIENT];
	char amount[AMOUNT];

	cout << "Please enter the check number: ";
		cin.getline(checkNo, FIELD);

	cout << "Please enter date the check was written: ";
		cin.getline(date, DATE);

	cout << "Please enter the recipient: ";
		cin.getline(recipient, RECIPIENT);

	cout << "Please enter the amount: $";
		cin.getline(amount, AMOUNT);

	newCheck(checkNo, date, recipient, amount);
}

void Checkbook::newCheck(char* checkNo, char* date, char* recipient, char* amount)
{
	file.clear();						
	file.seekp(0, ios::end);	

	file << checkNo << " : " << date << " : " << recipient << " : " << "$" << amount << endl;

	file.flush();
}

void Checkbook::list()
{
	Check list[100];
	int	count = read(list);

	for (int i = 0; i < count; i++)
		print(&list[i]);
}

int Checkbook::read(Check stack[])
{
	file.clear();			
	file.seekg(0);						

	int	count = 0;
	char line[100];

	while (file.getline(line, 100))
	{
		stack[count] = Check(line);
		count++;
	}

	return count;
}

/*double Checkbook::balance()
{

} 

double Checkbook::add_to_balance(double deposit)
{
	
} */

You don't need to mess around with the file read/write for balance at all. Is there any reason why Checkbook can't have a private member variable named balance? Then your balance() and add_to_balance methods really only need 1 line (well, you should do some error checking too, unless you want an account in the red for 10,000.00).

Ok, I did just that and it looks pretty good. My question is, is it gonna keep track of how much money is in the balance and taken from the balance? or is that gonna need to rely on the text file for that information?

Ok, I did just that and it looks pretty good. My question is, is it gonna keep track of how much money is in the balance and taken from the balance? or is that gonna need to rely on the text file for that information? also my balance isn't printing out for some reason.

Checkbook.h

#ifndef _CHECKBOOK_H_
#define _CHECKBOOK_H_

#define _CRT_SECURE_NO_WARNINGS

#include <iostream>
#include <fstream>
#include <stdlib.h>
#include "Check.h"
using namespace std;

class Checkbook
{
	private:
		double currentBalance;
		fstream	file;

	public:
			
		Checkbook() : currentBalance(0.0)	// constructor opens the file
			{
				// input and output stream
				file.open("Checkbook.txt", ios::in | ios::out | ios::app);
				if (!file.good())
				{
					cerr << "ERROR: unable to open \"Checkbook.txt\"\n";
					exit(1);
				}

			}

			~Checkbook()	// destructor flushes and closes the file
			{
				file.flush();
				file.close();
			}

		char menu();
		void interactive();
		int read(Check stack[]);
		void list();
		void print(Check* entry) { entry->printCheck(); }

		void newDeposit();
		void newDeposit(char* date, char* amount);

		void newCheck();
		void newCheck(char* checkNo, char* date, char* recipient, char* amount);

		void balance();
		double add_to_balance(double tempBalance, double depositAmount);
		double subtract_from_balance(double tempBalance, double checkAmount);
};

#endif

Check.h

#ifndef _CHECK_
#define _CHECK_

#include <iostream>
#include <iomanip>
#include <string>
using namespace std;

enum sizes { FIELD = 20, DATE = 20, RECIPIENT = 50, AMOUNT = 50  };	// the sizes of card fields

class Check
{
	private:
			char checkNo[FIELD];
			char date[DATE];
			char recipient[RECIPIENT];
			char amount[AMOUNT];

	public:
			Check()
			{
				checkNo[0] = '\0';
				date[0] = '\0';
				recipient[0] = '\0';
				amount[0] = '\0';
			}

			Check(char* c, char* d, char* r, char* a)
			{
				strcpy_s(checkNo, c);
				strcpy_s(date, d);
				strcpy_s(recipient, r);
				strcpy_s(amount, a);
			}

			Check(char* line)
			{
				strcpy_s(checkNo, strtok(line, ":"));
				strcpy_s(date, strtok(NULL, ":"));
				strcpy_s(recipient, strtok(NULL, ":"));
				strcpy_s(amount, strtok(NULL, ":"));
			}

			void printCheck()
			{
				cout << checkNo << ": " << date << ": " << recipient << ": " << "$ " << amount << endl << endl;
			}
};

#endif

Checkbook.cpp

#define _CRT_SECURE_NO_WARNINGS

#include <iostream>
#include <fstream>
#include <cstring>
#include <strstream>	
#include "Checkbook.h"
#include "Check.h"
using namespace std;

int main()
{
	Checkbook checkbook;

	checkbook.menu();

	return 0;
}

char Checkbook::menu()
{
	system("cls");

	cout << "C\t Create a new check \n";
	cout << "D\t Enter a new deposit \n";
	cout << "L\t List all current entries \n";
	cout << "B\t Balance checkbook \n";
	cout << "Q\t Quit \n";

	cout << "\n\nCommand: ";

	char command;
	cin >> command;
	cin.ignore();						// discard the new line

	return command;
}

void Checkbook::interactive()
{
	while (true)
	{
		char operation = menu();

		switch (operation)
		{
			case 'c' :				// search
			case 'C' :
				newCheck();
				system("pause");
				break;

			case 'd' :				// search
			case 'D' :
				newDeposit();
				system("pause");
				break;

			case 'l' :				// enter
			case 'L' :
				list();
				system("pause");
				break;

			case 'b' :				// list
			case 'B' :
				balance();
				system("pause");
				break;

			case 'q' :				// quit
			case 'Q' :
				exit(0);

			default:
				cerr << "Unknown option: " << operation << endl;
				break;
		}

	}

}

void Checkbook::newDeposit()
{
	char date[DATE];
	char amount[AMOUNT];

	cout << "Please enter date the check was written: ";
		cin.getline(date, DATE);

	cout << "Please enter the amount: $";
		cin.getline(amount, AMOUNT);

	newDeposit(date, amount);
}

void Checkbook::newDeposit(char* date, char* amount)
{
	file.clear();						
	file.seekp(0, ios::end);				

	istrstream n1(amount);
	double temp;
	n1 >> temp;

	add_to_balance(currentBalance, temp);

	file << "Deposit" << " : " << date << " : " << "-" << " : " << "$" << amount << endl;
        file.flush();
}

void Checkbook::newCheck()
{
	char checkNo[FIELD];
	char date[DATE];
	char recipient[RECIPIENT];
	char amount[AMOUNT];

	cout << "Please enter the check number: ";
		cin.getline(checkNo, FIELD);

	cout << "Please enter date the check was written: ";
		cin.getline(date, DATE);

	cout << "Please enter the recipient: ";
		cin.getline(recipient, RECIPIENT);

	cout << "Please enter the amount: $";
		cin.getline(amount, AMOUNT);

	newCheck(checkNo, date, recipient, amount);
}

void Checkbook::newCheck(char* checkNo, char* date, char* recipient, char* amount)
{
	file.clear();						
	file.seekp(0, ios::end);	
	
	istrstream n1(amount);
	double temp;
	n1 >> temp;

	subtract_from_balance(currentBalance, temp);

	file << checkNo << " : " << date << " : " << recipient << " : " << "$" << amount << endl;
        file.flush();
}

void Checkbook::list()
{
	Check list[100];
	int	count = read(list);

	for (int i = 0; i < count; i++)
		print(&list[i]);
}

int Checkbook::read(Check stack[])
{
	file.clear();			
	file.seekg(0);						

	int	count = 0;
	char line[100];

	while (file.getline(line, 100))
	{
		stack[count] = Check(line);
		count++;
	}

	return count;
}

void Checkbook::balance()
{
	cout << currentBalance << endl;
} 

double Checkbook::add_to_balance(double tempBalance, double depositAmount)
{
	double newBalance = tempBalance + depositAmount;
	return newBalance;
} 

double Checkbook::subtract_from_balance(double tempBalance, double checkAmount)
{
	double newBalance = tempBalance - checkAmount;
	return newBalance;
}

Rely on the balance you keep within the program. If you wanted to make your code fancier, you could have an option to load the last balance from the register, but I wouldn't worry about that.

For your add_to_balance and subtract_from_balance you want to be operating on the currentBalance variable directly rather than passing it in as a copy. Remember, this currentBalance is a member of your class, it is within the checkbook object. So, add_to_balance shouldn't return anything. Instead you add depositAmount to currentBalance and move on (this way what you have on line 178 will work). I'm not sure what the assignment calls for, but you could also write the transaction to the file at that point.

So I think I'm almost there, its just now i need to try and figure out how to extract a certain part from my text file which would be the amount field, add them all up and set that number to balance whenever the balance function is called. so every time we start a new program or new task it updates the balance. Also, my add and subtract functions seem to work. but if i were to just command the program to display balance itll be 0. if i do a deposit first then print out the balance, the amount from the deposit becomes the balance so i think im pretty close.

Checkbook.h

#ifndef _CHECKBOOK_H_
#define _CHECKBOOK_H_

#define _CRT_SECURE_NO_WARNINGS

#include <iostream>
#include <fstream>
#include <stdlib.h>
#include "Check.h"
using namespace std;

class Checkbook
{
	private:
		double currentBalance;
		fstream	file;

	public:
			
		Checkbook() : currentBalance(0.0)	// constructor opens the file
			{
				// input and output stream
				file.open("Checkbook.txt", ios::in | ios::out | ios::app);
				if (!file.good())
				{
					cerr << "ERROR: unable to open \"Checkbook.txt\"\n";
					exit(1);
				}

			}

			~Checkbook()	// destructor flushes and closes the file
			{
				file.flush();
				file.close();
			}

		char menu();
		void interactive();
		int read(Check stack[]);
		void list();
		void print(Check* entry) { entry->printCheck(); }

		void newDeposit();
		void newDeposit(char* deposit, char* date, char* recipient, char* amount);

		void newCheck();
		void newCheck(char* checkNo, char* date, char* recipient, char* amount);

		void balance();
		void add_to_balance(double depositAmount);
		void subtract_from_balance(double checkAmount);
};

#endif

Check.h

#ifndef _CHECK_
#define _CHECK_

#include <iostream>
#include <iomanip>
#include <string>
using namespace std;

enum sizes { FIELD = 20, DATE = 20, RECIPIENT = 50, AMOUNT = 50  };	// the sizes of card fields

class Check
{
	private:
			char checkNo[FIELD];
			char date[DATE];
			char recipient[RECIPIENT];
			char amount[AMOUNT];

	public:
			Check()
			{
				checkNo[0] = '\0';
				date[0] = '\0';
				recipient[0] = '\0';
				amount[0] = '\0';
			}

			Check(char* c, char* d, char* r, char* a)
			{
				strcpy_s(checkNo, c);
				strcpy_s(date, d);
				strcpy_s(recipient, r);
				strcpy_s(amount, a);
			}

			Check(char* line)
			{
				strcpy_s(checkNo, strtok(line, ":"));
				strcpy_s(date, strtok(NULL, ":"));
				strcpy_s(recipient, strtok(NULL, ":"));
				strcpy_s(amount, strtok(NULL, ":"));
			}

			void printCheck()
			{
				cout << checkNo << ": " << date << ": " << recipient << ": " << amount << endl << endl;
			}
};

#endif

Checkbook.cpp

#define _CRT_SECURE_NO_WARNINGS

#include <iostream>
#include <fstream>
#include <cstring>
#include <strstream>	
#include "Checkbook.h"
#include "Check.h"
using namespace std;

int main(int argc, char* argv[])
{
	Checkbook checkbook;

	if (argc == 1)						
		checkbook.interactive();

	else if (argc == 2 && !strcmp(argv[1], "-l"))
		checkbook.list();

	else if (argc == 5 && strcmp(argv[1], "Deposit"))
		checkbook.newDeposit(argv[1], argv[2], argv[3], argv[4]);

	else if (argc == 5)
		checkbook.newCheck(argv[1], argv[2], argv[3], argv[4]);	

	else
		cerr << "USAGE: Checkbook | Checkbook -1 | Checkbook deposit <date> <amount> | Checkbook <checkNo> <date> <recipient> <amount> \n";

	return 0;
} 

char Checkbook::menu()
{
	system("cls");

	cout << "C\t Create a new check \n";
	cout << "D\t Enter a new deposit \n";
	cout << "L\t List all current entries \n";
	cout << "B\t Balance checkbook \n";
	cout << "Q\t Quit \n";

	cout << "\n\nCommand: ";

	char command;
	cin >> command;
	cin.ignore();						// discard the new line

	return command;
}

void Checkbook::interactive()
{
	while (true)
	{
		char operation = menu();

		switch (operation)
		{
			case 'c' :				// search
			case 'C' :
				newCheck();
				system("pause");
				break;

			case 'd' :				// search
			case 'D' :
				newDeposit();
				system("pause");
				break;

			case 'l' :				// enter
			case 'L' :
				list();
				system("pause");
				break;

			case 'b' :				// list
			case 'B' :
				balance();
				system("pause");
				break;

			case 'q' :				// quit
			case 'Q' :
				exit(0);

			default:
				cerr << "Unknown option: " << operation << endl;
				break;
		}

	}

}

void Checkbook::newDeposit()
{
	char date[DATE];
	char amount[AMOUNT];

	cout << "Please enter date the check was written: ";
		cin.getline(date, DATE);

	cout << "Please enter the amount: ";
		cin.getline(amount, AMOUNT);

	newDeposit("Deposit", date, "-", amount);
}

void Checkbook::newDeposit(char* deposit, char* date, char* recipient, char* amount)
{
	file.clear();						
	file.seekp(0, ios::end);				

	istrstream n1(amount);
	double temp;
	n1 >> temp;

	add_to_balance(temp);

	file << deposit << " : " << date << " : " << recipient << " : " << amount << endl;

	file.flush();
}

void Checkbook::newCheck()
{
	char checkNo[FIELD];
	char date[DATE];
	char recipient[RECIPIENT];
	char amount[AMOUNT];

	cout << "Please enter the check number: ";
		cin.getline(checkNo, FIELD);

	cout << "Please enter date the check was written: ";
		cin.getline(date, DATE);

	cout << "Please enter the recipient: ";
		cin.getline(recipient, RECIPIENT);

	cout << "Please enter the amount: ";
		cin.getline(amount, AMOUNT);

	newCheck(checkNo, date, recipient, amount);
}

void Checkbook::newCheck(char* checkNo, char* date, char* recipient, char* amount)
{
	file.clear();						
	file.seekp(0, ios::end);	
	
	istrstream n1(amount);
	double temp;
	n1 >> temp;

	subtract_from_balance(temp);

	file << checkNo << " : " << date << " : " << recipient << " : " << amount << endl;

	file.flush();
}

void Checkbook::list()
{
	Check list[100];
	int	count = read(list);

	for (int i = 0; i < count; i++)
		print(&list[i]);
}

int Checkbook::read(Check stack[])
{
	file.clear();			
	file.seekg(0);						

	int	count = 0;
	char line[100];

	while (file.getline(line, 100))
	{
		stack[count] = Check(line);
		count++;
	}

	return count;
}

void Checkbook::balance()
{
	const int MAX = 50;

	char amountField[MAX];
	char currentBalance[MAX];

	while (!file.eof())
	{
		file.getline(amountField, MAX, ':');
		file.getline(currentBalance, MAX, '\n');
		cout << currentBalance << endl;
	}

	file.flush();
}

void Checkbook::add_to_balance(double depositAmount)
{
	currentBalance += depositAmount;
} 

void Checkbook::subtract_from_balance(double checkAmount)
{
	currentBalance -= checkAmount;
}

Edited 5 Years Ago by rebellion346: n/a

This article has been dead for over six months. Start a new discussion instead.