Answer to Question #210244 in C++ for steve

Question #210244

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


1
Expert's answer
2021-06-24T03:35:49-0400
#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;
}

file-:

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

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

No comments. Be the first!

Leave a comment

LATEST TUTORIALS
New on Blog
APPROVED BY CLIENTS