Question

In: Computer Science

Consider a text file that you will create named “employees.txt”. The file contains data organized according...

Consider a text file that you will create named “employees.txt”. The file contains data organized according to the following format:John Smith 10 15Sarah Johnson 40 12Mary Taylor 27 13Jim Stewart 25 8For instance, “John” is the first name, “Smith” is the last name, “10” is the number of hours per week, and “15” is the hourly rate.Write a program that computes the weekly salary of each employee. The program prints the first name, last name, and weekly salary of each employee in a file named “results.txt”. ‘results.txt” must be created automatically by your program. You must use a function to read/process the data from the input file and this function must have parameters. The “employees.txt” file must be opened from main and read from within your defined function. in c++

and how to do the screenshots on mac

Solutions

Expert Solution

Please look at my code and in case of indentation issues check the screenshots.

---------------main.cpp----------------

#include <iostream>
#include <fstream>
#include <string>
#include <iomanip>

using namespace std;

struct employee{ //create a structure to store employee details
string fname, lname;
int hours_per_week, hourly_pay;
int weekly_pay;
};


int read_data(ifstream &inpfile, employee array[]);
void calculate_weekly_pay(employee array[], int size);
void write_to_file(employee array[], int size);


int main()
{
employee array[100]; //create an employee array to store employee details
ifstream inpfile("employees.txt"); //open input file
int n = read_data(inpfile, array); //read data from file and store results into array
calculate_weekly_pay(array, n); //calculate the weekly pay of each employee
write_to_file(array, n); //write the results into file
cout << "results.txt created successfully\n";
return 0;
}

int read_data(ifstream &inpfile, employee array[])
{
int i = 0; //array index
//read each line from file, and store details into array in the structure fields
while(inpfile >> array[i].fname >> array[i].lname >> array[i].hours_per_week >> array[i].hourly_pay){
i++; //move to next index of array
}
return i; //return the number of employees read from file
}

void calculate_weekly_pay(employee array[], int size)
{
for(int i = 0; i < size; i++) //loop for each index of array
{
array[i].weekly_pay = array[i].hours_per_week * array[i].hourly_pay; //calculate weekly pay
}
}


void write_to_file(employee array[], int size)
{
ofstream outfile("results.txt"); //open output file for writing
outfile << "First Name\tLast name\tWeekly Salary\n"; //write all employees details
for(int i = 0; i < size; i++) //setw is used for allignment in the output, it sets the width
{
outfile << left << setw(14) << array[i].fname << setw(10) << array[i].lname << setw(5) << array[i].weekly_pay << endl;
}
}

--------------Screenshots--------------------

------------------Input------------------

------------------Output------------------

----------------------------------------------------------------------------------------------------------
Please give a thumbs up if you find this answer helpful.
If it doesn't help, please comment before giving a thumbs down.
Please Do comment if you need any clarification.
I will surely help you.


Related Solutions

