Answer to Question #204509 in C++ for shahil

Question #204509

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, which contains a list of Annual (Gross) income records of employees in a firm, and produce various reports as outlined. Input File: The input file called IncomeRec.txt contains a list of Annual (Gross) income records of employees in a firm. You will assume that this firm contains at most 200 active 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 - cha 


1
Expert's answer
2021-06-08T09:32:50-0400
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


C++ code:


#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;
}




Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

Hans
25.06.21, 14:14

i have run the programm but there are issues with it so kindly ask if you could rewrite the program so it works please

Leave a comment

LATEST TUTORIALS
New on Blog