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 by enter 5
#include <iostream>
#include <fstream>
#include <vector>
int main()
{
std::string line;
std::ifstream file ("IncomeRec.txt");
std::vector<std::string> list;
if (file.is_open()) {
while (getline(file, line)) {
list.push_back(line);
}
file.close();
} else {
std::cout << "Unable to open file" << std::endl;
return 1;
}
while (true) {
int x; std::cin >> x;
switch (x) {
case 1:
for (std::string l : list) {
std::cout << l << std::endl;
}
break;
case 2:
// service implementation
break;
case 3:
// service implementation
break;
case 4:
// service implementation
break;
case 5:
std::cout << "Exit system" << std::endl;
return 0;
default:
std::cout << "Oops..." << std::endl;
break;
}
}
}
Comments
Leave a comment