Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

2) Array of structures, text files Please read the tutorial on handling files in C. Consider the following definitions. struct persalary{ int month; long salary;

image text in transcribedimage text in transcribed

2) Array of structures, text files Please read the tutorial on handling files in C. Consider the following definitions. struct persalary{ int month; long salary; /* number 1 corresponds to January, *1 /* 2 corresponds to February, and so on */ struct employee int emp_no; /* Employee number */ char name[12]; /* Employee name */ struct persalary salaries[3]; /* three months salaries */ long maximum; /* Maximum of 3 months salaries */ float average; /* Average of 3 months salaries*/ }; A) Using the above structures, define an array empArray of structure employee with size 10 that will be initialized using a data file (named emp.txt). The data file should have 10 rows of data in it. The first four rows are given. The fifth row should contain your name. The remaining 5 rows should contain data that you make up. (10 pts) 121 Joe 2 300 4 400 12 750 234 Ayse 3 250 6 800 7 475 456 Mehmet 4 750 5 880 10 660 875 Mary 2 950 4 660 9 775 Use Notepad to create the emp.txt file. Since the file has only 4 rows, there will be some empty places in your empArray. B) Write a function readFile that reads the data in the file into empArray. (10 pts) C) Write a function display that displays the contents of the array as shown below. Note that the integer values corresponding to months are converted to the proper month names. This can be achieved by declaring an array of the month names. (20 pts) Employee No Name Month Salary 121 Joe 300 400 750 250 800 475 234 February April December March June July Ayse etc. (i) D) Write a function computeAndDisplay that computes for each employee the average and the maximum of the three months' salaries (ii) sets the values of the corresponding fields in each record, and (iii) displays the output as follows. (20 pts) Employee No Name Average Maximum 121 Joe XXXX.XX XXXXXX 234 Ayse XXXX.XX 456 Mehmet XXXX.XX XXXXXX 875 Mary XXXX.XX XXXXXX XXXXXX E) What will be the total memory size of this array? Explain your answer. (5 pts) F) Assume that you declared allEmployee for 3 employees as follows struc employee allEmployee[3]; a) If the base address of this array is 1000, what the starting address of allEmployee[1].salaries[2].salary? (5 pts) b) If the base address of this array is 5000, what is the address of Mehmet's May salary? (5 pts) 2) Array of structures, text files Please read the tutorial on handling files in C. Consider the following definitions. struct persalary{ int month; long salary; /* number 1 corresponds to January, *1 /* 2 corresponds to February, and so on */ struct employee int emp_no; /* Employee number */ char name[12]; /* Employee name */ struct persalary salaries[3]; /* three months salaries */ long maximum; /* Maximum of 3 months salaries */ float average; /* Average of 3 months salaries*/ }; A) Using the above structures, define an array empArray of structure employee with size 10 that will be initialized using a data file (named emp.txt). The data file should have 10 rows of data in it. The first four rows are given. The fifth row should contain your name. The remaining 5 rows should contain data that you make up. (10 pts) 121 Joe 2 300 4 400 12 750 234 Ayse 3 250 6 800 7 475 456 Mehmet 4 750 5 880 10 660 875 Mary 2 950 4 660 9 775 Use Notepad to create the emp.txt file. Since the file has only 4 rows, there will be some empty places in your empArray. B) Write a function readFile that reads the data in the file into empArray. (10 pts) C) Write a function display that displays the contents of the array as shown below. Note that the integer values corresponding to months are converted to the proper month names. This can be achieved by declaring an array of the month names. (20 pts) Employee No Name Month Salary 121 Joe 300 400 750 250 800 475 234 February April December March June July Ayse etc. (i) D) Write a function computeAndDisplay that computes for each employee the average and the maximum of the three months' salaries (ii) sets the values of the corresponding fields in each record, and (iii) displays the output as follows. (20 pts) Employee No Name Average Maximum 121 Joe XXXX.XX XXXXXX 234 Ayse XXXX.XX 456 Mehmet XXXX.XX XXXXXX 875 Mary XXXX.XX XXXXXX XXXXXX E) What will be the total memory size of this array? Explain your answer. (5 pts) F) Assume that you declared allEmployee for 3 employees as follows struc employee allEmployee[3]; a) If the base address of this array is 1000, what the starting address of allEmployee[1].salaries[2].salary? (5 pts) b) If the base address of this array is 5000, what is the address of Mehmet's May salary? (5 pts)

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

Data Management Databases And Organizations

Authors: Richard T. Watson

3rd Edition

0471418455, 978-0471418450

More Books

Students also viewed these Databases questions

Question

6. Is all Internet training the same? Explain.

Answered: 1 week ago