PART 1: Write a program in C++ that permits users to enter the following information about your company’s five employees and writes the following information to the file (data.txt). ID no.               Name            Sex (M/F)              Hourly Wages                   Years with company   All information must be displayed in a well formatted manner, so you can put in relevant manipulators for this purpose. Run your program, put in employee information, and verify if you have a txt file as required.   PART 2: At this point you must have a .txt file with information of 5 employees. Go back to your C++ program (from part 1), put the entire existing program from part 1 within block comments. Now write a new program for part 2 (in that same C++ file) as per instructions given below.   Write a C++ program that reads this file data.txt, one line at a time, asks for the number of hours worked by each employee and calculates their total pay for the month. So for each of the employee records that stream in, your program must ask user: Enter hours worked by  (name of employee):   When user puts in the answer, program must calculate the total salary and display on the computer screen as ‘ The salary of (name) is $ (salary). Note that there are 2 parts to this program. When you add a cpp file to your project to write a code, you will first need to write the program to part 1, compile and run it. Then use that same cpp file to write your new code for part 2. That is why I require you finish part 1, put your entire code within block comments ( /* …....  */)  and then  write in your new code for Part 2. This way I can what you wrote for part 1, and also run your code for part 2.

Np Ms Office 365/Excel 2016 I Ntermed
1st Edition
ISBN:9781337508841
Author:Carey
Publisher:Carey
Chapter6: Managing Multiple Worksheets And Workbooks
Section: Chapter Questions
Problem 1.7CP
icon
Related questions
Question

I am stressed, beyond confused, angry, and really anxious about these directions, and it's making me feel like I want to break something. the instructions point out that both parts need to be submitted on a single .cpp file, but it's giving me a problem after problem after problem. I'll post the instructions below, then post what the submission instructions are, then what I currently have written below that. this is my S.O.S. Call, please help me, I'm at my witts end!

PART 1: Write a program in C++ that permits users to enter the following information about your company’s five employees and writes the following information to the file (data.txt).

ID no.               Name            Sex (M/F)              Hourly Wages                   Years with company

 

All information must be displayed in a well formatted manner, so you can put in relevant manipulators for this purpose.

Run your program, put in employee information, and verify if you have a txt file as required.

 

PART 2:

At this point you must have a .txt file with information of 5 employees.

Go back to your C++ program (from part 1), put the entire existing program from part 1 within block comments.

Now write a new program for part 2 (in that same C++ file) as per instructions given below.

 

Write a C++ program that reads this file data.txt, one line at a time, asks for the number of hours worked by each employee and calculates their total pay for the month. So for each of the employee records that stream in, your program must ask user:

Enter hours worked by  (name of employee):  

When user puts in the answer, program must calculate the total salary and display on the computer screen as ‘ The salary of (name) is $ (salary).

  1. Note that there are 2 parts to this program. When you add a cpp file to your project to write a code, you will first need to write the program to part 1, compile and run it. Then use that same cpp file to write your new code for part 2. That is why I require you finish part 1, put your entire code within block comments ( /* …....  */)  and then  write in your new code for Part 2. This way I can what you wrote for part 1, and also run your code for part 2.

//include necessary header files
#include <iostream>
#include <fstream>
#include <cstdlib>
#include <string>
#include <iomanip>
using namespace std;
int main() //main method
{
//declare variables
string filename = "data.txt";
const int num = 5;
string sex[num];
string name[num];
int ID[num], years[num];
double wages[num];
ofstream gm; // ofstream objects
gm.open(filename.c_str()); //open file
if (gm.fail()) //check if file is opened successfully
{
cout << "the file was not successfully opened" << endl;// displays message
exit(1);
}
gm << setiosflags(ios::fixed) << setiosflags(ios::showpoint) << setprecision(2);//for loop
for (int i = 0; i < num; i++)
{
cout << "Enter Employee ID: "; //displays message to enter ID
cin >> ID[i]; //reads imput from user
cout << "\n Enter Employee Name: ";//displays message to enter name
cin >> name[i];//reads imput from user
cout << "\n Enter Sex (M/F): ";//displays message to enter employee's gender
cin >> sex[i];//reads imput from user
cout << "\n Enter Hourly Wages: ";//displays message to enter hourly salary
cin >> wages[i];//reads imput from user
cout << "\n Enter number of years with company: ";//displays message to enter number of years with company
cin >> years[i];//reads imput from user
}
//declare required variables
int tempID, tempyears;
string tempsex;
string tempname;
double tempwages;

return 0;
}

//part2

int main()

//declare variables
string filename2 = ("data.txt");
const int num = 5;
string name[num];
double hours[num];
double wages[num];
double weeklyhrs;
double weeklypay;
double monthlyhrs;
double monthlypay;
int weekBeingPaid();
int monthBeingPaid();
ofstream gm; //ofstream object
gm.open(filename2.c_str());
if (gm.fail()) //check if file is open successfully
{
cout << "the file couldn't be opened successfully" << endl;
exit(1);
}
gm << setiosflags(ios::fixed) << setiosflags(ios::showpoint) << setprecision(2); //for loops
for (int i = 0; i < num; i++)
{
cout << "Enter Employee's Name: ";//displays message to enter employee name
cin >> name[i];//reads imput from user
cout << "\n Enter Employee's Hourly Wage: ";//displays message on entering hourly wage
cin >> wages[i]; //reads imput from user
cout << "\n Enter Hours Worked by Employee: ";//displays message on entering hours worked by employee
cin >> hours[i];//reads imput from user
}
//calculate weekly pay
for (int i = 0; i < num; i++)
{
weeklyhrs = hours[i] * 5; //calculate weekly hours worked
weeklypay = weeklyhrs * wages[i]; //calculate weekly pay
//calculate monthly pay
monthlyhrs = weeklyhrs * 4; //calculates hours worked in a month
monthlypay = weeklyhrs * 4; //calculates monthly payment
}
cout << name << "\n Works: " << weeklyhrs << "and earns: " << weeklypay << "per week";
weeklyhrs++;
weeklypay++;
cout << "\n The Salary of" << name << "Is: $ " << monthlypay << "Per Month";
monthlypay++;

return 0;
}

Expert Solution
trending now

Trending now

This is a popular solution!

steps

Step by step

Solved in 2 steps with 3 images

Blurred answer
Knowledge Booster
Analysis of Performance Measurement
Learn more about
Need a deep-dive on the concept behind this application? Look no further. Learn more about this topic, computer-science and related others by exploring similar questions and additional content below.
Similar questions
  • SEE MORE QUESTIONS
Recommended textbooks for you
Np Ms Office 365/Excel 2016 I Ntermed
Np Ms Office 365/Excel 2016 I Ntermed
Computer Science
ISBN:
9781337508841
Author:
Carey
Publisher:
Cengage
Programming Logic & Design Comprehensive
Programming Logic & Design Comprehensive
Computer Science
ISBN:
9781337669405
Author:
FARRELL
Publisher:
Cengage