Question

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 what is returned, if any value in the return oval symbol.
    • The call statements (in main) should use striped rectangles containing the name of the function called.
  • Study the sample outputs carefully. Your output should have the same “look”.
  • Do not use global variables.
    • Define, open, and close your file in main.
    • The file is passed as a reference variable of type ofstream to the one function that uses it.
    • You should not use any other reference variables in your code.
  • Use prototypes and code function definitions after the main function.
  • Use information from Chapters 1 – 6 in your text. (No arrays)
  • Follow the Processing Requirements exactly when you design your logic.

Concepts tested in this project

  • Learn to organize code within a function
  • Learn to pass data to and return data from a function
  • Use of loops
  • Use of output file processing

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 student’s full name as programmer on both the console output and the file output
  • display a due date
  • 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 variable of type ofstream inside main for the output file. Use this variable to open the file employeeAbsences.txt in your main program to write data to it.
  • 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 arguments of type int for the number of employees in the company and a reference argument of type ofstream, 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.
0 0
Add a comment Improve this question Transcribed image text
Answer #1

Summary :

Following are provided :

1) Code , (2) FLowchart for main and (3) output of program along with the file .

Note : implemented error handling for all fields .

##################### Code ###################


#include <fstream>
#include <iostream>
#include <string>
#include <stdio.h>
#include <stdlib.h>
#include <iomanip>

using namespace std;

int numOfEmployees();
double averageAbsent(int, int);
int totDaysAbsent(int, std::ofstream&);

int main()
{
   std::ofstream outfile;
   outfile.open("employeesAbsences.txt");
   outfile << " Student : " << " XYZ \n";
   outfile << std::setw(12) << "EmployeeID " << std::setw(14) << " No of Leaves \n";
   int tEmployees = numOfEmployees();
   int tLeaves = totDaysAbsent(tEmployees, outfile);
   double avgleaves = averageAbsent(tEmployees, tLeaves);
   outfile << "Average Leaves : " << avgleaves << "\n";
   outfile.close();

}


int numOfEmployees() {
   int num_employees = -1;
   bool flag = true;
   std::string istr;
   char a;
  
   while (flag) {
       std::cout << "Enter number of employees : ";
       try {
           std::cin >> istr;
           num_employees = std::stoi(istr);
           if (num_employees > 0)
               flag = false;
           else
               std::cout << "Invalid input , try again ...\n";
       }
       catch (std::invalid_argument const& e) {
           std::cout << "Invalid Input, try again ... \n";
       }
   }
   return num_employees;
}

int totDaysAbsent(int num, std::ofstream &outf) {
   bool flag = false;
   int total_leaves = 0;
   std::string idstr;
   std::string lstr;
   int id;
   int leaves;

   for (int i = 0; i < num; i++) {
      
       flag = true;
       idstr.clear();
       lstr.clear();
       while (flag) {
           std::cout << "Enter Employee ID : ";
           try {
               std::cin >> idstr;
               id = stoi(idstr);
               if (id > 0)
                   flag = false;
               else
                   std::cout << "Invalid input , try again ...\n";
           }
           catch (std::invalid_argument const& e) {
               std::cout << "Invalid Input, try again ... \n";
           }
       }


       flag = true;
      
       while (flag) {
           std::cout << "Enter Total Number of Leaves in the Year for Employee - " << id << " : ";
           try {
               std::cin >> lstr;
               leaves = stoi(lstr);
               if (leaves > 0)
                   flag = false;
               else
                   std::cout << "Invalid input , try again ...\n";
           }
           catch (std::invalid_argument const& e) {
               std::cout << "Invalid Input, try again ... \n";
           }
       }
       total_leaves = total_leaves + leaves;
       outf << std::setw(8)<< id << " , " << std::setw(10) << leaves << "\n";
   }

   return total_leaves;
}

double averageAbsent(int totalEmployees, int totalLeaves) {

   return (double)totalLeaves / totalEmployees;
}

###################### End Code ################

FLow chart :

Start lopen employeesAbsences.txt file write Student info Get Number of Employees totDaysAbsent numEmployees outfile) agerage

Output :

usr@DESKTOP-VUM526N: /mnt/i/ PRJ/ Code/cpp/misc/EmployeeLeaves$ g++ Employee Leaves.cpp usr@DESKTOP-VUM526N:/mnt/i/PRJ/Code/

Add a comment
Know the answer?
Add Answer to:
In C++, Please help me compute the following flowchart exactly like this requirement: Use while loops...
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
  • 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 DescriptionWrite 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 SpecificationsInput 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...

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

  • C++ Programming

    PROGRAM DESCRIPTIONIn this project, you have to write a C++ program to keep track of grades of students using structures and files.You are provided a data file named student.dat. Open the file to view it. Keep a backup of this file all the time since you will be editing this file in the program and may lose the content.The file has multiple rows—each row represents a student. The data items are in order: last name, first name including any middle...

  • in c++ please HW09: Read/Write File Ints Now that we've had a taste of what file...

    in c++ please HW09: Read/Write File Ints Now that we've had a taste of what file I/O is all about, here's your chance to try it out on your own! You're to write a program that will prompt the user if he/she would like to read ints from a file (and have them displayed to stdout) or write ints to a file for safekeeping. If the user wishes to save a set of numbers, then the file nums.txt is opened...

  • Student ID: 123 Write a C+ program with the following specifications: a. Define a C++ function (name it function_Student...

    Student ID: 123 Write a C+ program with the following specifications: a. Define a C++ function (name it function_StudentlD where StudentID is your actual student ID number) that has one integer input (N) and one double input (x) and returns a double output S, where N S = n 0 and X2 is given by 0 xeVn n 0,1 Хл —{2. nx 2 n 2 2 m2 x2 3 (Note: in the actual quiz, do not expect a always, practice...

  • using c++ output format should look this but use employee id,hours worked and pay rate and...

    using c++ output format should look this but use employee id,hours worked and pay rate and the total should be calculated. for example employee id:1234 hours work:29.3 pay rate:16.25 administrative, office and field should be outputted as well too. Using a structure, and creating three structure variables, write a program that will calculate the total pay for thirty (30) employees. (Ten for each structured variable.) Sort the list of employees by the employee ID in ascending order and display their...

  • create java application with the following specifications: -create an employee class with the following attibutes: name...

    create java application with the following specifications: -create an employee class with the following attibutes: name and salary -add constuctor with arguments to initialize the attributes to valid values -write corresponding get and set methods for the attributes -add a method in Employee called verify() that returns true/false and validates that the salary falls in range1,000.00-99,999.99 Add a test application class to allow the user to enter employee information and display output: -using input(either scanner or jOption), allow user to...

  • use  JOptionPane to display output Can someone please help write a program in Java using loops, not...

    use  JOptionPane to display output Can someone please help write a program in Java using loops, not HashMap Test 1 Grades After the class complete the first exam, I saved all of the grades in a text file called test1.txt. Your job is to do some analysis on the grades for me. Input: There will not be any input for this program. This is called a batch program because there will be no user interaction other than to run the program....

  • 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)     {            ...

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