Homework Help Question & Answers

I NEED A PSEUDOCODE ALGORITHM FOR THIS CODE PLEASE C++: #include #include #include #include using...

I NEED A PSEUDOCODE ALGORITHM FOR THIS CODE PLEASE C++:

#include

#include

#include

#include

using namespace std;

int NumOfEmployees();

int TotDaysAbsent(int);

double AverageAbsent(int, int);

int main()

{

        cout << endl << "Calculate the average number of days a company's employees are absent." << endl << endl;

     int numOfEmployees = NumOfEmployees();

        TotDaysAbsent(numOfEmployees);

   return 0;

}

int NumOfEmployees()

{

   int numOfEmployees = 0;

    cout << "Please enter the number of employees in the company: ";

        cin >> numOfEmployees;

    while(numOfEmployees <= 0)

    {   

        cout << endl << "The number of employees must not be 0 or negative.\nPlease re-enter the number of employees: ";

        cin >> numOfEmployees;   

    }

    return numOfEmployees;    

}

int TotDaysAbsent(int numOfEmployees)

{    

    int totalDaysAbsent = 0;

    int employeeId[numOfEmployees];

    int daysAbsent[numOfEmployees];

    string programmerName = "";

    for(int i = 0; i < numOfEmployees; i++

    {        

        int empId = 0;

        int absentDays = 0;

        cout << "Please enter an employee id: ";

        cin >> empId;

        employeeId[i] = empId;

        cout << "Please enter the number of days this employee was absent: ";

        cin >> absentDays;

        while(absentDays < 0)

               {

            cout << endl << "The number of days must not be negative.\nPlease re-enter the number of days absent: ";

            cin >> absentDays;   

        }

        daysAbsent[i] = absentDays;

    }

    cout << "Programmer: ";

    cin.sync();

    cin >> programmerName;

    //getline(cin, programmerName, '\n');

    // write to file

    ofstream outputFile("employeeAbsences.txt");

    if(!outputFile.is_open())

        cout << "Unable to open employeeAbsences.txt file!" << endl;

    else

    {

        outputFile << "EMPLOYEE ABSENCE REPORT" << endl;

        outputFile << "Employee Id\t\tDays Absent" << endl;

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

        {

            outputFile << employeeId[i] << "\t\t\t\t\t" << daysAbsent[i] << endl;

            totalDaysAbsent += daysAbsent[i];

}

        outputFile << endl << "The " << numOfEmployees << " employees were absent for a total of " << totalDaysAbsent << " days." << endl;

        outputFile << "The average number of days absent is " << setprecision(1) << fixed << AverageAbsent(numOfEmployees, totalDaysAbsent) << " days." << endl;

        outputFile << endl << "Programmer: " << programmerName << endl;

                outputFile.close();        

    }  

    return totalDaysAbsent;  

}

double AverageAbsent(int numOfEmployees, int totalDaysAbsent)

{    

    return (double)(totalDaysAbsent / numOfEmployees);

}

0 0
ReportAnswer #1

START

   METHOD Main
       PRINT "Calculate the average number of days a company's employees are absent"
       GET numOfEmployees = CALL NumOfEmployees() Method
       CALL TotDaysAbsent(numOfEmployees)


   METHOD NumOfEmployees ()
       DECLARE numOfEmployees to 0
       GET numOfEmployees from USER
      
       WHILE (numOfEmployees is < 0)
           PRINT "Must not be 0, enter again: "
           GET numOfEmployees from USER
      
       RETURN GET numOfEmployees

  
   METHOD TotDaysAbsent (numOfEmployees)
       DECLARE totalDaysAbsent = 0
       DECLARE employeeId[numOfEmployees]
       DECLARE daysAbsent[numOfEmployees]
       DECLARE programmerName

       LOOP FOR i = 0 down to numOfEmployees
           GET empID and absentDay
           Validate INPUTs taken above
           employeeId[i] = empID
           daysAbsent[i] = absentDay

       GET programmerName from the user
          
       OPEN FILE "employeeAbsences.txt"

       LOOP FOR i = 0 down to numOfEmployees
           APPEND employeeId[numOfEmployees] into FILE
           APPEND daysAbsent[numOfEmployees] into FILE
           UPDATE totalDaysAbsent = totalDaysAbsent + daysAbsent[i]
      
       WRITE to FILE numOfEmployees + totalDaysAbsent
       WRITE to FILE AverageAbsent(numOfEmployees, totalDaysAbsent)
       WRITE to File programmerName

       RETURN totalDaysAbsent


   METHOD AverageAbsent (numOfEmployees, totalDaysAbsent)
       RETURN totalDaysAbsent / numOfEmployees

END

METHOD Main PRINT Calculate the average number of days a company s employees are absent GET numOfEmployees CALL NumofEmploye

Add Homework Help Answer
Add Answer of:
I NEED A PSEUDOCODE ALGORITHM FOR THIS CODE PLEASE C++: #include #include #include #include using...
Your Answer: Your Name: What's your source?
Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Need Online Homework Help?
Ask a Question
Get FREE EXPERT Answers
WITHIN MINUTES