Answer to Question #209564 in C++ for fijian fala

Question #209564

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. 

1. You must read this input file (IncomeRec.txt) and store the records of gross incomes into appropriate arrays.

2. Your program should then be able to process the following commands. i.e. program should provide user with the following menu.

▪ 1. Print the entire list.

▪ 2. Print list sorted by Gross income.

▪ 3. Print list of employees which match a given lastname initial

▪ 4. Calculate: a) the Tax corresponding to the provided gross income of each employee using Table 1; and b) the Net Income and c) Print in a file called IncomeTax.txt where the tax and Net income are displayed in separate columns.

[NB. The tax is calculated according to the Tax Calculation Table provided and the Net Income = Gross income – Tax]

▪ 5. Exit program


1
Expert's answer
2021-06-22T07:25:30-0400
#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

No comments. Be the first!

Leave a comment

LATEST TUTORIALS
New on Blog
APPROVED BY CLIENTS