samedi 22 juillet 2017

How do you take information from one file, perform calculations, then add that information to a new file?

I'm looking to get information from a file called cars.txt, gather details of used and new cars, combining relative information, and displaying that information in both the console and a new .txt file. I have not found anything online to help me figure this out and my book uses a not-so-similar example.

I need to use this information (cars.txt):

1999 Ford Ranger 3000 156000 used
2000 Mazda Miata 4000 98000 used
2015 Jeep Wrangler 33000 250 new

This information will help me gather details to later create some output keeping track of how many used/new cars and combined mileage and price.

This is the output to the terminal (and file) I need:

Category| Number| Total Price| Total Mileage|
     New|      1|       33000|           250|
    Used|      2|        7000|        254000|

Using this code:

// Function prototype
void AnalyzeFile(std::istream & fin,
    int & numUsed,
    int & numNew,
    double & newTotalPrice,
    double & newTotalMileage,
    double & usedTotalPrice,
    double & usedTotalMileage);




  int main()
{
double newTotalPrice = 0;
double newTotalMileage = 0;
double usedTotalPrice = 0;
double usedTotalMileage = 0;
int numUsed = 0;
int numNew = 0;
std::ifstream fin; // 'f'ile in - fin
std::string filename = "cars.txt";
bool isOpen = GetInputFileStream(&fin, filename);
std::ofstream fout;
GetOutputFileStream(&fout, "output.txt");
std::cout << filename << " open: ";
std::cout << std::boolalpha << isOpen << std::endl;
AnalyzeFile(fin,
 numUsed,
 numNew,
 newTotalPrice,
 newTotalMileage,
 usedTotalPrice,
 usedTotalMileage);
PrintStatistics(std::cout,
 numUsed,
 numNew,]
 newTotalPrice,
 newTotalMileage,
 usedTotalPrice,
 usedTotalMileage);
}



// Function definition
void AnalyzeFile(std::istream & fin,
    int & numUsed,
    int & numNew,
    double & newTotalPrice,
    double & newTotalMileage,
    double & usedTotalPrice,
    double & usedTotalMileage)
{
    //logic here should calculate data from cars.txt
}

Aucun commentaire:

Enregistrer un commentaire