Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

in C++ You may assume that the data is valid, and that there is at least one input record. Instructor class (or struct) Instructor has

in C++ image text in transcribed
image text in transcribed
image text in transcribed
You may assume that the data is valid, and that there is at least one input record. Instructor class (or struct) Instructor has members for all the input fields. The instructor number and salary members are ints, the middle initial is a char, and the rest are strings. Define a class (or a struct) that matches this description. There are no member functions for Instructor so a struct is probably a better choice. There are some differences between the input fields and the form of the Instructor members. The Instructor ID field in the input is an example of a coded key. It may look like a 9-character ID, but in reality it contains two distinct fields. The first three characters are a payroll code. The next six characters are a unique number. You may assume that the numbers are assigned such that every instructor has a unique 9-character ID. The salary is a whole number (no decimal places). Using a pointer array The technique of using a pointer array to keep track of dynamically allocated objects is described in the dynamic allocation in-class examples we did. Dynamic allocation of structures is also covered in Gaddis chapter 11.9. Initialize each element in the array of pointers to nullptr. As you read input records and create new instructor objects, point the next element in the pointer array at the new object. Later, when you loop through the pointer array to process the objects, you'll know that there are no more when you come across a pointer with a null value. This way, the pointer array is self-contained and you don't need a counter. Display the Instructor objects When you hit EOF on the input file, close it, and display the entire list of instructors. Do not create the report while you're in the loop that reads input records, else you won't be dumping data from the structure you've created. Your output should look something like this: salary function Code a function named salary, which has two parameters and a return value. The parameters are: 1) the Instructor pointer array 2) a pointer variable of type instructor The return value is an int. salary performs two bits of analysis. It loops through the instructor objects, calculating the average salary. It also determines which Instructor has the highest salary. You can perform both analyses in the same loop. The average salary is passed back to the caller as the return value. The address of the instructor object with the highest salary is passed back to the caller in the second parameter. Main's structure: open the input file - if it fails to open, display an error message and terminate read the file and populate the Instructor objects display the Instructor data with appropriate column headers and formatting to make it readable invoke salary display the average salary and the name of the instructor with the highest salary clean up (deallocate memory, close files) return Source code file structure Use the standard approach to source files in this assignment. - a. .cpp for each function. You'll have at least two-main and salary. You could have more if you design your project with more functions. - a header file for the instructor class / struct, properly guarded. - a header file for the function prototype for salary, properly guarded. Debugging For debugging purposes, it would be a good idea to code your program in steps. First, write code to read the input and create the instructor objects. Determine if your parsing works by displaying each Instructor as it's created (but remove this display before you submit for a grade). Make sure that if you read n input records, you actually create n objects. Verify that the n+1 th pointer in the Instructor pointer array contains nulls. Then, add the code to produce the report from the instructor objects. Finally, code the salary function, call it, and display its results

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_2

Step: 3

blur-text-image_3

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

Database Design Query Formulation And Administration Using Oracle And PostgreSQL

Authors: Michael Mannino

8th Edition

1948426951, 978-1948426954

More Books

Students also viewed these Databases questions