Problem Definition You are provided with a text file (employees.txt) containing a number of text lines. Each line contains a record of one employee. Each record has three attributes: Title: string, Prof. (Professor) or Dr. (Doctor). First and Last names: string. Salary: float number. The attributes are separated by the character (','). Figure 1.a, 1.b, and 1.c show a sample of employees.txt files.

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
icon
Related questions
Topic Video
Question
Problem Definition
You are provided with a text file (employees.txt) containing a number of text lines. Each line contains a record of one
employee. Each record has three attributes:
Title: string, Prof. (Professor) or Dr. (Doctor).
First and Last names: string.
Salary: float number.
The attributes are separated by the character (','). Figure 1.a, 1.b, and 1.c show a sample of employees.txt files.
Dr., Julia Scott,141518
Prof.,Joan Stewart,111673
Mr.,Ali Al-Shukaili,122311
Prof.,Sana Al-Abri,131673
Dr.,Fadi Al-Rasdhi,153790
Ms., Salwa Al-Youssfi, 111675
Dr.,Lillian Brown,67251
Dr.,Julia Scott,141518
Prof.,Joan Stewart
Dr., Daniel Cooper,153790
Dr.,Lillian Brown,unknown
Dr., Daniel Cooper,153790
Dr.,Lillian Brown,67251
Dr.,Benjamin Russel1,117642
Prof.,Patrick Bailey,72305
Dr., Ralph Flores,118457
Dr., Douglas Flores,181793
Dr.:Benjamin Russell:117642
Figure 1.b: A sample of the text file 'employees.txt
Figure 1.a: A sample of the text file
'employees.txt without errors
Figure 1.c: A sample of the text file
'employees.txt' including 3 invalid records
including 2 records with incorrect titles
You are requested to write a Python program that reads the contents of the text file, saves the titles, the names and the
salaries of employees in three lists and computes the average salary per title as well as the average for all employees.
Your program should display the employees per titles, the number of employees of each title, the average salary of each
title, the average for all employees, as well as the number of records with invalid title, and the number of invalid record as
shown in Figure 2.a, 2.b, and 2.c:
Salaries per category:
Salaries per category:
Salaries per category:
Name
Salary
Name
Salary
Name
Salary
Prof.
Joan Stewart
111673.00
Prof.
=- - ===--
Patrick Bailey
72305.00
Sana Al-Abri
131673.00
Dr.
141518.00
153790.00
The average salary of 2 Prof. is: 91989. 00
Julia Scott
The average salary of 1 Prof. is: 131673.00
Daniel Cooper
Dr.
Julia Scott
Daniel Cooper
141518.00
Dr.
The average salary of 2 Dr. is: 147654.00
153790.00
67251.00
117642.00
Fadi Al-Rasdhi
153790.00
Lillian Brown
Lillian Brown
67251.00
Benjamin Russell
Ralph Flores
Douglas Flores
The number of records having incorrect title is 0
118457.00
The average salary of 2 Dr. is: 110520.50
The number of invalid records is 3
181793.00
The number of records having incorrect title is 2
The number of invalid records is 0
The average salary of 6 Dr. is: 130075.17
The number of records having incorrect title is 0
The number of invalid records is 0
Figure 2.a: The output of the program
related to input file of figure 1.a
Figure 2.b: The output of the program
related to input file of figure 1.b
Figure 2.c: The output of the program
related to input file of figure 1.c
Transcribed Image Text:Problem Definition You are provided with a text file (employees.txt) containing a number of text lines. Each line contains a record of one employee. Each record has three attributes: Title: string, Prof. (Professor) or Dr. (Doctor). First and Last names: string. Salary: float number. The attributes are separated by the character (','). Figure 1.a, 1.b, and 1.c show a sample of employees.txt files. Dr., Julia Scott,141518 Prof.,Joan Stewart,111673 Mr.,Ali Al-Shukaili,122311 Prof.,Sana Al-Abri,131673 Dr.,Fadi Al-Rasdhi,153790 Ms., Salwa Al-Youssfi, 111675 Dr.,Lillian Brown,67251 Dr.,Julia Scott,141518 Prof.,Joan Stewart Dr., Daniel Cooper,153790 Dr.,Lillian Brown,unknown Dr., Daniel Cooper,153790 Dr.,Lillian Brown,67251 Dr.,Benjamin Russel1,117642 Prof.,Patrick Bailey,72305 Dr., Ralph Flores,118457 Dr., Douglas Flores,181793 Dr.:Benjamin Russell:117642 Figure 1.b: A sample of the text file 'employees.txt Figure 1.a: A sample of the text file 'employees.txt without errors Figure 1.c: A sample of the text file 'employees.txt' including 3 invalid records including 2 records with incorrect titles You are requested to write a Python program that reads the contents of the text file, saves the titles, the names and the salaries of employees in three lists and computes the average salary per title as well as the average for all employees. Your program should display the employees per titles, the number of employees of each title, the average salary of each title, the average for all employees, as well as the number of records with invalid title, and the number of invalid record as shown in Figure 2.a, 2.b, and 2.c: Salaries per category: Salaries per category: Salaries per category: Name Salary Name Salary Name Salary Prof. Joan Stewart 111673.00 Prof. =- - ===-- Patrick Bailey 72305.00 Sana Al-Abri 131673.00 Dr. 141518.00 153790.00 The average salary of 2 Prof. is: 91989. 00 Julia Scott The average salary of 1 Prof. is: 131673.00 Daniel Cooper Dr. Julia Scott Daniel Cooper 141518.00 Dr. The average salary of 2 Dr. is: 147654.00 153790.00 67251.00 117642.00 Fadi Al-Rasdhi 153790.00 Lillian Brown Lillian Brown 67251.00 Benjamin Russell Ralph Flores Douglas Flores The number of records having incorrect title is 0 118457.00 The average salary of 2 Dr. is: 110520.50 The number of invalid records is 3 181793.00 The number of records having incorrect title is 2 The number of invalid records is 0 The average salary of 6 Dr. is: 130075.17 The number of records having incorrect title is 0 The number of invalid records is 0 Figure 2.a: The output of the program related to input file of figure 1.a Figure 2.b: The output of the program related to input file of figure 1.b Figure 2.c: The output of the program related to input file of figure 1.c
Expert Solution
steps

Step by step

Solved in 2 steps with 3 images

Blurred answer
Knowledge Booster
Instruction Format
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.
Similar questions
  • SEE MORE QUESTIONS
Recommended textbooks for you
Database System Concepts
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)
Starting Out with Python (4th Edition)
Computer Science
ISBN:
9780134444321
Author:
Tony Gaddis
Publisher:
PEARSON
Digital Fundamentals (11th Edition)
Digital Fundamentals (11th Edition)
Computer Science
ISBN:
9780132737968
Author:
Thomas L. Floyd
Publisher:
PEARSON
C How to Program (8th Edition)
C How to Program (8th Edition)
Computer Science
ISBN:
9780133976892
Author:
Paul J. Deitel, Harvey Deitel
Publisher:
PEARSON
Database Systems: Design, Implementation, & Manag…
Database Systems: Design, Implementation, & Manag…
Computer Science
ISBN:
9781337627900
Author:
Carlos Coronel, Steven Morris
Publisher:
Cengage Learning
Programmable Logic Controllers
Programmable Logic Controllers
Computer Science
ISBN:
9780073373843
Author:
Frank D. Petruzella
Publisher:
McGraw-Hill Education