Question

Write a program that calculates the average number of days a company's employees are absent during the year and outputs a report on a file named "employeeAbsences.txt".


Project Description

Write a program that calculates the average number of days a company's employees are absent during the year and outputs a report on a file named "employeeAbsences.txt".

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:

  • display a due date

  • display the user full name

  • 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".

Processing Requirements

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

  3. 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.


NOTE:

  • The location of the file employeeAbsences.txtcreated by your program will be in the same folder as your .cpp source file. Make sure to check your file system directory to see if the file is getting created as the result of running your program and its format matches with the format shown in Sample File output format.

  • Also avoid declaring an absolute path foremployeeAbsences.txt, for example e:\\ employeeAbsences.txt orc:\\cmsc140\\employeeAbsences.txt in your program].

0 0
Add a comment Improve this question Transcribed image text
Answer #1

//please provide +ve rating , thanks!!

#include
#include

using namespace std;
ofstream out;
int NumOfEmployees();
int TotDaysAbsent(int number_of_employees);
double AverageAbsent(int n, int total_no_days);
int main()
{
   //call functions
   int n = NumOfEmployees();
   int total_absent_days = TotDaysAbsent(n);
   //call third function AverageAbsent
   double avg = AverageAbsent(n, total_absent_days);
   cout << "Average number of days absent: " << avg << endl;
}

int NumOfEmployees()
{
   int n;
   cout << "Enter number of employees: ";
   cin >> n;
   return n;
}
int TotDaysAbsent(int number_of_employees)
{
   int ID, sum = 0, days;
   //open output file for reading
   out.open("employeeAbsences.txt");
   if (!out)
   {
       cout << "Not able to open employeeAbsences.txt file for writing\n";
       return -1;
   }
   for (int i = 0; i < number_of_employees ;i++)
   {
       cout << "Enter employee ID: ";
       cin >> ID;
       do
       {
           cout << "Enter number of days the employee missed: ";
           cin >> days;
           if (days < 0)
           {
               cout << "Number of days cannot be negetive\n";
           }
       } while (days < 0);
       //write ID and number of days to output file employeeAbsences.txt
       out << ID << " " << days << endl;
       sum += days;
   }
   //close file
   out.close();
   //return total days
   return sum;
}
double AverageAbsent(int n, int total_no_days)
{
   return (double)total_no_days / n;
}

/*Output1
Enter number of employees: 5
Enter employee ID: 1234
Enter number of days the employee missed: -1
Number of days cannot be negetive
Enter number of days the employee missed: 6
Enter employee ID: 3456
Enter number of days the employee missed: 7
Enter employee ID: 8976
Enter number of days the employee missed: 0
Enter employee ID: 3452
Enter number of days the employee missed: 10
Enter employee ID: 9876
Enter number of days the employee missed: 12
Average number of days absent: 7
//check outputfile content employeeAbsences.txt
1234 6
3456 7
8976 0
3452 10
9876 12
//output2
Enter number of employees: 6
Enter employee ID: 4532
Enter number of days the employee missed: 5
Enter employee ID: 8765
Enter number of days the employee missed: 11
Enter employee ID: 5432
Enter number of days the employee missed: 8
Enter employee ID: 9876
Enter number of days the employee missed: 11
Enter employee ID: 5543
Enter number of days the employee missed: 2
Enter employee ID: 7765
Enter number of days the employee missed: 7
Average number of days absent: 7.33333
//check outputfile content employeeAbsences.txt
4532 5
8765 11
5432 8
9876 11
5543 2
7765 7
*/

Add a comment
Know the answer?
Add Answer to:
Write a program that calculates the average number of days a company's employees are absent during the year and outputs a report on a file named "employeeAbsences.txt".
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • In C++, Please help me compute the following flowchart exactly like this requirement: Use while loops...

    In C++, Please help me compute the following flowchart exactly like this requirement: Use while loops for the input validations required: number of employees(cannot be less than 1) and number of days any employee missed(cannot be a negative number, 0 is valid.) Each function needs a separate flowchart. The function charts are not connected to main with flowlines. main will have the usual start and end symbols. The other three functions should indicate the parameters, if any, in start; and...

  • Using basic c++ write 2 separate codes for this assignment. Program #1 Write a program that...

    Using basic c++ write 2 separate codes for this assignment. Program #1 Write a program that calculates the average of a group of test scores, where the lowest score in the group is dropped. It should use the following functions. • void getScore() should ask the user for a test score, store it in the reference parameter variable, and validate it. This function should be called by the main once for each of the five scores to be entered. •...

  • C++ 3. Write a program that reads integers from a file, sums the values and calculates...

    C++ 3. Write a program that reads integers from a file, sums the values and calculates the average. a. Write a value-returning function that opens an input file named in File txt. You may "hard-code" the file name, i.e., you do not need to ask the user for the file name. The function should check the file state of the input file and return a value indicating success or failure. Main should check the returned value and if the file...

  • Kindly solve this using C PROGRAMMING ONLY. 4. Write a program marks.c which consists of a...

    Kindly solve this using C PROGRAMMING ONLY. 4. Write a program marks.c which consists of a main function and three other functions called. readmarks , changemarks (, and writemarks() The program begins by calling the function readmarks () to read the input file marksin. txt which consists of a series of lines containing a student ID number (an integer) and a numeric mark (a float). Once the ID numbers and marks have been read into arrays (by readmarks () the...

  • In header file (.h) and c++ file format (.cpp). A local company has asked you to...

    In header file (.h) and c++ file format (.cpp). A local company has asked you to write a program which creates an Employee class, a vector of Employee class objects, and fills the objects with employee data, creating a "database" of employee information. The program allows the user to repeatedly search for an employee in the vector by entering the employee's ID number and if found, display the employee's data. The Employee_C class should have the following data and in...

  • The name of the C++ file must be search.cpp Write a program that will read data...

    The name of the C++ file must be search.cpp Write a program that will read data from a file. The program will allow the user to specify the filename. Use a loop that will check if the file is opened correctly, otherwise display an error message and allow the user to re-enter a filename until successful. Read the values from the file and store into an integer array. The program should then prompt the user for an integer which will...

  • In C++ Programming Write a program in a file named SeedFinder.cpp that finds and displays all...

    In C++ Programming Write a program in a file named SeedFinder.cpp that finds and displays all the seeds of a integer given by the user. Let’s define a seed of an integer, n, to be a positive value that equals n when multiplied by its individual digits. For example, 23 is a seed of 138 because 23 × 2 × 3 = 138. 111 is an example of a seed of itself because 111 × 1 × 1 × 1...

  • Write a C++ program that calculates the working hours of multiple employees during a weekday. The...

    Write a C++ program that calculates the working hours of multiple employees during a weekday. The program will take the last digits of your student id as the number of row employees of the array (if your last digits are less than or equal to 7 add 3 to it) and the weekdays are the column then fill the array with using random integer inputs (between 0 - 10 ) (stores the random numbers in a 2D array using both...

  • Write a program named program44.py that can be used to determine the average of some integers....

    Write a program named program44.py that can be used to determine the average of some integers. The number of integers can vary, and this should not be initially set by user input (see sample output). Instead, use a while loop and a sentinel value of zero to cease integer input. Display the average accurate to two decimal places.

  • Write a program that writes a series of random numbers to a file. Each random number...

    Write a program that writes a series of random numbers to a file. Each random number should be in the range of 1 through 500 inclusive. 1.Use a file called randoms.txt as a input file and output file a. If you go to open the file and its not there then ask the user to create the file     and then quit 2. Ask the user to specify how many random numbers the file will hold. a.Make sure that the...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT