Question

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

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
Add a comment Improve this question Transcribed image text
Answer #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

Add a comment
Know the answer?
Add Answer to:
I NEED A PSEUDOCODE ALGORITHM FOR THIS CODE PLEASE C++: #include #include #include #include using namespace...
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
  • 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)     {            ...

  • I need a detailed pseudocode for this code in C ++. Thank you #include <iostream> #include...

    I need a detailed pseudocode for this code in C ++. Thank you #include <iostream> #include <string> #include <iomanip> using namespace std; struct Drink {    string name;    double cost;    int noOfDrinks; }; void displayMenu(Drink drinks[], int n); int main() {    const int size = 5;       Drink drinks[size] = { {"Cola", 0.65, 2},    {"Root Beer", 0.70, 1},    {"Grape Soda", 0.75, 5},    {"Lemon-Lime", 0.85, 20},    {"Water", 0.90, 20} };    cout <<...

  • How do can I update this code (Code A): Code (A) #include using namespace std; int fibonacci(int n) { int a = 0,...

    How do can I update this code (Code A): Code (A) #include using namespace std; int fibonacci(int n) { int a = 0, b = 1, c; if (n <= 1) return n; for (int i = 2; i <= n; i++) { c = a + b; a = b; b = c; } return b; } int fibonacciRecursive(int n) { if (n <= 1) { return n; } return fibonacciRecursive(n-1) + fibonacciRecursive(n-2); } int main() { int n;...

  • #include <iostream> #include <chrono> using namespace std; double improvedPow(double x, int y) { // To be...

    #include <iostream> #include <chrono> using namespace std; double improvedPow(double x, int y) { // To be implemented by you } int main() { cout << "To calculate x^y ..." << endl; double x; int y; cout << "Please enter x: "; cin >> x; cout << "Please enter y: "; cin >> y; if(x == 0) { if (y > 0) cout << 0 << endl; else cout << "x^y is not defined" <<endl; } else { cout << improvedPow(x,y)...

  • Using the code below (C++), add a struct with only 1 vector #include #include #include //...

    Using the code below (C++), add a struct with only 1 vector #include #include #include // Needed to define vectors using namespace std; int main() { vector hours; // hours is an empty vector vector payRate; // payRate is an empty vector int numEmployees; // The number of employees int index; // Loop counter // Get the number of employees. cout << "How many employees do you have? "; cin >> numEmployees; // Input the payroll data. cout << "Enter...

  • #include <iostream> #include <cstdlib> using namespace std; int **dynArray(int row, int cols) { int **myPtr; int...

    #include <iostream> #include <cstdlib> using namespace std; int **dynArray(int row, int cols) { int **myPtr; int lab[4]; myPtr = new int *[row]; for(int i = 0; i < row; i++) myPtr[i] = new int[lab[i]]; for(int i = 0; i<row ; i++) if(myPtr[i] == 0) cout<<"empty"; return myPtr; } void getinput(int ID,int &Station,int &labnumb) { cout<<" Enter your ID number: "<<endl; cin>>ID; cout<<" Enter your station number: "<<endl; cin>>Station; cout<<" Enter your lab number: "<<endl; cin>>labnumb; return; } void logout(int ID,int...

  • This is C++ code for parking fee management program #include <iostream> #include <iomanip> using namespace std;...

    This is C++ code for parking fee management program #include <iostream> #include <iomanip> using namespace std; void input(char& car, int& ihour,int& imin, int& ohour, int& omin); void time(char car, int ihour, int imin, int ohour, int omin, int& phour, int& pmin, int& round, double& total); void parkingCharge (char car, int round, double& total); void print(char car, int ihour, int imin, int ohour, int omin, int phour, int pmin, int round, double total); int main() { char car; int ihour; int...

  • please help me fix the error in here #include<iostream> #include <string> using namespace std; string getStudentName();...

    please help me fix the error in here #include<iostream> #include <string> using namespace std; string getStudentName(); double getNumberExams(); double getScoresAndCalculateTotal(double E); double calculateAverage(double n, double t); char determineLetterGrade(); void displayAverageGrade(); int main() { string StudentName; double NumberExam, Average, ScoresAndCalculateTotal; char LetterGrade; StudentName = getStudentName(); NumberExam = getNumberExams(); ScoresAndCalculateTotal= getScoresAndCalculateTotal(NumberExam); Average = calculateAverage(NumberExam, ScoresAndCalculateTotal); return 0; } string getStudentName() { string StudentName; cout << "\n\nEnter Student Name:"; getline(cin, StudentName); return StudentName; } double getNumberExams() { double NumberExam; cout << "\n\n Enter...

  • i am having trouble displaying results and displaying them evenly it is suppose to look like...

    i am having trouble displaying results and displaying them evenly it is suppose to look like this Enter the following data for employee 1: Employee ID: 1298 Hours worked: 35.8 Pay rate (per hour): 23.45 Enter the following data for employee 2: Employee ID: 1899 Hours worked: 34.5 Pay rate (per hour): 19.5 Enter the following data for employee 3: Employee ID: 4435 Hours worked: 30.5 Pay rate (per hour): 20.75 Enter the following data for employee 4: Employee ID:...

  • c++ programming : everything is done, except when you enter ("a" ) in "F" option ,...

    c++ programming : everything is done, except when you enter ("a" ) in "F" option , it does not work. here is the program. #include <iostream> #include <string> #include <bits/stdc++.h> #include <iomanip> #include <fstream> using namespace std; #define MAX 1000 class Inventory { private: long itemId; string itemName; int numberOfItems; double buyingPrice; double sellingPrice; double storageFees; public: void setItemId(long id) { itemId = id; } long getItemId() { return itemId; } void setItemName(string name) { itemName = name; } string...

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