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 63 64 65 66 67 68 69 70 71 72 73 74
|
#include <iostream>
#include <string>
#include <fstream>
using namespace std;
struct employees { int id; string lname; double qtrSale[4]; double tsale; };
void getIdName(employees list[], ifstream& infile, int num);
void getData(employees list[], ifstream& infile, int num);
const int lsize = 3;
int main()
{
ifstream infile;
string file("file1.txt");
infile.open(file);
employees list[lsize];
//getting first & last name
getIdName(list, infile, lsize);
infile.close();
infile.open(file);
//getting quarter sale
getData(list, infile, lsize);
infile.close();
for(int i = 0; i < lsize; i++)//checking struct
{
cout << list[i].id << " " << list[i].lname << endl;
for(int j = 0; j < 4; j++)
{
cout << list[i].qtrSale[j] << " | ";
}
cout << "\n";
}
system("pause");
return 0;
}
void getIdName(employees list[], ifstream& infile, int lsize)
{
double sale, qtr;
for(int i = 0; i < lsize; i++)
{
infile >> list[i].id >> list[i].lname >> qtr >> sale;
for(int j = 0; j < 4; j++)
{
list[i].qtrSale[j] = 0.0; //cero out the quarters
}
}
}
void getData(employees list[], ifstream& infile, int lsize)
{
int id, qtr, j = 0, i = 0;
string name;
double amount;
for(int t = 0; t < 12; t++)
{
infile >> id >> name >> qtr >> amount;
if(list[j].id == id && qtr == 1) { i = 0; list[j].qtrSale[i] = amount; }
if(list[j].id == id && qtr == 2) { i = 1; list[j].qtrSale[i] = amount; }
if(list[j].id == id && qtr == 3) { i = 2; list[j].qtrSale[i] = amount; }
if(list[j].id == id && qtr == 4) { i = 3; list[j].qtrSale[i] = amount; }
if( t < 3 ) { j = 0; }
if( t > 2 && t < 6 ) { j = 1; }
if( t > 5 && t < 9 ) { j = 2; }
}
}
|