1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62
|
#include<iostream>
#include<cstdlib>
#include<iomanip>
#include<fstream>
#include<string>
using namespace std;
ifstream in_stream;
ofstream out_stream;
char infilename[21], outfilename[21];
int main()
{
cout <<"Please enter the input file name including the extension (i.e. .txt,.exe)\n";
cout <<"(1 - 20 characters):";
cin >>infilename;
cout <<"Thank you, you entered "<<infilename<<endl;
cout <<"Please enter the output file name including the extension (i.e. .txt,.exe)\n";
cout <<"(1-20 characters):";
cin >>outfilename;
cout <<"Thank you, I will now write to " <<outfilename<<endl;
in_stream.open(infilename);
if (in_stream.fail( ))
{
cout << "Input file opening failed.\n";
exit(1);
}
out_stream.open(outfilename);
if (out_stream.fail( ))
{
cout << "Output file opening failed.\n";
exit(1);
}
writesales();
in_stream.close();
out_stream.close();
return 0;
}
|
That Is the code that I have written so far, But it is still in progress. I am supposed to open a file (i will include the file info in a moment) and take the data and calculate the data and return it into an outfile. The thing that i am not sure on how to do is to read a line from the file and to calculate it, not to calculate the whole thing. So i dont know if it would be an array or what.
If anyone has any ideas on how to take one line from the file and then do the calculation and put it in the outfile i would really appreciate it.
the file that i have to read the info from looks like this :
4 3 // number of people, then weeks
lastName1 firstName1 1234.4 546.9 541.9 7654.7 876.98
lastname2 firstName2 987.6 874.9 234.7 85.5 1965.4
lastName3 firstName3 24.4 547.9 54.9 764.7 6543.5
lastname4 firstName4 97.6 874.9 234.7 865.5 345.6
lastName1 firstName1 34.4 5416.9 1541.9 154.7 816.98
lastname2 firstName2 97.6 8174.9 14.7 85.5 165.4
lastName3 firstName3 2314.4 76.9 54.9 74.7 643.5
lastname4 firstName4 974.6 844.9 234.7 825.5 145.6
lastName1 firstName1 14.4 56.9 5441.9 7454.7 76.98
lastname2 firstName2 987.6 87654.9 1234.7 8765.5 965.4
lastName3 firstName3 24.4 546.9 544.9 765.7 653.5
lastname4 firstName4 977.6 74.9 534.7 85.5 45.6
the calculations is to calculate
The number of sales persons and weeks that were processed
Total and average sales for each salesperson for each period
Total sales and average sales for each salesperson over all periods
Grand total sales and average sales for all persons for all periods
please help!