I am not sure why my program isn't writing to the text file.
When I start the program it tells me that the file opens. Then I call the functions that are inherited from other classes and I would assume that it would write to the file and then display them. I was able to get this to work earlier without using the insertion and extraction operators, but I wanted to get it to work with them as well. Does anyone have any ideas?
//A Class for a checking account with a set interest.
class CheckingWithInterest
: public SavingsAccount, public CheckingAccount
{
friend ostream& operator<<(ostream& bank_Info_Out, const CheckingWithInterest& wIAcct);
friend istream& operator>>(istream& bank_Info_In, const CheckingWithInterest& wIAcct);
public:
CheckingWithInterest();
void displayWithInterest();
};
//Default constructor for the special accounts
CheckingWithInterest::CheckingWithInterest()
: CheckingAccount(0, 0, 9999, 0), SavingsAccount(0.02)
{
}
// Displays the accounts information
void CheckingWithInterest::displayWithInterest()
{
BankAccount::displayAccounts();
SavingsAccount::displaySavAccount();
CheckingAccount::displayCAccount();
}
//Displays interest rates on the accounts.
ostream& operator<<(ostream& bank_Info_Out, CheckingWithInterest& wIAcct)
{
bank_Info_Out << setprecision(2);
ofstream myfile;
myfile.open("Account_Data.txt");
if (!myfile.good())
cout << "File couldn't be OPENED!!" << endl;
else
{
cout << "File OPENED!!" << endl;
wIAcct.displayWithInterest();
}
myfile.close();
return bank_Info_Out;
}
//Operator that takes in accounts with an interest in the checking account.
istream& operator>>(istream& bank_Info_In, CheckingWithInterest& wIAcct)
{
ifstream myfile;
myfile.open("Account_Data.txt", ios::in);
if (!myfile.good())
cout << "File couldn't be OPENED!!" << endl;
else
{
cout << "File OPENED!!" << endl;
wIAcct.enterAccountData();
wIAcct.getSavInfo();
wIAcct.getCheckInfo();
}
myfile.close();
return bank_Info_In;
}
/*Main function that makes and displays any number of accounts
it is currently set to a Maximum of 4 accounts for ease of logic
error checking. Change the number to make more bank accounts*/
int main()
{
cout << fixed << setprecision(2);
int x = 0;
const int ERROR = 0;
const int MAX_ACCTS = 2;
//Makes an array of bank account objects
CheckingWithInterest checkIntAccts[MAX_ACCTS];
while (x < MAX_ACCTS)
{
cin >> checkIntAccts[x];
x++;
}
for (x = 0; x < MAX_ACCTS; x++)
{
cout << checkIntAccts[x] << endl;
}
system("pause");
return 0;
}