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

Giving thumbs up for helpful solution, no vectors allowed. Employee_Data.csv FIL

ID: 3745621 • Letter: G

Question

Giving thumbs up for helpful solution, no vectors allowed.

Employee_Data.csv FILE:

Employee file:

First Name,Last Name,Employee Rank,Salary

Ella,Moon,7,"$37,643"

Karleigh,Gross,2,"$53,293"

Irma,Garza,7,"$54,910"

Peter,Collins,1,"$59,497"

Erin,Weeks,5,"$73,832"

Wang,King,10,"$53,982"

Tucker,Lowery,7,"$69,740"

Cruz,Irwin,5,"$52,492"

Elvis,Fisher,9,"$69,442"

Wesley,Carr,4,"$79,795"

Tatum,Villarreal,2,"$36,856"

Austin,Mooney,10,"$41,352"

Kieran,Morgan,1,"$61,690"

Tamekah,Roy,8,"$45,495"

Tana,Rose,6,"$57,523"

Caesar,Berry,10,"$77,075"

Lee,Pickett,9,"$57,435"

Adena,Holt,6,"$44,542"

Quyn,Hanson,4,"$75,872"

Peter,Pratt,6,"$73,957"

Teagan,Mooney,5,"$57,907"

Hashim,Kent,3,"$64,725"

Quail,Guthrie,8,"$65,237"

Priscilla,Cantrell,8,"$39,540"

Marcia,Wilkerson,8,"$73,772"

Larissa,Franklin,6,"$78,973"

Elmo,Nash,2,"$60,257"

Jaden,Montoya,1,"$76,959"

Tatum,Morrison,2,"$48,052"

Kiona,Mcneil,5,"$46,114"

Berk,Stone,6,"$79,404"

Allistair,Torres,6,"$76,000"

Tarik,Bartlett,2,"$63,828"

Ursula,Pace,1,"$54,100"

Eden,Beck,6,"$48,311"

Graiden,Acosta,5,"$67,049"

Macey,Waters,5,"$78,543"

Norman,Walls,4,"$38,180"

Gay,Barton,9,"$48,946"

Lila,Guthrie,6,"$61,833"

Summer,Le,5,"$41,353"

Keith,Skinner,7,"$78,910"

Cleo,Shepherd,4,"$38,625"

Belle,Norman,4,"$60,012"

Roary,Henry,7,"$67,354"

Cara,Snider,2,"$44,653"

Bradley,Larson,2,"$51,060"

Chanda,Dawson,6,"$39,710"

Amal,Sharpe,6,"$47,221"

Dakota,Hendricks,2,"$66,947"

Miranda,Hays,9,"$78,687"

Ocean,Simon,5,"$76,586"

Seth,Green,4,"$77,435"

Bethany,Parsons,10,"$49,477"

Patience,Wade,8,"$52,147"

Xaviera,Graham,4,"$66,469"

Rhona,Garner,10,"$60,262"

Kevin,Holder,7,"$53,339"

Tate,Welch,10,"$48,841"

Ayanna,Atkinson,10,"$57,601"

Kai,Myers,4,"$58,992"

Molly,Ryan,5,"$78,606"

Louis,Giles,5,"$41,756"

Zia,Hartman,5,"$49,840"

Brynn,Zamora,8,"$40,594"

Aphrodite,Cotton,9,"$59,794"

Teagan,West,4,"$55,254"

Dawn,Decker,1,"$49,384"

Brock,Chavez,10,"$38,568"

Daquan,Weber,1,"$55,251"

Zorita,Collins,2,"$46,170"

Denise,Rich,7,"$70,031"

Abra,Brady,10,"$76,971"

Bruno,Roberts,10,"$66,619"

Nadine,Peterson,8,"$79,551"

Patrick,Farrell,7,"$77,322"

Mark,Pugh,3,"$39,238"

Jena,Blackburn,2,"$46,262"

Mechelle,Cook,1,"$48,148"

Keaton,Schmidt,1,"$39,698"

Marshall,Ruiz,1,"$57,573"

Emma,Glenn,2,"$60,534"

Maya,Serrano,6,"$77,199"

Naida,Pollard,3,"$55,229"

Kennedy,Merrill,1,"$78,400"

Celeste,Knowles,2,"$60,954"

Kevin,Houston,5,"$70,892"

Mechelle,Snow,9,"$53,897"

Sage,Tucker,3,"$64,155"

Amos,Dorsey,10,"$50,029"

Lee,Bright,5,"$66,279"

Quail,Price,10,"$42,063"

Shelley,Holder,8,"$45,720"

Dennis,Villarreal,7,"$54,218"

Keely,Cameron,6,"$64,053"

Carter,Daugherty,6,"$72,471"

TaShya,Norman,2,"$58,203"

Ainsley,Byers,2,"$79,631"

Dante,Stone,4,"$40,131"

Ashton,Coleman,2,"$42,692"

A data of 100 employees is provided. This data includes the first names, last names, ranks, and salary of the employees. Design and implement a C++ program that opens this file, gets the user's input, sorts the list and save it as a new file based on user's request. First, the user is asked to write down the name of the column they want to sort (exact column name), second, they provide their choice of descending order or ascending order. The ascending order can be chosen by typing 'DESC' and ascending order can be chosen by typing 'ASC Use at least one function inside your program for sorting functionality. Your program has to save the newly sorted file in a separate file called output.csv'. Hint: Use switch statement to process user's input. Consider using fstream, ifstream, ofstream for working with the input and output files. Arrays might be very helpful to store the data.

