Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Please solve it in C++ and make sure to run it to see if it works because I posted it and the answer was incorrect,

Please solve it in C++ and make sure to run it to see if it works because I posted it and the answer was incorrect, so I'm posting it again.
image text in transcribed
image text in transcribed
image text in transcribed
image text in transcribed
image text in transcribed
image text in transcribed
Write a program that manages the keys owned by the individual employees of a department. The program first loads the key information from a file then supports (1) print out all the employees and their lists of keys: (2) print out the list of keys of a particular employee; (3) print out the employees' names who have a specific key; (4) add a new key to a specific employee; (5) return a key by an employee; and (6) save the current key information to a file. To achieve this, you need to create a struct named eeployee that contains the following member variables: - name, a string that holds the name of an employee (that may contain whitespaces) - nkeyspossessed, an integer that stores the number of keys an employee owns - keys, a string array with 5 elementa Each element stores the room that the key can opens, e.g, "AHC201" The key information of the individual employees is stored in a text file. Write a reader () function to load the key information and store it in an Employee array. This function should take a string for the filename, an array of Employee array, and the number of employees (should be. passed in as reference) as input. The function will attempt to open the input file. If the input file does not exist (or cannot be opened), the function returns false. Otherwise, the function will ioad the key information, then return true. The function deciaration should iook like bool reader (string input filename. Employee enployees [1, int \& nployees): The text file storing the key information has the following format knumber of employeess 1 s keyls kenployee 1 s key 2> cnumber of keys erpioyee I possessess cenployee I's keyls cemployee 1 . 3 key 2>... 2 s names 2 ' keyl comployee 2 ' 3 key 2> The following is an exarrple input key file 2 Ya Hoo 3 AHCt 2 ABC200 AHC111 MLChael Loo 2. AHC303 AHC200 Next, implement a writer() function to output the cufent key information a specified output fie, This function will take the same parameters as the above reader () function except that the last integer does not use pass by reference. This function should be declared as follows void writer (atring output_filenane, Enployeo employeesil, int nemployees); Now, implement two functions. The firat function addkeyforfmployee() will add a new key to a specified employee. This function will take the Employee array, the number of total employees, the specilied employees name, and the room number the that the new key opens as input. The function then searches the employee based on the input name in the Employee array, If the specified employee is not found, the function wil print out "Cannot find the specified enployee!" and retum false if the specified employte is found but already possesses 5 keys, the function will print out "This employee already has 5 keys!" and return false if the employee has iess than 5 function will print out "Cannot find the specified eeployee1" and refurn false. If the specified employee is found but already possesses 5 keys, the function will print out "This enployee already has 5 keys!" and return fal se if the employee has less than 5 keys, but one of these keys is the same as the new key (based on their respective room numbers), the progam will print out "This enployee already has this key!" and retum false. Otherwse, the new key will be added to the end of the keys array of the employee and the number of the keys that employee has will be increased by one. The function then teturns a true. This function should be declared as follows. bool adakeyForEmployee (Esployee employees[1. Int nkmployees, string enp_name, string newkey), The next function returnakey () will return (or remove) a key fot a specified employec. This function takes exactly the same list of parameters as the above addkeyforEnployee() function. This function then searches the employee based on the input name in the Employee array. If the specified employee is not found, the function will print out "Cannot find the specified eaployeel" and return false. If the specified employee is found but does not possess the specifed key, the function will print out "This employee does not have the specified key!" and retum false. Otherwise, the specifed key will be removed from the list of keys that this employee has, and the total number of keys this employee has will decrease by 1 . Note that this key maybe located in the middie of the keys array and the removal shouk not leave out an empty spot in the middle of the srray. This function shoukd be deciared as foliows. bool returndkey (Zniploye employees (l, int nknployees, string enp_name, string returnkey); in the main() function, do the following - Print cut "please enter key file name to start: ", then accept user input of a flename; - Call the reader () function to load the file. if the function returns false (ie, the file doesnit exit), print out "File not found, exiting the program..." and ext the program: - Call the reader () function to load the file. If the function returns false (ie, the file doesnt exit) print out "File not found, exiting the program..." and eut the program; - If the file is loaded successfully, the program wil print out the following menu in a loop. This loop will repeat until the user selects the exit option (li.e, option 7) Please select froe the folloking options: 1. thow ail employees and the Ir keya 2. show the keys an employee possesses 3. thon which eaployees posnest a specifie koy 4. add a key to an enployee 5. Lotura a key by an employee 6. Have the current key itatue 7. exit the progran - If the ube selects an option not listed above, print "Not a valid option. Please try again." - If the user selecta option 1 (ie. by enter an integer 1), the program wili print all the errpiopeed' names and their keys in the following formating Hases cname of enployeels Keys posyessed: ckeyl of enployeel> kkey? of employoel> kkeys of enployeel>... Hasas snase of employee2s Keya pojneasedt ckeyt of enployee2s skey2 of enployeez? ckeys of enployee2>+.. - If the user selects option 2 the programt will print "Please enter employee's name: " and accept user input of a name. The program will then search for this emplayee in the Employee array and print out all the keys this employee has in the folowing format crame of the apecifled enployees possessen the tollowing key": ckeyds ckeyz? ckoy3> ... If the employee specified cannot be found in the array. print out "Cannot find the specified enployee!" - If the user selects option 3, the program will print "please enter a key: " and acoept the user input of a key. The program wil then seatch the employee(t) in the Employee array and print out their names in the foliowing format cname13, knase23, ...... posaest this key. If no employee possessen the specificd key, print out "No one possesses this key." - If the user selects option 4, the program will prompt the user to firat enter the employees name by printing out "please enter employee" s nake: "and then accept the uster input of an employee s name. It then prints out "please enter a new key: "and accepts the user input of a new key. The program next will call the addkeyForfmployee() function if the new key is successtuly added to the apeeifed employees key list (ie., the function returns true), the program will print out "Key added successfully. " The other situations are handed in the addkeyforfeployee() function as descrbed abowe. - If the user selects option 5 the program will prompt the user to frat enter the employee s name by printing out "please enter. enployee's name: "and then accept the user input of an employee s name. It then prets oud "please enter the returned key: "and acoepta the user input of a returned key. The program next will call the returnaxey() function if the retumed key is aocepts the user input of a new key. The program next will call the addkeyforenployee() function. If the new key is sucoessfuly added to the specified empioyee's key list (ie. the function returns true), the program will print out "Key added success fully. ." The other situations are handled in the addxeyforEnployee() function as described above - If the user selects option 5, the program will prompt the user to first enter the employeers name by printing out "Please enter employee's name: " and then accept the user input of an employee's name. it then prints out "please enter the returned key: = and accepts the user input of a returned key. The program next will call the returnakey() function If the retumed key if successitully removed from the specified employee's key list (i.e. the function teturns true), the program will print out "Key returned successful1y. " The other sifuations are handled in the returnakey() function as described above - If the user selecis option 6, the program will prompt the user to enter the output file's name by printing out "please enter output file nane: "and then accept the user input of the output fie name. The program next will cal the writer() to write the current bey information to the specified cutput file - If the user selects option 7, the program will call the writer() function to write the current key information to the keys_updated.txt file then print out "Thank you for using the systeml Goodbye!" before exiting the program. lint: Donit forget to close files atter you finish reading/writing themt Also, mike sure to call cin. Ignore() of inputFile, ignore() when

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Machine Learning And Knowledge Discovery In Databases European Conference Ecml Pkdd 2015 Porto Portugal September 7 11 2015 Proceedings Part 3 Lnai 9286

Authors: Albert Bifet ,Michael May ,Bianca Zadrozny ,Ricard Gavalda ,Dino Pedreschi ,Francesco Bonchi ,Jaime Cardoso ,Myra Spiliopoulou

1st Edition

3319234609, 978-3319234601

More Books

Students also viewed these Databases questions

Question

Apply your own composing style to personalize your messages.

Answered: 1 week ago

Question

Format memos and e-mail properly.

Answered: 1 week ago