Programming language C++
Database System Concepts
7th Edition
ISBN:9780078022159
Author:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Chapter1: Introduction
Section: Chapter Questions
Problem 1PE
Related questions
Question
![A text file called hours.txt has been provided. Copy the text file into the folder of the project.
The lines of text in the text file contain the surname, list of hours spent on Facebook per day over a period of
7 days (one week) and job title of a number of employees.
Example of the content of the text file:
Simon
8234556
Manager
Johnson
1020103
Clerk
Peterson
6238126
Assistant
Pule
4568752
Manager
Note: Three lines of text contain the information of one employee.
3.1 Declare an array of Employee structs called arrEmp that must be able to hold the information of up to 30
employees. An employee struct must consist of the following fields: surname, hours (integer) and
manager (bool).
Use the following declaration (this declaration is compulsory and must be used):
5
struct Employee
ahar surname (20]
int hours:
bool manager
3.2 Write a method called readFromFile() that will receive the array and number of elements as parameters.
Read the data from the text file into the array. The Facebook hours must be read as an integer into the
hours-field. If the job title is a manager, the Boolean value of true must be assigned to the manager-
field. Otherwise the value of false must be assigned to the manager-field. Return the number of
elements (employees) saved in the array.
Note: The information of one employee is saved in three lines of text in the file.
Therefore you need three read instructions per employee.
3.3 Write a function called displayinfo() that will receive the array and the number of elements in the array.
Display the list of employees as shown in the example.
Example of output:
List of employees
Surname
Simon
Johnson
Peterson
Pule
Gumede
Green
Mokoena
Fourie
Hours
Manager
8234556
1020103
6238126
4568752
4536776
2310211
1
7683587
1
4342742
3.4 Write a function called calcTotal() that will receive an integer value (e.g. 8234526) and calculate and
return the total number of Facebook hours for the employee.
NOTE:
To calculate the total number of hours get each individual digit contained in the value received by
the function and add up the individual digit-values.
For this purpose use the % operator and / operator repetitively inside a for loop.
3.5 Write a function called displayTotalHours() that will receive the array and the number of elements
saved in the array as parameters. Inside a for loop, call the calcTotal() function to obtain the total hours
for each employee and display a numbered list with the surnames and total number of hours spent on
Facebook for each employee. Calculate and return the total number of hours spent on Facebook by all
the employees.
Example:
List of total Facebook hours per employee
Simon
2
33
Johnson
3
Peterson
28
14
Pule
15
Gumede
37
38
16
Green
10
17
Mokoena
44
18
Fourie
26](/v2/_next/image?url=https%3A%2F%2Fcontent.bartleby.com%2Fqna-images%2Fquestion%2Fef3b0792-0c88-49e2-ab96-8edcab6f3856%2F79cd03b9-f719-435a-8ae7-8402436bd0ae%2Fbri4p1_processed.jpeg&w=3840&q=75)
Transcribed Image Text:A text file called hours.txt has been provided. Copy the text file into the folder of the project.
The lines of text in the text file contain the surname, list of hours spent on Facebook per day over a period of
7 days (one week) and job title of a number of employees.
Example of the content of the text file:
Simon
8234556
Manager
Johnson
1020103
Clerk
Peterson
6238126
Assistant
Pule
4568752
Manager
Note: Three lines of text contain the information of one employee.
3.1 Declare an array of Employee structs called arrEmp that must be able to hold the information of up to 30
employees. An employee struct must consist of the following fields: surname, hours (integer) and
manager (bool).
Use the following declaration (this declaration is compulsory and must be used):
5
struct Employee
ahar surname (20]
int hours:
bool manager
3.2 Write a method called readFromFile() that will receive the array and number of elements as parameters.
Read the data from the text file into the array. The Facebook hours must be read as an integer into the
hours-field. If the job title is a manager, the Boolean value of true must be assigned to the manager-
field. Otherwise the value of false must be assigned to the manager-field. Return the number of
elements (employees) saved in the array.
Note: The information of one employee is saved in three lines of text in the file.
Therefore you need three read instructions per employee.
3.3 Write a function called displayinfo() that will receive the array and the number of elements in the array.
Display the list of employees as shown in the example.
Example of output:
List of employees
Surname
Simon
Johnson
Peterson
Pule
Gumede
Green
Mokoena
Fourie
Hours
Manager
8234556
1020103
6238126
4568752
4536776
2310211
1
7683587
1
4342742
3.4 Write a function called calcTotal() that will receive an integer value (e.g. 8234526) and calculate and
return the total number of Facebook hours for the employee.
NOTE:
To calculate the total number of hours get each individual digit contained in the value received by
the function and add up the individual digit-values.
For this purpose use the % operator and / operator repetitively inside a for loop.
3.5 Write a function called displayTotalHours() that will receive the array and the number of elements
saved in the array as parameters. Inside a for loop, call the calcTotal() function to obtain the total hours
for each employee and display a numbered list with the surnames and total number of hours spent on
Facebook for each employee. Calculate and return the total number of hours spent on Facebook by all
the employees.
Example:
List of total Facebook hours per employee
Simon
2
33
Johnson
3
Peterson
28
14
Pule
15
Gumede
37
38
16
Green
10
17
Mokoena
44
18
Fourie
26
![struat Employee
char surname [20]:
int hours
bool manager
3.2 Write a method called readFromFile() that will receive the array and number of elements as parameters.
Read the data from the text file into the array. The Facebook hours must be read as an integer into the
hours-field. If the job title is a manager, the Boolean value of true must be assigned to the manager-
field. Otherwise the value of false must be assigned to the manager-field. Return the number of
elements (employees) saved in the array.
Note: The information of one employee is saved in three lines of text in the file.
Therefore you need three read instructions per employee.
3.3 Write a function called displaylnfo() that will receive the array and the number of elements in the array.
Display the list of employees as shown in the example.
Example of output:
kist of employees
Surname
Simon
bohnson
Peterson
Pule
Gumede
Green
Mokoena
Fourie
Hours
Manager
8234556
1
1020103
6238126
4568752
4536776
1
2310211
7683587
4342742
3.4 Write a function called calcTotal() that will receive an integer value (e.g. 8234526) and calculate and
return the total number of Facebook hours for the employee.
NOTE:
To calculate the total number of hours get each individual digit contained in the value received by
the function and add up the individual digit-values.
For this purpose use the % operator and / operator repetitively inside a for loop.
3.5 Write a function called displayTotalHours() that will receive the array and the number of elements
saved in the array as parameters. Inside a for loop, call the calcTotal() function to obtain the total hours
for each employee and display a numbered list with the surnames and total number of hours spent on
Facebook for each employee. Calculate and return the total number of hours spent on Facebook
the employees.
all
Example:
List of total Facebook hours per employee
1
Simon
33
2
Johnson
3
Peterson
28
4
15
6
17
Pule
37
Gumede
38
Green
10
Mokoena
Fourie
44
26
6.
3.6 Write a function called writeToFile() that will receive the array and the number of elements that the
array contains as parameters. Write the surname and total number of Facebook-hours of employees
who spent more than 20 hours on Facebook to a text file called warnings.txt. Managers are excluded
from this condition. Therefor the names of managers who spent more than 20 hours on Facebook must
not be written to the warnings text file.
Example of the content of the warnings.txt file:
awarnings - Notepad
File Ede Fomat View Help
Peterson : 28
Gumede : 38
Fourie : 26](/v2/_next/image?url=https%3A%2F%2Fcontent.bartleby.com%2Fqna-images%2Fquestion%2Fef3b0792-0c88-49e2-ab96-8edcab6f3856%2F79cd03b9-f719-435a-8ae7-8402436bd0ae%2F54dtktc_processed.jpeg&w=3840&q=75)
Transcribed Image Text:struat Employee
char surname [20]:
int hours
bool manager
3.2 Write a method called readFromFile() that will receive the array and number of elements as parameters.
Read the data from the text file into the array. The Facebook hours must be read as an integer into the
hours-field. If the job title is a manager, the Boolean value of true must be assigned to the manager-
field. Otherwise the value of false must be assigned to the manager-field. Return the number of
elements (employees) saved in the array.
Note: The information of one employee is saved in three lines of text in the file.
Therefore you need three read instructions per employee.
3.3 Write a function called displaylnfo() that will receive the array and the number of elements in the array.
Display the list of employees as shown in the example.
Example of output:
kist of employees
Surname
Simon
bohnson
Peterson
Pule
Gumede
Green
Mokoena
Fourie
Hours
Manager
8234556
1
1020103
6238126
4568752
4536776
1
2310211
7683587
4342742
3.4 Write a function called calcTotal() that will receive an integer value (e.g. 8234526) and calculate and
return the total number of Facebook hours for the employee.
NOTE:
To calculate the total number of hours get each individual digit contained in the value received by
the function and add up the individual digit-values.
For this purpose use the % operator and / operator repetitively inside a for loop.
3.5 Write a function called displayTotalHours() that will receive the array and the number of elements
saved in the array as parameters. Inside a for loop, call the calcTotal() function to obtain the total hours
for each employee and display a numbered list with the surnames and total number of hours spent on
Facebook for each employee. Calculate and return the total number of hours spent on Facebook
the employees.
all
Example:
List of total Facebook hours per employee
1
Simon
33
2
Johnson
3
Peterson
28
4
15
6
17
Pule
37
Gumede
38
Green
10
Mokoena
Fourie
44
26
6.
3.6 Write a function called writeToFile() that will receive the array and the number of elements that the
array contains as parameters. Write the surname and total number of Facebook-hours of employees
who spent more than 20 hours on Facebook to a text file called warnings.txt. Managers are excluded
from this condition. Therefor the names of managers who spent more than 20 hours on Facebook must
not be written to the warnings text file.
Example of the content of the warnings.txt file:
awarnings - Notepad
File Ede Fomat View Help
Peterson : 28
Gumede : 38
Fourie : 26
Expert Solution

This question has been solved!
Explore an expertly crafted, step-by-step solution for a thorough understanding of key concepts.
Step by step
Solved in 2 steps

Knowledge Booster
Learn more about
Need a deep-dive on the concept behind this application? Look no further. Learn more about this topic, computer-science and related others by exploring similar questions and additional content below.Recommended textbooks for you

Database System Concepts
Computer Science
ISBN:
9780078022159
Author:
Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:
McGraw-Hill Education

Starting Out with Python (4th Edition)
Computer Science
ISBN:
9780134444321
Author:
Tony Gaddis
Publisher:
PEARSON

Digital Fundamentals (11th Edition)
Computer Science
ISBN:
9780132737968
Author:
Thomas L. Floyd
Publisher:
PEARSON

Database System Concepts
Computer Science
ISBN:
9780078022159
Author:
Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:
McGraw-Hill Education

Starting Out with Python (4th Edition)
Computer Science
ISBN:
9780134444321
Author:
Tony Gaddis
Publisher:
PEARSON

Digital Fundamentals (11th Edition)
Computer Science
ISBN:
9780132737968
Author:
Thomas L. Floyd
Publisher:
PEARSON

C How to Program (8th Edition)
Computer Science
ISBN:
9780133976892
Author:
Paul J. Deitel, Harvey Deitel
Publisher:
PEARSON

Database Systems: Design, Implementation, & Manag…
Computer Science
ISBN:
9781337627900
Author:
Carlos Coronel, Steven Morris
Publisher:
Cengage Learning

Programmable Logic Controllers
Computer Science
ISBN:
9780073373843
Author:
Frank D. Petruzella
Publisher:
McGraw-Hill Education