Due to upcoming end of financial year, you are being called in to write a program which will read in an input file called IncomeRec.txt, whichcontains a list of Annual(Gross)incomerecordsof employees in a firm,and produce various reports as outlined and You must read this input file(IncomeRec.txt)and store the records ofgrossincomesinto appropriate arrays. 2.Your program should then be able to process the following commands. i.e. programshould provide user with the following menu.▪1. Print the entire list.▪2. Print list sorted byGross income.▪3. Print list ofemployees which match a given lastname initial▪4. Calculate:a)the Taxcorresponding to the provided grossincomeof each employeeusing Table 1;and b)the Net Incomeand c)Print in a filecalled IncomeTax.txtwhere the tax and Net income are displayed in separatecolumns.[NB. The tax is calculatedaccording to the Tax Calculation Table provided and the Net Income =Gross income–Tax]▪5. Exit program
IncomeRec.txt file:
Lastname(initial) FNPF# Age Gross_Incowe Resident
F 12345 24 40000 Y
B 12361 19 20000 Y
H 34763 47 100000 N
H 11224 50 35000 Y
R 54129 35 75000 N
B 10717 26 28000 Y
code-:
#include <iostream>
#include <fstream>
#include <sstream>
#include <string>
using namespace std;
class Employee{
private:
char lastname;
int FNPF;
int age;
int gross_Income;
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;
const string FILE_NAME="IncomeRec.txt";
ifstream ifstreamIncomeRecFile;
ifstreamIncomeRecFile.open(FILE_NAME);
if(ifstreamIncomeRecFile){
char lastname;
int FNPF;
int age;
int gross_Income;
char resident;
string line;
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();
}
}
ifstreamIncomeRecFile.close();
system("pause");
return 0;
}
Comments
Leave a comment