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 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92
|
#include <iostream>
#include <cstdlib>
#include <string>
#include <vector>
#include <fstream>
using namespace std;
void load_data(vector <int>& ID, vector <string>& Name, vector <double>& salary);
void print_data(vector <int> ID, vector <string> Name, vector <double> salary);
int main()
{
string file_name;
vector <int> ID;
vector <string> name;
vector <double> salary;
load_data(ID, name, salary);
print_data(ID, name, salary);
return EXIT_SUCCESS;
}
void load_data(vector <int>& ID, vector <string>& Name, vector <double>& salary)
{
ifstream inputfile;
int input_numbers = 0;
string input_strings;
string file_name;
cout << "\nPlease enter the name of the file containing your employeer data: ";
cin >> file_name;
inputfile.open(file_name);
if (inputfile.fail())
{
cout << "\nFile failed to open. Please re-enter the file name: ";
load_data(ID, Name, salary);
}
while(inputfile >> input_numbers)
{
if(input_numbers < 10000)
{
ID.push_back(input_numbers);
}
}
inputfile.clear();
inputfile.seekg(0, ios::beg);
while(inputfile >> input_strings)
{
Name.push_back(input_strings);
}
inputfile.clear();
inputfile.seekg(0, ios::beg);
while(inputfile >> input_numbers)
{
if(input_numbers >= 10000)
{
salary.push_back(input_numbers);
}
}
inputfile.clear();
inputfile.seekg(0, ios::beg);
inputfile.close();
}
void print_data(vector <int> ID, vector <string> Name, vector <double> salary)
{
cout << "ID Name Salary \n";
cout <<"____________________________________\n"; // this function isn't
for( int loop : ID) // finished yet
{
cout << loop << " ";
}
}
|