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

This program need to be done from chap 1to 7 only from book link Write a C++ pro

ID: 3621832 • Letter: T

Question

This program need to be done from chap 1to 7 only from book link

Write a C++ program  that calculates the average number of days a company's employees are absent.  Input will come from a file and output will go to the screen.  The file name will be entered from the keyboard in the main function.  Assume that the employees start with 1 and are numbered sequentially.  The first entry in the file should be the number of employees to process.   Check this value to see if it is greater than or equal to one.  If it is not, print the message:  Invalid number of employees and your name as programmer.  Read from the input file the number of days each employee missed during the past year.  Assume the number of days absent will be an integer.  Echo to the screen the number of days missed for each employee.  If the number of days missed is negative, print after the negative number read, the message:  Invalid number of days.  Do not add the negative number to the total number of days absent.  Print the total number of days absent, the average number of days absent, the least number of days absent with the employee number(s), and the most number of days absent with the employee number(s).  Be sure to omit employees with negative numbers from the summary data.  Use a one-dimensional array to hold the employee absences.  Always show two decimal places for the average.

Assume that the company has no more than 50 employees and that your input file is constructed correctly. Code at least three functions in addition to the main function.          

1. Use static_cast for average

2. comments are used with code and variables           

This is the input file need to be in .txt format

10

3

0

1

2

4

-7

1

3

2

1

This part bellow is the finish program and the program should look similar ( not part of the question but the finish program)

       CALCULATE AVERAGE EMPLOYEE ABSENCE

 

Please enter the name of the input file a:in7.txt

             Employee Number      Days Absent

                         1                                 3

                         2                                 0

                         3                                 1

                         4                                 2

                         5                                 4

                         6                                -7  Invalid number of days

                         7                                 1

                         8                                 3

                         9                                 2

                        10                                1

The total days absent for 10 employees is 17 days.

The average number of days absent is 1.70 days.

The minimum number of absences, 0 days, was from employee(s): 2

The maximum number of absences, 4 days, was from employee(s): 5

 

Programmer: insert your name here

Book:

Starting Out with C++: From Control Structures Through Objects (6th) chap 7

Explanation / Answer

please rate - thanks

#include <iostream>
#include <fstream>
#include <iomanip>
using namespace std;
void Readdata(int[],int&);
int Large(int[],int[],int&,int);
int Small(int[],int[],int&,int);
int Total(int[],int);
void output(int[], int,int[],int,int,int[],int,int ,int,double);
int main()
   {int a[50],n=0,min[50],max[50],sum,minn,maxn,minv,maxv;
   double avg;
   cout<<" CALCULATE AVERAGE EMPLOYEE ABSENCE ";
   Readdata(a,n);
   maxv=Large(a,max,maxn,n);
   minv=Small(a,min,minn,n);
   sum=Total(a,n);
   output(a,n,min,minn,minv,max,maxn,maxv,sum,(double)sum/n);
   system("pause");
    return 0;
     }
void Readdata(int a[ ], int &n)
{char filename[30];
int i=0;
   ifstream input;
   cout<<"Please enter the name of the input file ";
   cin>>filename;  
   input.open(filename);           //open file
   if(input.fail())             //is it ok?
       { cout<<"file did not open please check it ";
        system("pause");
        return;
        }
   input>>n;
     for(i=0;i<n;i++)
          input>>a[i];
       input.close();
}
void output(int a[], int n,int min[],int minn,int minv,int max[],int maxn,
            int maxv,int sum,double avg)
{cout<<" Employee Number      Days Absent ";
int i;
for(i=0;i<n;i++)
     cout<<" "<<i+1<<" "<<a[i]<<endl;
cout<<"The total days absent for "<<n<<" employees is "<<sum<<" days. ";
cout<<"The average number of days absent is "<<setprecision(2)<<fixed<<avg<<" days ";
cout<<"The minimum number of absences, "<<minv<<" days, was from employee(s): ";
for(i=0;i<minn;i++)
    cout<<min[i]<<" ";
cout<<endl;
cout<<"The maximum number of absences, "<<maxv<<" days, was from employee(s): ";
for(i=0;i<maxn;i++)
    cout<<max[i]<<" ";
cout<<endl;
cout<<"Programmer: insert your name here ";
}
int Total(int Array[], int N)
{int i,sum=0;
for(i=0;i<N;i++)
    if(Array[i]>=0)
         sum+=Array[i];
return sum;
}
int Small(int Array[], int m[],int& upto,int N)
{int i,max;
upto=0;
max=32000;
for(i=0;i<N;i++)
if(Array[i]>=0)
    if(Array[i]<max)
         {max=Array[i];
         m[0]=i+1;
         upto=1;
         }
    else if(Array[i]==max)
        m[upto++]=i+1;
cout<<upto;
for(i=0;i<upto;i++)
     cout<<m[i]<<" ";
cout<<endl;
return max;
}
int Large(int Array[], int m[],int& upto,int N)
{int i,max;
upto=0;
max=-10;
for(i=0;i<N;i++)
    if(Array[i]>max)
         {max=Array[i];
         m[0]=i+1;
         upto=1;
         }
    else if(Array[i]==max)
        m[upto++]=i+1;
return max;
}

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