2.3 Task 3 [3 marks] In the staff.c file, there is a function called "enter_staff_info ()". Modify the function to store

Business, Finance, Economics, Accounting, Operations Management, Computer Science, Electrical Engineering, Mechanical Engineering, Civil Engineering, Chemical Engineering, Algebra, Precalculus, Statistics and Probabilty, Advanced Math, Physics, Chemistry, Biology, Nursing, Psychology, Certifications, Tests, Prep, and more.
Post Reply
answerhappygod
Site Admin
Posts: 899603
Joined: Mon Aug 02, 2021 8:13 am

2.3 Task 3 [3 marks] In the staff.c file, there is a function called "enter_staff_info ()". Modify the function to store

Post by answerhappygod »

2 3 Task 3 3 Marks In The Staff C File There Is A Function Called Enter Staff Info Modify The Function To Store 1
2 3 Task 3 3 Marks In The Staff C File There Is A Function Called Enter Staff Info Modify The Function To Store 1 (10.07 KiB) Viewed 126 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.3 Task 3 [3 marks] In the staff.c file, there is a function called "enter_staff_info ()". Modify the function to store information in the structure in Task 2 using "scanf ()" function.
Join a community of subject matter experts. Register for FREE to view solutions, replies, and use search function. Request answer by replying!
Post Reply