1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92
|
#include <iostream>
#include <fstream>
int getEmployeeNumber();
int fileAndEmployees(ofstream& outFile, int);
double getAverage(int, int);
int main()
{
int employees = getEmployeeNumber();
ofstream outFile("employeesAbsent.txt");
write the total number of employees on outfile
create a variable of an appropriate type and
call fileAndEmployees() in a way that it's return value
will be stored into that variable.
Don't forget to pass the file and the number of employees.
create a variable of an appropriate type and
call getAverage() in a way that it's return value
will be stored into that variable.
Don't forget to pass the number of employees and the absence days.
write the stored result into outFile
return 0;
}
int getEmployeeNumber()
{
// This function asks for the number of employee.
// There must be at least one employee.
// No further controls will be implemented.
start with a variable which stores the number of employees set to zero
loop until that number is less than one (at the beginning is zero, so...)
^ ask the user for a number
| insert that number into the variables which stores the num. of empl.
^ check if it is at least one, and in case...
| ...print out a message error
|--<--<--
return number of employees
}
int fileAndEmployees(ofstream& outFile, int employees)
{
// This function writes on file and sends to screen the IDs and
// the absence days of each employee.
// To perform such a task, it enters a loop which iterates as many
// times as the number of employees.
// At each iteration, it asks the user for
// - employee ID
// - employee's absence days.
// Then, it writes them on the given file.
// If the data are to be output on screen, it's possible to add an
// instruction which says: "written on file: " << ID << days of absence.
// Before asking for new data, the loop will increase the total number
// of absence days, which will be later returned to the caller.
create a variable to store the total absence days and set it to zero
for a number (for example 'i') which varies from 0 to the number
^ of employees less 1 --> if employees == 5, 'i' must run from 0 to 4.
|
| ask the user for an employee's ID
^ create a variable to store that number
| insert the user's answer in that number
|
^ ask the user for an employee's days of absence
| create a variable to store that number
| insert the user's answer in that number
^
| write employee's ID and absence days on the given file
|
^ increase the variable which store the total absence days by
| the current absence days
|<--<--
return total days of absence of all the employees
}
double getAverage (int employees, int absences)
{
// This function calculate the average of days of absence,
// i.e. absences / employees
// To avoid data loss, it turns those, which are ints, into doubles
// before performing any calculation.
turn employess into double
turn absences into double
return the ratio of absences to employees (both turned into doubles)
}
|