Explanation / Answer

Using Struct:

#include <iostream>

#include <fstream>

#include <vector>

#include <string.h>

#include <algorithm>

using namespace std;

#define pb push_back

#define mp make_pair

struct Emp{

string Fname,Lname,Rank,Salary;

};

int switch_case,switch_type;

//sort according to First Name

bool comp1(Emp a,Emp b)

{

if(a.Fname!=b.Fname)

{

if(switch_type==2)

return a.Fname > b.Fname;

else if(switch_type==1)

return a.Fname < b.Fname;

}

if(a.Lname!=b.Lname)

{

if(switch_type==2)

return a.Lname > b.Lname;

if(switch_type==1)

return a.Lname < b.Lname;

}

if(a.Rank!=b.Rank)

{

if(switch_type==2)

return a.Rank > b.Rank;

if(switch_type==1)

return a.Rank < b.Rank;

}

if(a.Salary!=b.Salary)

{

if(switch_type==2)

return a.Salary > b.Salary;

if(switch_type==1)

return a.Salary < b.Salary;

}

}

//sort according to Last name

bool comp2(Emp a,Emp b)

{

if(a.Lname!=b.Lname)

{

if(switch_type==2)

return a.Lname > b.Lname;

if(switch_type==1)

return a.Lname < b.Lname;

}

if(a.Fname!=b.Fname)

{

if(switch_type==2)

return a.Fname > b.Fname;

else if(switch_type==1)

return a.Fname < b.Fname;

}

if(a.Rank!=b.Rank)

{

if(switch_type==2)

return a.Rank > b.Rank;

if(switch_type==1)

return a.Rank < b.Rank;

}

if(a.Salary!=b.Salary)

{

if(switch_type==2)

return a.Salary > b.Salary;

if(switch_type==1)

return a.Salary < b.Salary;

}

}

//sort according to rank

bool comp3(Emp a,Emp b)

{

if(a.Rank!=b.Rank)

{

if(switch_type==2)

return a.Rank > b.Rank;

if(switch_type==1)

return a.Rank < b.Rank;

}

if(a.Fname!=b.Fname)

{

if(switch_type==2)

return a.Fname > b.Fname;

else if(switch_type==1)

return a.Fname < b.Fname;

}

if(a.Lname!=b.Lname)

{

if(switch_type==2)

return a.Lname > b.Lname;

if(switch_type==1)

return a.Lname < b.Lname;

}

if(a.Salary!=b.Salary)

{

if(switch_type==2)

return a.Salary > b.Salary;

if(switch_type==1)

return a.Salary < b.Salary;

}

}

//sort according to salary

bool comp4(Emp a,Emp b)

{

if(a.Salary!=b.Salary)

{

if(switch_type==2)

return a.Salary > b.Salary;

if(switch_type==1)

return a.Salary < b.Salary;

}

if(a.Fname!=b.Fname)

{

if(switch_type==2)

return a.Fname > b.Fname;

else if(switch_type==1)

return a.Fname < b.Fname;

}

if(a.Lname!=b.Lname)

{

if(switch_type==2)

return a.Lname > b.Lname;

if(switch_type==1)

return a.Lname < b.Lname;

}

if(a.Rank!=b.Rank)

{

if(switch_type==2)

return a.Rank > b.Rank;

if(switch_type==1)

return a.Rank < b.Rank;

}

}

int main()

{

ifstream file ("emp.csv");

int Count=0;// to store number of rows in the file

string fname,lname,rank,sal;

Emp E[150];

getline( file, fname, ',' );

getline( file, lname, ',' );

getline( file, rank, ',' );

getline( file, sal, ' ' );

while ( file.good() )

{

getline( file, E[Count].Fname, ',' );

getline( file, E[Count].Lname, ',' );

getline( file, E[Count].Rank, ',' );

getline( file, E[Count].Salary, ' ' );

Count++;

// cout << "Fname " << fname << " Lname " << lname << " Rank " << rank << " Sal " << sal << endl;

}

// for(int i=0;i<Count;i++)

// {

// cout << E[i].Fname << " " << E[i].Lname << " " << E[i].Rank << " " << E[i].Salary << endl;

// }

char input[100];

// switch case for Column type,switch_tpye for sorting type

cout << "Enter Column Name: ";

cin.getline(input,100);

if(strcmp(input,"First Name")==0) switch_case=1;

if(strcmp(input,"Last Name")==0) switch_case=2;

if(strcmp(input,"Employee Rank")==0) switch_case=3;

if(strcmp(input,"Salary")==0) switch_case=4;

string sort_type;

cout << "Sort tpye(ASC/DESC): ";

cin >> sort_type;

if(sort_type=="ASC") switch_type=1;

if(sort_type=="DESC") switch_type=2;

switch(switch_case)

{

case 1:

sort(E,E+Count,comp1);

break;

case 2:

sort(E,E+Count,comp2);

break;

case 3:

sort(E,E+Count,comp3);

break;

case 4:

sort(E,E+Count,comp4);

break;

}

// for(int i=0;i<Count;i++)

// {

// cout << E[i].Fname << " " << E[i].Lname << " " << E[i].Rank << " " << E[i].Salary << endl;

// }

ofstream out;

out.open("output.csv");

for(int i=0;i<Count;i++)

{

out << E[i].Fname << "," << E[i].Lname << "," << E[i].Rank << "," << E[i].Salary << endl;

}

return 0;

}

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