write a program that reads input file called IncomeRec.txt, The input file contains a list of Annual (Gross) income records of employees with at most 200 staff. Each record is on a single line and the fields are separated by a single space. The names of the fields are: • Employee Lastname (initial) char
• FNPF# - integer
• Age - integer
• Gross_Income - integer
• Resident - char
Requirements
1. Print the entire list. by typing 1 and should print the contents of the file on the screen. (fileds output are: lastname initial, FNPF#, age, Gross_Income and Resident)
2. Print list sorted by Gross Income by typing 2. Program prints the list in ascending order of Gross Income. ( fields output are: FNPF# and Gross_Income)
3. Print list of employees which match a given lastname initial typing 3. the user is asked to enter the search initial. if no person have last names matching the search initial “no matching record found” is displayed. to display in output are: lastname and FNPF#
#include <iostream>
#include <fstream>
#include <sstream>
#include <string>
using namespace std;
class Employee{
private:
//Employee Lastname (initial) - char
char lastname;
//FNPF# - integer
int FNPF;
//Age - integer
int age;
//Gross_Income - integer
int gross_Income;
//Resident - char
char resident;
public:
Employee(){}
Employee(char lastname,int FNPF,int age,int gross_Income,char resident){
this->lastname=lastname;
this->FNPF=FNPF;
this->age=age;
this->gross_Income=gross_Income;
this->resident=resident;
}
char getLastname(){
return this->lastname;
}
int getFNPF(){
return this->FNPF;
}
int getAge(){
return this->age;
}
int getGrossIncome(){
return this->gross_Income;
}
char getResident(){
return this->resident;
}
void displayInfo(){
cout<<this->lastname<<"\t\t"<<this->FNPF<<"\t\t"<<this->age<<"\t\t"<<this->gross_Income<<"\t\t\t"<<this->resident<<"\n";
}
};
int main (){
Employee employees[200];
int totalEmployees=0;
//The file name
const string FILE_NAME="IncomeRec.txt";
//Open the file
ifstream ifstreamIncomeRecFile;
ifstreamIncomeRecFile.open(FILE_NAME);
if(ifstreamIncomeRecFile){
//Employee Lastname (initial) - char
char lastname;
//FNPF# - integer
int FNPF;
//Age - integer
int age;
//Gross_Income - integer
int gross_Income;
//Resident - char
char resident;
string line;
//read the first line of the file
getline(ifstreamIncomeRecFile,line);
while (!ifstreamIncomeRecFile.eof()){
ifstreamIncomeRecFile>>lastname>>FNPF>>age>>gross_Income>>resident;
employees[totalEmployees]=Employee(lastname,FNPF,age,gross_Income, resident);
totalEmployees++;
}
}else{
cout<<"\nThe file does not exist.\n\n";
}
if(totalEmployees>0){
cout<<"Last N\t\tFNPF\t\tAge\t\tGross Income\t\tResident\n";
for(int i=0;i<totalEmployees;i++){
employees[i].displayInfo();
}
}
//close files stream
ifstreamIncomeRecFile.close();
system("pause");
return 0;
}
Comments
Leave a comment