So I'm having problem with the output of this program. The program runs and compiles, except when I look at the output it gives me the default contructor for the seller array rather than reading in the data.
The current output is:
#include "Seller.h"
#include <iostream>
#include <iomanip>
using std::cout;
using std::string;
usingnamespace std;
//**********************************************************************************************
Seller::Seller() //default contructor
{
*name = '\0';
salesTotal = 0;
}
//**********************************************************************************************
Seller::Seller(char* newName, double newSalesTotal) //contructor that takes a character array containing a name and new sales total
{
strcpy (name, newName); //copies the new name into the name array
salesTotal = newSalesTotal; //copies the new sales total
}
//**********************************************************************************************
constchar* Seller::getName() //accessor that returns the name of the seller's name
{
return name;
}
//**********************************************************************************************
double Seller::getSalesTotal() //accessor that returns the total sales of the seller
{
return salesTotal;
}
//**********************************************************************************************
void Seller::setSalesTotal(double newSalesTotal) //accessor that takes the new sales total
{
salesTotal = newSalesTotal;
}
//**********************************************************************************************
void Seller::print() //prints the seller's name and sales total
{
cout <<left << setw(30) << name;
cout << right << setw (9) << salesTotal;
}
//**********************************************************************************************
I'm having trouble reading your program because the indentation style you use is so absurd. Could you at least point out where you think the problem is?
I think the problem occurs the file is being read into the program and somewhere along there the data from the file isn't being filtered into where it should be needed.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15
SalesDB::SalesDB (constchar* fileName)
{
ifstream inFile;
inFile.open (fileName, ios::binary);
if (!inFile)
{
cout << "Error - unable to open input file " << fileName << endl;
exit(1);
}
while (inFile)
{
inFile.read((char*) this, sizeof(SalesDB));
}
inFile.close();
}
I figure the problem might arising from section but not sure.
I did not know. This is the first time I've dealt with a binary file. I was told that I could use that command to read in the file into my SalesDB object.
Could you suggest any other method of writing the data in the binary file into an array? I've never really worked with binary files, only with regular text files.