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 93 94 95 96 97 98 99 100 101 102 103
|
#include <iostream>
#include <string>
#include <fstream>
#include <sstream>
using namespace std;
const int MAX = 24;
struct applicant_info
{
string job_title, company_name, web_site, email_address, location, phone_number;
int salary, desirability;
};
typedef applicant_info info_array[24];
info_array info;
void read_file(fstream &open_file, applicant_info info_array[MAX], int& num);
void print_info(applicant_info info_array[MAX], int& num);
int main()
{
fstream open_file;
string junk, file_name;
int num = 0;
cout << "What is the name of the file you would like to open?" << endl;
cin >> file_name;
open_file.open(file_name, ios::in);
if (open_file.fail())
{
cout << "Failed to open " << file_name << " input file." << endl;
getline(cin, junk);
exit(1);
}
read_file(open_file, info, num);
print_info(info, num);
open_file.close();
return 0;
}
void print_info(applicant_info info_array[MAX], int& num)
{
for (int a = 0; a < num; a++)
{
cout << "Company Name: " << info_array[a].company_name << endl;
cout << "Job Title: " << info_array[a].job_title << endl;
cout << "Salary: " << info_array[a].salary << endl;
cout << "Location: " << info_array[a].location << endl;
cout << "Phone Number: " << info_array[a].phone_number << endl;
cout << "Email Address: " << info_array[a].email_address << endl;
cout << "Web Site: " << info_array[a].web_site << endl;
cout << "What is the desirability of this applicant? (pick a number such as 1-5)" << endl;
cin >> info_array[a].desirability;
}
}
void read_file(fstream &open_file, applicant_info info_array[24], int& num)
{
int num_of_lines = 0;
num = 0;
string info_line;
string salary1, job_title1, company_name1, web_site1, email_address1, location1, phone_number1;
int desirability1;
while (open_file)
{
getline(open_file, company_name1, ',');
getline(open_file, job_title1, ',');
getline(open_file, salary1, ',');
getline(open_file, location1, ',');
getline(open_file, phone_number1, ',');
getline(open_file, email_address1, ',');
getline(open_file, web_site1, ',');
desirability1 = 0;
info_array[num_of_lines].company_name = company_name1;
info_array[num_of_lines].job_title = job_title1;
istringstream (salary1) >> info_array[num_of_lines].salary;
info_array[num_of_lines].location = location1;
info_array[num_of_lines].phone_number = phone_number1;
info_array[num_of_lines].email_address = email_address1;
info_array[num_of_lines].web_site = web_site1;
info_array[num_of_lines].desirability = desirability1;
}
num_of_lines++;
num++;
if (num_of_lines == MAX)
{
cout << "You have reached the maximum limit for the number of applicants you can have, being 24." << endl
<< "If you wish to see more information you must edit your text document." << endl
<< "Any information beyond line 24 will not be read into the program. " << endl;
}
}
|