Page 1 of 1

2.4 Task 4 [3 marks] In staff.c file, there is a function called "print_staff_info()". Modify the contents of the functi

Posted: Tue Jul 12, 2022 8:05 am
by answerhappygod
2 4 Task 4 3 Marks In Staff C File There Is A Function Called Print Staff Info Modify The Contents Of The Functi 1
2 4 Task 4 3 Marks In Staff C File There Is A Function Called Print Staff Info Modify The Contents Of The Functi 1 (45.51 KiB) Viewed 205 times
/*=======================================================================================* * File: staff.c * ---------------------------- * .c file of staff library. All function prototype instaff.h. * * You can add local functions if required. Insert theprototype and implementations * between the marked lines. * *=======================================================================================*/
#include <stdio.h>#include "staff.h"
struct StaffInfo loaded_staff_data[10]/* Remove this line and line 23 to uncomment if required = {{123, "Raju Abhijit", "Ipoh", 2020, "Junior Engineer",3000}, {104, "Sharifah Al-Amir", "Kuala Lumpur", 2019,"Engineer", 3500}, {254, "Sanjana Suman", "Jeli", 2016, "HR Officer",4750}, {256, "Chin Qiang Lian", "Tawau", 2021, "SiteEngineer", 2500}, {165, "Yahya Hamid", "Rasa", 2016, "Senior Engineer",8750}, {155, "Jeremy Chew", "Bintangor", 2020, "LogisticsOfficer", 3000}, {654, "Mohamad Ali", "Ipoh", 2018, "Secretary",3500}, {855, "Eu Sze Kuan", "Kemaman", 2017, "Accountant",7000}, {655, "Stanley Khoo", "Dungun", 2020, "SafetyOfficer", 4000}, {654, "Amir Hamzah", "Rasa", 2019, "Technician",3500}} * Remove this line and line 12 to uncomment */;
/*********** Local Function Prototype and Implementation***********//* You can add local function prototypes and implementation below *//*******************************************************************///<------------------- START editing here------------------------>//
//<-------------------- STOP editing here------------------------>////----- End of Local Function Prototypes and Implementations-------/
/*---------------------------------------------------------------------------------------* * Function: open_file * -------------------- * Opens a file named with your matric number. Do not closethe created file * * Arguments: None * * Returns: File pointer to created file (do not edit) * Returns NULL if filecreation fails * * IMPORTANT! Only edit between the marked lines. DO NOT CLOSETHE CREATED FILE. *---------------------------------------------------------------------------------------*/FILE *open_file(void) { FILE *fp = NULL; //<---------------------- START editing here-------------------->//
//<----------------------- STOP editing here-------------------->// return fp;}
/*---------------------------------------------------------------------------------------* * Function: enter_staff_info * -------------------- * Enters staff info in the structure. THe main function willcall this function every * time there is a new staff info to be entered. You DO NOThave to iterate for multiple * staff data entry. * * Arguments: struct StaffInfo pointer - points to staff infoin StaffInfo structure * * Returns: None * * IMPORTANT! Only edit between the marked lines. *---------------------------------------------------------------------------------------*/void enter_staff_info(struct StaffInfo *staff_info) { printf("Begin staff info entry...\n\n"); //<---------------------- START editing here-------------------->//
//<----------------------- STOP editing here-------------------->//}
/*---------------------------------------------------------------------------------------* * Function: print_staff_info * -------------------- * Prints newly entered staff info from the StaffInfostructure. This function will be * called by the main function for every staff info entered.You DO NOT have to iterate * to print multiple staff info. * * Arguments: struct StaffInfo - staff info structure * * Returns: None * * IMPORTANT! Only edit between the marked lines. *---------------------------------------------------------------------------------------*/void print_staff_info(struct StaffInfo staff_info) { printf("\n\nPrinting new staff info...\n\n"); //<---------------------- START editing here-------------------->//
//<----------------------- STOP editing here-------------------->//}
/*---------------------------------------------------------------------------------------* * Function: store_staff_info * -------------------- * Stores newly entered staff info into file. The mainfunction will call this function * for every staff info entered. You DO NOT have to iteratefor every staff info. * * Arguments: FILE *fp - pointer to file where the informationwill be stored * struct StaffInfo -structure containing staff info * * Returns: None * * IMPORTANT! Only edit between the marked lines. *---------------------------------------------------------------------------------------*/void store_staff_info(FILE *fp, struct StaffInfo staff_info){ printf("\n\nStoring new staff info infofile...\n\n"); //<---------------------- START editing here-------------------->//
//<----------------------- STOP editing here-------------------->//}
/*---------------------------------------------------------------------------------------* * Function: load_staff_file * -------------------- * Loads staff information file. This function should openexisting staff info file and * inserts it into the struct StaffInfo loaded_staff_data[10]array as declared at the * top of this (staff.c) file. * * If you choose to skip implementation of this function, youcan proceed with next task * by uncommenting lines 15 - 26 above (delete line 15 and26). You may need to change * your struct StaffInfo elements to accommodate the defaultdata. * * Arguments: None * * Returns: File pointer to created file (do not edit) * Returns NULL if filecreation fails * * IMPORTANT! Only edit between the marked lines. *---------------------------------------------------------------------------------------*/FILE *load_staff_file(void) { FILE *fp = NULL; // Variable to store file pointer to the opened staffinfo // file
printf("\nStarting staff info fileload...\n\n"); //<---------------------- START editing here-------------------->//
//<----------------------- STOP editing here-------------------->// return fp;}
/*---------------------------------------------------------------------------------------* * Function: calculate_salary_difference * -------------------- * Calculates salary difference of staff compared to staffsalary based on experience. The * expected salary can be calculated as follows: * Expected salary = basic *(1.1)^(years of experience) * This function stores all the information of the staff intothe file created in * open_file(). * * Arguments: FILE *fp - file pointer to the created file inopen_file * int new_staff_no -total number of new staff info added * struct StaffInfo*staff_info - pointer to an array of StaffInfo structure. * You have to iterate through the array elements toaccess each staf * info. * * Returns: None * * IMPORTANT! Only edit between the marked lines. *---------------------------------------------------------------------------------------*/void calculate_salary_difference (FILE *fp, int new_staff_no,struct StaffInfo *staff_info) { printf("\nCalculating staff salarydifference...\n\n"); //<---------------------- START editing here-------------------->// if (new_staff_no == 0) { // process only loaded data
} else { // process both entered and loadeddata
} //<----------------------- STOP editing here-------------------->//}
2.4 Task 4 [3 marks] In staff.c file, there is a function called "print_staff_info()". Modify the contents of the function to print all the information stored in the structure in the terminal. An example output is as in Figure 4. Use your creativity to make the display easy to read and interesting. Done correctly, the program should print all newly entered staff info in "enter_staff_info ()" (Task 3) function. You are encouraged to explore the main.c file to see how it works. To print staff info, enter P. To skip printing staff info, enter "E". To terminate program, enter 'T'. Р Printing new staff info... Name: Ahmad Albab Date of Birth: 12 June 1999 City of Birth: Malau Year of joining Company: 2929 Job title: Logistics Engineer Monthly Salary: RM4000 Figure 4. Example staff info print out.