Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

I have been working on this project and have run into a roadblock. I purposely d

ID: 3569559 • Letter: I

Question

I have been working on this project and have run into a roadblock. I purposely did not post my code so hopefully someone can help without it, I am able to get my program to ask for the input file and output file and the interest rate. Then it prints the correct output for Jim and Bob's current account status but it will not print Sally's current status?? Then it prints New Account status and the headers but no names or account information???

Can someone give some tips on what I may be doing wrong to cause this to happen? Thank you.

Develop code to perform the daily account maintenance duties at Bank.com. Every
morning they want to examine the active accounts and either (a) give them interest on their savings or
(b) charge them interest on their credit.

Contents of a1.txt are as follows:

Jim 23.40 0

Bob 58.32 0

Sally -1.34 0

Below is code:

#include
#include
#include
#include

// Function prototypes
//[BEGIN MAIN]
int main()
{
std::string inputFileName;
std::string outputFileName;
double interestRate;

std::cout << "Enter an input filename: ";
std::cin >> inputFileName;
std::cout << "Enter an output filename: ";
std::cin >> outputFileName;
std::cout << "Enter an interest rate (%): ";
std::cin >> interestRate;

std::cout << std::endl;
std::ifstream ifile = GetInputFile(inputFileName);
std::ofstream ofile = GetOutputFile(outputFileName);

std::cout << "Current account status:" << std::endl;
PrintFileContents(ifile);

ProcessAccounts(ifile, ofile, interestRate);

ifile.close();
ofile.close();

std::cout << std::endl;
std::cout << "New account status:" << std::endl;
ifile = GetInputFile(outputFileName);

PrintFileContents(ifile);

ifile.close();

std::cout << "Press ENTER";
std::cin.ignore();
std::cin.get();
return 0;
}
//[END MAIN]

void ProcessAccounts(std::ifstream &ifile, std::ofstream& ofile, double rate)
{
// Every day the bank checks the status of the accounts and processes them
// If the customer has:
// 1) a positive savings balance, pay them interest
// 2) a negative savings balance, transfer it to credit (credit is positive)
// 3) a credit balance, charge them interest
// Note: Unlike normal banks, the interest rate for savings and credit is the same

// Read the info from the input file
// Put the new info into the output file
// The format for the input file and output file should be
// [NAME] [SAVINGS BALANCE] [CREDIT BALANCE]
// There is a single space between each value and a newline at the end

// Put your code here
}

void PrintFileContents(std::ifstream &str)
{
// Print the contents of the file
// First, print the file headers
// Then, print each line.
// Make sure the text is properly formatted
// Remember the functions available in iomanip?

// EXAMPLE:
// Name Savings Credit
// Bob $23.56 $0.00
// Joe $43.52 $0.00
// Sally -$1.58 $0.00

// Put your code here
}

std::ifstream GetInputFile(std::string filename)
{
// Open the file named filename
// Make sure it exists
// Return it as an input file stream
  
// Put your code here
}

std::ofstream GetOutputFile(std::string filename)
{
// Open the file named filename
// Make sure it exists
// Return it as an output file stream
  
// Put your code here
}

void SetInputStreamPos(std::ifstream &str, int pos)
{
// Set the 'g'et cursor to the desired byte in the stream
// Use the beginning of the file as the reference point
  
// Put your code here

std::ifstream ifile;
   ifile.open(filename);
return ifile;
}

void SetOutputStreamPos(std::ofstream &str, int pos)
{
// Set the 'p'ut cursor to the desired byte in the stream
// Use the beginning of the file as the reference point
  
// Put your code here
}

Output should read:

Enter an input filename: a1.txt

Enter an output filename: a2.txt

Enter an interest rate (%): 25

Current account status:

Name               Savings           Credit

Jim                      $23.40               $0.00

Bob                      $58.32               $0.00

Sally                   -$1.34                 $0.00

New account status:

Name                     Savings             Credit

Jim                        $29.25                   $0.00

Bob                        $72.90                  $0.00

Sally                       $0.00                    $1.68

Press ENTER

Explanation / Answer

You may possibly need to set the file to the beginning before searching through the file with your loops. Try using ifile.seekg(0);

Maybe that will hlep

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote