Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Processes data from an input file. The first line of the input file should conta

ID: 3798339 • Letter: P

Question

Processes data from an input file. The first line of the input file should contain exactly one character. The character should be printable, but not alphanumeric This character will be used in your program as a separator. Each section separator should be 60 characters long The input file should contain three entries containing: First Name and Last Name, separated by white space 4 salary entries in chronological (not necessarily ascending value) order Accepts the full path to a file on the computer as input. Use a separator before printing the next section. For each entry Print the person's last name and first name. Print the current salary to 2 decimal places. Print the average raise received to 2 decimal places. Print the average rate of salary increase as a percentage to 4 decimal places. Rate of salary increase (%) = (currentSalary = previoussalary/previousSalary Find all three of these and compute the geometric average. Print another separator, then: Print the average (current) salary for all of the people in the input file. Print the average rate of salary increase for all.

Explanation / Answer

C++ code:

#include <bits/stdc++.h>
using namespace std;

int main()
{
   cout << "Please enter filename" << endl;
   string filename;
   cin >> filename;
   string line, separator;
   ifstream myfile (filename.c_str());
   std::vector< vector<float> > data;
   std::vector<string> fnames;
   std::vector<string> lnames;
   if (myfile.is_open())
   {
   getline (myfile,separator);
   while ( getline (myfile,line) )
   {
   string buf; // Have a buffer string
   stringstream ss(line); // Insert the string into a stream
   vector<string> tokens; // Create vector to hold our words
   while (ss >> buf)
   tokens.push_back(buf);
   fnames.push_back(tokens[0]);
   lnames.push_back(tokens[1]);
   std::vector<float> salary;
   salary.push_back(atof(tokens[2].c_str())); salary.push_back(atof(tokens[3].c_str()));
   salary.push_back(atof(tokens[4].c_str())); salary.push_back(atof(tokens[5].c_str()));
   data.push_back(salary);
   }
   float av_salary_for_all = 0;
   float av_rate_of_salary_increase_for_all = 0;
   for (int i = 0; i < fnames.size(); ++i)
   {
       float averagerais = ((data[i][1] - data[i][0]) + (data[i][2] - data[i][1]) + (data[i][3] - data[i][2]) )/ 3.0;
       float average_rais_percentage = ((data[i][1] - data[i][0])/(data[i][0]) + (data[i][2] - data[i][1])/(data[i][1]) + (data[i][3] - data[i][2])/(data[i][2]) )/3.0*100.0;
       cout << fnames[i] << " " << lnames[i] << " "<< separator << " ";
       cout << "Current salary " << (data[i][3])*100.0/100.0 << "" << separator << " ";
       cout << "Average raise " << averagerais*100.0/100.0 << " " << separator << " ";
       cout << "Average raise percentage " << average_rais_percentage << endl;
       av_salary_for_all = av_salary_for_all + data[i][3];
       av_rate_of_salary_increase_for_all = av_rate_of_salary_increase_for_all + average_rais_percentage;
   }
   cout << " Average(Current) salary For All entris = " << av_salary_for_all/data.size();
   cout << " Average rate of salary increase for all = " << av_rate_of_salary_increase_for_all/data.size() << endl;
   myfile.close();
   }
   else
   {
   cout << "Unable to open file" << endl;
   exit(1);
   }          
   return 0;
}

Input.txt:

:
akash baviskar 1000 2000 3000 4000
sagar baviskar 1000 2000 3000 4000

Sample Output:

Please enter filename
input.txt
akash baviskar : Current salary 4000: Average raise 1000 : Average raise percentage 61.1111
sagar baviskar : Current salary 4000: Average raise 1000 : Average raise percentage 61.1111
Average(Current) salary For All entris = 4000 Average rate of salary increase for all = 61.1111

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote