Question: Problem 2 This problem is designed to make sure you can write a program that reads data into an array of structures from a file

Problem 2
This problem is designed to make sure you can write a program that reads data into an array of
structures from a file and prints out the contents of the array you have populated. This will be
especially important, since to test data structures we will need a lot of data and it will be far
more than you can type in!
The file to be processed is provided with the exercise. It is named "Problem1_2DataFile.txt". If
you open it, you will see it contains multiple lines. Each contains a name, an age, and a salary.
The Solution / Test Requirements
I want your program to demonstrate that you can define a struct that has 3 fields. They are
Name, Age and Salary. The struct is to be declared using a typedef. The Name field is a
character array sized to hold 30 characters and a NULL (zero byte) at the end. Both the Age
and Salary fields are integers.
Two functions are needed to augment your test main.
GetData is a function that is called by your test main to populate the array. It is passed the file
name to open / read / close, the array to populate and the maximum number of array entries to
fill from the file. It will need to open the file, read in as many items as the test main has
requested and close the file. It must return the number of array items that have been filled.
ShowData is a function called to display the array contents on the console. It will need to
receive the array and the number of items to print. It should print the number of items being
requested to be printed and then iterate through the array, printing out the Name, Age and
Salary fields for the requested number of items. You should use a %s format to print out the
Name field.
Your Test Main must:
Create the array of the structure type. The size of the array is to be fixed at 10.
Get the number of items to actually place in the array by prompting the user for a
number from 1 to 10. If you get a number outside the range, you must exit your
program. Otherwise,
a. You must call GetData, passing it the file name to use, the array to fill and the
number of items to place in the array. Remember that GetData will return the
number of items actually placed in the array.
b. On return from GetData, you must call ShowData, passing it the array and the
number of items returned by GetData.
Run your program, for 3,6 and 10 items, submitting all runs with your code.
 Problem 2 This problem is designed to make sure you can

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!