QuestionQuestion

Transcribed TextTranscribed Text

In this assignment, you will make practice reading and writing information to/from both text and binary files. We will be writing code that reads in a file of records representing employee absences in a small company of 36 employees. The ultimate goal is to write a piece of A.I. software that will attempt to estimate the likelihood of an employee being sick or absent based on various parameters. However, in this assignment, we are just interested in reading in the file, extracting some relevant data, re- writing it to another file and then re-reading that data and showing some statistics. There are 740 records. Each record is a single line that contains the following information from a single absence “episode”: • ID – the employee’s ID ... a number from 1 to 36 • Reason for Absence – an integer indicating the reason for being absent, number from 1-28: Absences attested by the International Code of Diseases (ICD) stratified into 21 categories (I to XXI) as follows: I Certain infectious and parasitic diseases II Neoplasms III Diseases of the blood and blood-forming organs and certain disorders involving the immune mechanism IV Endocrine, nutritional and metabolic diseases V Mental and behavioural disorders VI Diseases of the nervous system VII Diseases of the eye and adnexa VIII Diseases of the ear and mastoid process IX Diseases of the circulatory system X Diseases of the respiratory system XI Diseases of the digestive system XII Diseases of the skin and subcutaneous tissue XIII Diseases of the musculoskeletal system and connective tissue XIV Diseases of the genitourinary system XV Pregnancy, childbirth and the puerperium XVI Certain conditions originating in the perinatal period XVII Congenital malformations, deformations and chromosomal abnormalities XVIII Symptoms, signs and abnormal clinical and laboratory findings, not elsewhere classified XIX Injury, poisoning and certain other consequences of external causes XX External causes of morbidity and mortality XXI Factors influencing health status and contact with health services. And 7 categories without (CID) patient follow-up (22), medical consultation (23), blood donation (24), laboratory examination (25), unjustified absence (26), physiotherapy (27), dental consultation (28). • Month of Absence – a number from 1 to 12, where Jan = 1 and Dec = 12 • Day of the Week – a number where 2=Mon, 3=Tues, 4=Wed, 5=Thurs, 6 = Fri • Season – a number ... 1=Winter, 2=Spring, 3=Summer, 4=Fall • Transportation Expense – an integer representing the monthly cost of transportation to work • Distance from Residence to Work – an integer representing the km traveled to work • Service Time – number of years worked at the company • Age – the age of the employee • Workload Average/day – float indicating the normal minutes worked per day by the employee • Hit Target – an estimate of their performance ... a percentage • Disciplinary Failure – 1 if has been disciplined, 0 otherwise • Education – 1=high school, 2=graduate, 3=postgraduate, 4=masters or doctorate • Number of Children – number of children the employee has • Social Drinker – 1 if yes, 0 if no • SocialSmoker–1ifyes,0ifno • Number of Pets - – number of pets the employee has • Weight – integer (Kg) • Height – integer (cm) • Body Mass Index – an integer • Hours Absent – hours absent during this episode Part 1 Download the file called absenteeism.txt. It contains a header line, followed by 740 records. Write a program called textToBinary.c that will read in this text file, extract some data from it and then re- write it to a new file called absenteeism.bin. Here is what you need to do: 1. Make sure that you open the text file for reading and close it when you are done. You must also check for errors in opening the file and use printf to indicate if an error has occurred. 2. You must open the binary file for writing, and also close it when you are done. You must check for errors as well in case the file cannot be created. Each time you run the code, the binary file must be overwritten. 3. The binary file must begin with an unsigned short int indicating how many records have been read in from the text file. You MUST NOT hard-code the number. It must be computed by reading through the entire text file once to determine how many records are in there. Thus, your program should work properly regardless of the number of records in the text file. 4. The program must read in all the records until none remain. 5. Thebinaryfilewillcontainrecordinformationinthesameorderasthetextfile,howeversome of the text file data will be ignored and not written to the binary file. Also, you will reformat some of the data as explained below: • The ID should be written as an unsigned char. • The Reason For Absence should be ignored. • The Month and Day of Week should each be written as a char. • The Season should be written as the char ‘W’, ‘P’, ‘S’ or ‘F’ based on whether the text file had the number 1, 2, 3 or 4, respectively. • The Transportation Expense, Distance from Residence to Work and Service Time should all be ignored. • The Age should be written as an unsigned char. • The Workload Average/day, Hit Target and Disciplinary Failure should all be ignored. • The Education should be written as the char ‘HS’, ‘GR’, ‘PG’ or ‘MD’ based on whether the text file had the number 1, 2, 3 or 4, respectively. • The Number of Children should be written as an unsigned char. • The Social Drinker should be written as ‘Y’ if 1 or ‘N’ if 0. • The Social Smoker should be written as ‘Y’ if 1 or ‘N’ if 0. • The Number of Pets should be written as an unsigned char. • The Weight and Height should be ignored. • The Body Mass Index should be written as an unsigned char. • The Hours Absent should be written as an unsigned char. The original text file should be exactly 44,491 bytes in size. The final absenteeism.bin file MUST be 10,362 bytes in size. You can use ls -l to confirm the file sizes. Part 2 Write a program called healthAssessment.c while reads in the absenteeism.bin file that you just created and prints out the information below exactly (including formatting) ... which MUST be based on the values that you read in from the file. For the CATEGORY, a person is “Underweight” if their Body Mass Index < 18.5 ... if >25 and <=30 then they are “Overweight”. If above 30, then they are “Obese”. The file contains absenteeism episodes for employees more than once ... at different dates. As a result, some of the data may change from instance to instance. One example of this is that the Body Mass Index was found to be different for the same employee from one episode to the next. You should use the record that is closest to the end of the file as the data to be used. For example, if an employee ID appears a few times in the file ... the Personal Data (i.e., age, education, numChildren, socialDrinker, socialSmoker, numPets, bodyMassIndex, totalHoursAbsent) should be taken from the last episode that this employee has in the file. The file contains 740 records Individual Employee Data: ------------------------- ID ABSENT AGE SMOKER DRINKER #CH #PT CATEGORY EDU ------------------------------------------------------------------ 348238 1447634 11 450 33 2834728 34 344 37 3631150 2030636 926258 2425441 1525340 2225330 10 186 28 1318331 17 126 40 Y 112137 1811828 510443 268343 Y 337347 67233 254232 234036 Y 123431 303129 Y Y00ObeseHS Y20 HS Y 2 1 Overweight HS 12 HS 0 0 Overweight HS Y10ObeseHS Y40 21 Y00 Y11 00 Y 1 4 Y30 20 11 00 Y 10 Y 21 21 22 00 24 Y18 Y00 HS HS HS HS PG Overweight HS HS GR Overweight PG GR Obese HS HS Obese HS HS PG HS GR HS 73039YY20 HS 272727 2 25 48 292141 311650 321649 161646 211633 19 6 32 4 0 40 35053 8 0 39 Y 00 HS 1 5 Obese HS Y22OverweightMD Grand Total Hours Absent: 5124 Hours absent based on weekday: ------------------------------ Sat: 0 Sun: 0 Mon: 1489 Tue: 1229 Wed: 1115 Thu: 553 Fri: 738 Hours absent based on season: ----------------------------- Winter: 1241 Spring: 1152 Summer: 1492 Fall : 1239 Hours absent based on month: ---------------------------- Jan: 222 Feb: 294 Mar: 765 Apr: 482 May: 400 Jun: 411 Jul: 734 Aug: 288 Sep: 292 Oct: 349 Nov: 473 Dec: 414 Y Y 00 02 20 00 HS Obese HS HS GR HS Obese HS HS Obese HS Y 0 0 Y 18 11 Y 22 Here are the steps that you MUST follow to make this happen: • You must read in the absenteeism.bin file, not the absenteeism.txt. • You must use the following struct to hold onto an employee’s personal data: typedef struct { unsigned char unsigned char char unsigned char char char unsigned char id; age; education[3]; numChildren; socialDrinker; socialSmoker; numPets; unsigned char bodyMassIndex; unsigned short int totalHoursAbsent; } PersonalData; • You must use the following struct to hold onto a single episode of absenteeism: typedef struct { unsigned char char char char id; month; dayOfWeek; season; unsigned short int hoursAbsent; } AbsentEpisode; • You must dynamically allocate space to read in and store the personal information for the 36 employees. You should make an array of 36 PersonalData pointers, but each pointer will point to the dynamically-allocated space for a single person. • You should read in all of the absentee episodes. For each one, you should allocate space to store the AbsentEpisode information. You should make an array of up to 1000 AbsentEpisode pointers, where each pointer will point to the dynamically-allocated space for a single absenteeism episode. • You must go through all the episodes and determine how many hours each employee has been absent and then sort them in order of most absent to least absent, as shown in the above output. • You must display the grand total of hours absent for all employees together and then display the table of employee information as shown in the above output. • You must then display the Hours absent base don the weekday, season and month as shown in the above output. • You should then free up all allocated memory and close any opened files. You can use valgrind --leak-check=yes ./healthAssessment to check for memory leaks and to make sure that you have not overwritten any memory locations. ________________________________________________________________________________ IMPORTANT SUBMISSION INSTRUCTIONS: Submit all of your c source code files as a single tar file containing: 1. A Readme text file containing • your name and studentNumber • a list of source files submitted • any specific instructions for compiling and/or running your code 2. All of your .c source files and all other files needed for testing/running your programs. 3. Any output files required, if there are any.

Solution PreviewSolution Preview

These solutions may offer step-by-step problem-solving explanations or good writing examples that include modern styles of formatting and construction of bibliographies out of text citations and references. Students may use these solutions for personal skill-building and practice. Unethical use is strictly forbidden.

#include <stdio.h>
#include <stdlib.h>
#include <string.h>

struct employee {
    // The ID should be written as an unsigned char.
    unsigned char ID;
    // The Reason For Absence should be ignored.

    // The Month and Day of Week should each be written as a char.
    char month;
    char week_day;
    // The Season should be written as the char "W", "P", "S" or "F"
    // based on whether the text file had the number 1, 2, 3 or 4,
    // respectively.
    char season;
    // The Transportation Expense, Distance from Residence to Work and Service Time should all be ignored.

    // The Age should be written as an unsigned char.
    unsigned char age;
    // The Workload Average/day, Hit Target and Disciplinary Failure
    // should all be ignored.

    // The Education should be written as the char "HS", "GR", "PG" or "MD"
    // based on whether the text file had the number 1, 2, 3 or 4,
    // respectively.
    char education[3];

    // The Number of Children should be written as an unsigned char.
    unsigned char children_num;
    // The Social Drinker should be written as "Y" if 1 or "N" if 0.
    char social_drinker;
    // The Social Smoker should be written as "Y" if 1 or "N" if 0.
    char social_smoker;
    // The Number of Pets should be written as an unsigned char.
    unsigned char pet_num;
    // The Weight and Height should be ignored.

    // The Body Mass Index should be written as an unsigned char.
    unsigned char bmi;
    // The Hours Absent should be written as an unsigned char.
    unsigned char hour_absent;
};

typedef struct employee employee;

// You must use the following struct to hold onto an employee’s personal data:

typedef struct {
    unsigned char id;
    unsigned char age;
    char education[3];
    unsigned char numChildren;
    char socialDrinker;
    char socialSmoker;
    unsigned char numPets;
    unsigned char bodyMassIndex;
    unsigned short int totalHoursAbsent;
} PersonalData;

// You must use the following struct to hold onto a single episode of absenteeism:

typedef struct {
    unsigned char id;
    char month;
    char dayOfWeek;
    char season;
    unsigned short int hoursAbsent;
} AbsentEpisode;...

By purchasing this solution you'll be able to access the following files:
Solution.zip.

$92.00
for this solution

or FREE if you
register a new account!

PayPal, G Pay, ApplePay, Amazon Pay, and all major credit cards accepted.

Find A Tutor

View available C-Family Programming Tutors

Get College Homework Help.

Are you sure you don't want to upload any files?

Fast tutor response requires as much info as possible.

Decision:
Upload a file
Continue without uploading

SUBMIT YOUR HOMEWORK
We couldn't find that subject.
Please select the best match from the list below.

We'll send you an email right away. If it's not in your inbox, check your spam folder.

  • 1
  • 2
  • 3
Live Chats