in java please!!! suppose there is a text file named TextFile.txt with some data in the...
in java please!!! suppose there is a text file named TextFile.txt with some data in the root directory (e.g. C:\ or \) of your computer. In JAVA, write code that (i) opens the file in read mode; (ii) displays the file content on the monitor screen/console; (iii) uses exception handling mechanism with try, catch, and finally blocks; and (iv) safely closes the file. Writing the main() method is optional.
An HTML file is a text file that contains text to be displayed in a browser...
An HTML file is a text file that contains text to be displayed in a browser and __________ to be interpreted (read) by the browser formatting and styling the document Both C++ and javascript are computer programing languages; what are their differences? What HTML tag can let you insert javascript in to document Which attributes of the <script> tag tells the brorwser what kind of scripting language is insterted? (give an example) in the javascript section of the HTML file,...
how to creat Create a text file that contains a list of integer numbers separated by...
how to creat Create a text file that contains a list of integer numbers separated by comma (numbers.txt). E.g. 3, 7, 5, 1, 11, 8,2, 6 2- how to Write a python program (minMax.py) to read the file numbers.txt and find the largest and smallest numbers in the file. (without using use min(), max()). calculate the average and output the results. 3-Use python file i/o, write a python program (fileCopy.py) that makes a copy of minMax.py (Read contents of minMax.cp...
In this PYTHON 3 program assignment, you will find a text file named WorldSeries.txt. This file...
In this PYTHON 3 program assignment, you will find a text file named WorldSeries.txt. This file contains a chronological list of the World Series' winning teams from 1903 through 2018. The first line in the file is the name of the team that won in 1903, and the last line is the name of the team that won in 2018. (Note the World Series was not played in 1904 and 1994. There are entries in the file indicating this.) Write...
Create a file named StudentArrayList.java,within the file create a class named StudentArrayList. This class is meant...
Create a file named StudentArrayList.java,within the file create a class named StudentArrayList. This class is meant to mimic the ArrayList data structure. It will hold an ordered list of items. This list should have a variable size, meaning an arbitrary number of items may be added to the list. Most importantly this class should implement the interface SimpleArrayList provided. Feel free to add as many other functions and methods as needed to your class to accomplish this task. In other...
Create a Python file named num_sum.py that contains: The definition of two functions: volume - accepts...
Create a Python file named num_sum.py that contains: The definition of two functions: volume - accepts three parameters and returns the product of them, but displays nothing sum_of_nums - accepts 1 or more numbers and returns their sum, but displays nothing A print function call that includes a call to volume, passing 2, 3, and 4 A print function call that includes a call to sum_of_nums, passing 1, 2, 3, 4, and 5
You are given a text file that contains the timetable for buses that travel a college...
You are given a text file that contains the timetable for buses that travel a college campus. The first line of the file contains the name for each stop on the bus system separated by colons. Each following line contains the times using a 24-hour clock at which each bus in the system will arrive at a bus stop, also separated by colons.The timetable will have the following format: Edinburgh:Danderhall:Dalkeith:Edgehead:Pathhead:Blackshiels:Oxton:Carfraemill:Lauder:Earlston:Leaderfoot:Newtown St Boswells:St Boswells:Clintmains:Kelso 0850:0911:0918:0930:0933:0939:0953:0955:1001:1015:1025:1029:1032:1038:1055 1150:1211:1218:1230:1233:1239:1253:1255:1301:1315:1325:1329:1332:1338:1355 1350:1411:1418:1430:1433:1439:1453:1455:1501:1515:1525:1529:1532:1538:1555 1610:1633:1640:1652:1655:1701:1715:1717:1723:1737:1746:1750:1753:1803:1820 1750:1811:1818:1830:1833:1839:1853:1855:1901:1919:1925:1929:1932:1938:1955 2000:2021:2028:2037:2040:2046:2100:2102:2108:2121:2126:2130:2133:2138:2155 Write...
Create C# code that can search a text file and output the data at the line...
Create C# code that can search a text file and output the data at the line number inputted and amount of entries needed. Example of call in command window: Search16s filename.txt 273   10 Where 273 is the line number to start the output from, and 10 is the number of sequences that the program should output. The number of sequences entered on call should always be a odd number or give an error in console. The output should also display...
Define a class named Document that contains an instance variable of type String named text that...
Define a class named Document that contains an instance variable of type String named text that stores any textual content for the document. Create a method named toString that returns the text field and also include a method to set this value. Next, define a class for Email that is derived from Document and includes instance variables for the sender, recipient, and title of an email message. Implement appropriate set and get methods. The body of the email message should...
Create this C++ program using classes 1. Create a file text file with a string on...
Create this C++ program using classes 1. Create a file text file with a string on it 2. Check the frecuency of every letter, number and symbol (including caps) 3. Use heapsort to sort the frecuencys found 4. Use huffman code on the letters, symbols or numbers that have frecuencys I created the file, and the frecuency part but i'm having trouble with the huffman and heapsort implementation.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT