Question

In: Computer Science

Spring 2019 CMSC 140 Programming Project 4: Days Out Project Specifications Input for this project: the...

Spring 2019 CMSC 140 Programming Project 4: Days Out

Project Specifications

Input for this project:

  • the user must enter the number of employees in the company.
  • the user must enter as integers for each employee:
    • the employee number (ID)
    • the number of days that employee missed during the past year.

Input Validation:

  • Do not accept a number less than 1 for the number of employees.
  • Do not accept a negative number for the days any employee missed.
  • Be sure to print appropriate error messages for these items if the input is invalid.

Output: The program should display the following data:

  • Each employee number (ID) and the number of days missed should be written to the report file named "employeeAbsences.txt".
  • The average number of days a company's employees are absenting during the year should be written to the report file named "employeeAbsences.txt".
  • Create a global variable of type ofstream for the output file. Use this variable to open the fileemployeeAbsences.txt in your program to write data to it. A global variable is defined above the main function and its scope is throughout the program.
  • Create the following three functions that will be called by the main function:

         

  1. A function called NumOfEmployees. This function asks the user for the number of employees in the company. This value should be returned as an int. The function accepts no arguments (No parameter/input).
  2. A second function called TotDaysAbsent that accepts an arguments of type int for the number of employees in the company and returns the total of missed days as an int. This function should do the following:
    1. Asks the user to enter the following information for each employee:
  • The employee number (ID) (Assume the employee number is 4 digits or fewer, but don't validate it).
  • The number of days that employee missed during the past year.
    1. Writes each employee number (ID) and the number of days missed to the output file (employeeAbsences.txt). ( Refer to Sample File Output )
  1. A third function called AverageAbsent that calculates the average number of days absent.
    1. The function takes two arguments:
  • the number of employees in the company
  • the total number of days absent for all employees during the year.
    1. This function should return, as a double, the average number of days absent.
    2. This function does not perform screen or file output and does not ask the user for input.

Solutions

Expert Solution

// C++ program to take inputs of number of days the employees of a company was absent and write these information as well as average number of days absent to the file

#include <iostream>

#include <fstream>

#include <iomanip>

using namespace std;

// global variable

ofstream fout;

// function declaration

int NumOfEmployees();

int TotDaysAbsent(int numEmployees);

double AverageAbsent(int numEmployees, int absentDays);

int main() {

               fout.open("employeeAbsences.txt");

               int numEmployees, absentDays;

               numEmployees = NumOfEmployees();

               fout<<left<<setw(15)<<"Employee ID"<<left<<setw(10)<<"Days Absent"<<endl;

               absentDays = TotDaysAbsent(numEmployees);

               double avgAbsent = AverageAbsent(numEmployees, absentDays);

               fout<<"Average Number of days a company's employees are absent : "<<fixed<<setprecision(2)<<avgAbsent;

               fout.close();

               return 0;

}

// function to get and return the number of employees in a company

int NumOfEmployees()

{

               int num;

               cout<<"Enter the number of employees :";

               cin>>num;

               while(num < 1)

               {

                              cout<<"Number of employees must be at least 1"<<endl;

                              cout<<"Enter the number of employees :";

                              cin>>num;

               }

               return num;

}

// function get and return the total number of days the employees of a company was absent

int TotDaysAbsent(int numEmployees)

{

               int daysAbsent, totalDaysAbsent = 0, empId;

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

               {

                              cout<<"Employee "<<(i+1)<<" : "<<endl;

                              cout<<"Enter the employee id : ";

                              cin>>empId;

                              cout<<"Enter the number of days that employee missed during the past year : ";

                              cin>>daysAbsent;

                              while(daysAbsent < 0)

                              {

                                             cout<<"Number of days absent cannot be negative"<<endl;

                                             cout<<"Enter the number of days that employee missed during the past year : ";

                                             cin>>daysAbsent;

                              }

                              fout<<left<<setw(15)<<empId<<left<<setw(10)<<daysAbsent<<endl;

                              totalDaysAbsent += daysAbsent;

               }

               return totalDaysAbsent;

}

// function to calculate and return the average number of days the employees of a company was absent

double AverageAbsent(int numEmployees, int absentDays)

{

               return(((double)absentDays)/numEmployees);

}

//end of program

Output:

Console:

File:


Related Solutions

ACT 205 Spring 2018 - 2019 The Accounting Equation Neal decides to open a computer programming...
ACT 205 Spring 2018 - 2019 The Accounting Equation Neal decides to open a computer programming service which he names Microsoft. 1. On January 1, 2018, Neal invests $15,000 cash in the business. 2. Microsoft purchases computer equipment for $7,000 cash. 3. Microsoft purchases computer paper and other supplies for $1,600 from ABC Supply Company expected to last several months. ABC agrees to allow Microsoft to pay this bill in February. 4. Microsoft receives $1,200 cash from customers for programming...
"This C Programming " Write a program that accepts four (4) lines of input: • The...
"This C Programming " Write a program that accepts four (4) lines of input: • The first line contains a float value in 4.2f format • The second line contains a char value • The third line contains a 4-digit int value • The fourth line contains a char value and then displays all of the input on a single line Write a program that accepts a phone number of the form +1(xxx)-xxx-xxxx where x is a digit, and displays...
It was spring 2019 when John Edgeworth was a project manager at Kreative Toy Corporation (KTC)...
It was spring 2019 when John Edgeworth was a project manager at Kreative Toy Corporation (KTC) submitted a proposal for funding to the recently established product review committee. He was proposing that KTC introduce through its distribution channels a new toy based on a popular cartoon character. John felt that Kreative could get this new product out for Christmas, Kreative could take advantage of the strong market for gift giving. John also knew that the toy market was very volatile...
Semester 2019 Java Programming Project 3: Loops, Strings, and Character Methods Having a secure password is...
Semester 2019 Java Programming Project 3: Loops, Strings, and Character Methods Having a secure password is a very important practice, particularly when much of our personal information is stored online. Please write a program that validates a new password, following these 4 rules: The password must be at least 8 characters long. The password must have at least one upper case letter. The password must have at least one lower case letter. The password must have at least one digit....
Perimeter Road has 4 streetlights. A streetlight burns out after an average of 100 days of...
Perimeter Road has 4 streetlights. A streetlight burns out after an average of 100 days of use (exponentially distributed). It takes an average of 10 days to replace a burned-out street lamp (exponentially distributed). Model the number of functioning streetlights as a birth-and-death process. (a) What is the long-run proportion of time that all streetlights are burned out? (b) On average how many streetlights are illuminating the Perimeter Road?
Net present worth (NPW) of a project is sensitive to 4 input parameters, namely: A, B,...
Net present worth (NPW) of a project is sensitive to 4 input parameters, namely: A, B, C and D. Assume that NPW= 4000-90000Pa, is the relation that gives the NPW of the project as a function of Pa, which is the percentage deviation in the factor A. Similarly, assume that NPW= 4000-40000Pb, NPW= 4000+60000Pc and NPW= 4000+70,000Pd are the functions that give the NPW of the project as function of the percentage deviations in the factors B, C and D...
____ 4. Stephanie is self-employed. In 2019 she drove 1,000 miles for business out of a...
____ 4. Stephanie is self-employed. In 2019 she drove 1,000 miles for business out of a total 10,000 miles for the year. Her auto expenses for the year were: gasoline - $500; insurance - $1,000; repairs - $200; business parking - $400. How much is her automobile deduction if she uses the standard mileage method?             a.         $580             b.         $980             c.         $2,680             d.         $2,100             e.         $210             f.          $0. ____ 5. An aggressive young attorney is...
Java Part 2 of 4 - Amusement Park Programming Project MUST BE COMPATIBLE WITH PART 1...
Java Part 2 of 4 - Amusement Park Programming Project MUST BE COMPATIBLE WITH PART 1 https://www.chegg.com/homework-help/questions-and-answers/java-part-1-4-amusement-park-programming-project-requirements-use-java-selection-construct-q40170145?trackid=ERIFssNL Requirements: Use the Java selection constructs (if and if else). Use the Java iteration constructs (while, do, for). Use Boolean variables and expressions to control iterations. Proper error handling. Class: Merchandise – models merchandise available in the gift shop such as t-shirts, sweatshirts, and stuffed animals. Instance Fields: id : long – to identify the specific merchandise item. category : String – to...
Java. Part 1 of 4 - Amusement Park Programming Project Requirements: Use the Java selection constructs...
Java. Part 1 of 4 - Amusement Park Programming Project Requirements: Use the Java selection constructs (if and if else). Use the Java iteration constructs (while, do, for). Use Boolean variables and expressions to control iterations. Proper error handling. Class: Ticket – models admission tickets. Instance Fields: number : long – identify the unique ticket. category : String – store the category of the ticket. holder : String – store the name of the person who purchased the ticket. date...
Internet Programming Project #4:  XML, Schema and XSLT 1.   Write a complete XML file named textbooks.xml, in which...
Internet Programming Project #4:  XML, Schema and XSLT 1.   Write a complete XML file named textbooks.xml, in which you describe at least a partial list of the textbooks you are using this semester. You should include at least two distinct textbooks. If you are using only one text this semester, expand your list to cover the current academic year. Your description of each book must include the title, author(s), publisher, year of publication, and the ISBN. For each author, specify the first...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT