2.6 Task 6 You are tasked to create a software to compare the current staff salary with expected salary. All of the task
Posted: Tue Jul 12, 2022 8:05 am
#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.6 Task 6 You are tasked to create a software to compare the current staff salary with expected salary. All of the tasks (a) to (d) should be done in the function "calculate_salary_difference ()". The formula to calculate expected salary is as follows: Expected salary = basic* (1.1)(years in company) where basic = RM2,500. The salary difference is Salary difference Expected salary - Actual salary a. [4 marks] Modify the function "calculate_salary_difference ()" to calculate the difference of expected salary and actual salary of each staff. The difference should be calculated as Salary difference = Expected salary - Staff Salary. b. [2 marks] Modify the "StaffInfo" structure to include expected salary and salary difference for each staff information as elements of the structure. c. [5 marks] In the file you created, print the Full Name, Salary and Salary Difference of all staff, including the newly entered staff in Task 5. Format the file so the information is readable. Use your creativity to print the result in the file to make it readable.