So I've been working on an assignment for a class, and I was receiving help from a grad student and he said my program looked good and to turn it in. However, the auto-evaluate program did not work with my code and it would not compile. Anyone have suggestions?
#include <iostream>
#include <fstream>
#include <string>
#include <iomanip>
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)
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
//printing contents of file
std::string name;
double savingsbalance;
double creditbalance;
std::cout <<"Name\tSavings\tCredit" << std::endl;
str >> name >> savingsbalance >> creditbalance;
while(!str.eof())
{
std::cout << std::setprecision(2) << std::fixed << name << "\t$" << savingsbalance <<"\t$"<< creditbalance << std::endl;
str >> name >> savingsbalance >> creditbalance;
}
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::ifstream ifile;
ifile.open(filename); //open file
if(!ifile.is_open())
{
ifile.close(); //determine if file can open
}
else;
{
std::cout <<"Error. Unable to open file " << std::endl;
}
return ifile; //showing error if unable
// 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
std::ofstream ofile;
ofile.open(filename); //open file
//determine if file can open
if(!ofile.is_open())
{
ofile.close();
}
else
{
std::cout <<"Error. Unable to open file" << std::endl; //error message
}
return ofile;
// 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
str.clear();
str.seekg(pos, std::ios::beg);
}
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
str.clear();
str.seekp(pos, std::ios::beg);
}