Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Please i need help with this C program field in the file. The first column represent the last first name, the second column represent the

Please i need help with this C program

image text in transcribed

image text in transcribed

image text in transcribed

image text in transcribed

image text in transcribed

image text in transcribed

field in the file. The first column represent the last first name, the second column represent the last name,the third column represent the major, the fourth column represent the minor, the fifth column represent number of years of experience follow respectively by number of volunteer activities, number of honors, number of extracurricular activities and GPA

This assignment will test your ability to write a C program that is made up of functions stored in different files. The main topic that this assignment will test you over is proper parameter passing. You will have to decide what parameters should be passed by copy and which should be passed as addresses and properly dereference those parameters in your functions. Incorrect parameter passing or a lack of demonstration that you know how to pass parameters properly will result in a low grade. This is discussed more later. The idea behind this program is to predict the earnings potential for students. The students' information will be stored in a text file. Your program will open the file, use a loop to input each student's information, compute the student's earning potential, output this student's earnings potential, and update some running totals. Upon completion of processing all students, a summary will be output This program must be broken into the following functions. Additional functions may be used as described below. 1. main - declare all variables needed for main, open the input file, use a while loop to input the next student, call the necessary functions to compute and output the student's earning potential, and update running totals. After the loop ends, close the file and output a summary 2. input - receive the FILE * variable along with all of the variables that will store input values. The function should consist of one fscanf instruction. It is recommended that this function be an int function returning the result of your fscanf. In main, you can then test the result of input against EOF (there are several ways you can go about this, my recommendation is given below). 3. compute - a computation function to compute three values: base salary, potential bonus, potential ceiling (maximum this student might expect during their career). Specifics for this function are given below. If desired, you can break this function into subfunctions so that this function can be more concise. If you do so, then this function calls other functions to perform the computations (these auxiliary functions are not called from main). This function is the one that returns to main the base, bonus and ceiling. 4. range - given the base, bonus and ceiling, this function computes the students expected starting salary and maximum career salary. 5. output - output to the console (using printfs) the current student's first and last name, starting and maximum salaries, in a formatted way. 6. update - given the total number of students so far, the total number of tech students so far, the starting and maximum salaries for this students, the total starting and total maximum salaries so far, the total starting and total maximum salaries for tech students so far, and this student's major, update totals. The totals are number of students, total starting and total maximum salaries, and if this student is a tech major then total number of tech majors, total starting and maximum salaries of tech majors. This should be a void function. 7. isTech - a function which receives a string that will be either a student's major or minor and will return true (non-0) if this student's major is one of the tech disciplines. See the list below, 8. isSci - same but for science disciplines, 9. isHum - same but for humanities disciplines. 10. summary - given the total number of students, total number of tech students, total starting salary, total maximum salary, total starting salary for tech majors and total maximum salary for tech majors, compute the average pay for all students (total starting + total maximum salaries)/(2* total number of students). If there were any tech majors, also compute the average pay for tech majors. Output the number of students, number of tech majors, and the average salary (if there were tech majors, output their average too). Assume there will be at least 1 student processed but there may not be any tech majors so the code to compute and output tech major's average salary needs to be done in an if statement to avoid a division by 0 error. If you look at the payroll.c sample program, you will see that iterating through the records in the input file was handled by a for-loop because the program started by inputting the number of employees. We don't have that luxury in this assignment because the data files do not store the number of students. Instead, we will use a while loop. My recommendation to implement this is as follows: while(input(...)!=EOF) {...} Here, the input function is expected to return the value returned by your fscanf statement. The ... in parens is the parameters passed to the input function. This is an int so input would become an int function rather than a void function. This also means that you do not call input from within the body of the loop but in the condition of the loop. An alternative approach, which in some cases repeats the last input twice and so may not be the best approach is to use while(!feof(...)) {...}. The ... in the 'feof condition is your FILE * variable. In this case, the input function would be part of the loop body. Tech majors are ASE, CIT, CSC, CYS, DSC and MIN. SCI majors are BIO, CHE, PHY and MAT. HUM majors are ANT, ART, ENG, HIS, MUS, PHI, and SOC. There could be other majors. The following are the formulas to use to compute the base, bonus and ceiling values. Any VALUE indicated in italics listed below should be stored in a constant using a #define statement. Any other value can be hard-coded into the program. The base salary is 50000 for tech majors 40000 for science majors 30000 for humanity majors 35000 for everyone else Base salaries are adjusted as follows +4000 for tech minors +2500 for science minors +3500 if the student has more than 5 years of work experience +3000 if the student has 4-5 years of work experience +2500 if the student has 3 years of work experience +1500 if the student has 1-2 years of work experience +1525 for a GPA > 3.25 -1000 for a GPA 2 years. If the student is a tech major and either a tech or science minor, add 15000 to the ceiling. If the student has a humanities major and minor, subtract 5000 from the ceiling. A student's starting salary is their base salary + bonus /3. A student's maximum salary is base + bonus + ceiling . Store your program in four files as described below. main.c - this file only contains main. The file should start with #include "header.h" where header is the name of your header file. header.h - this is your header file. It will store all necessary #include statements, your #define statements to define the constants as listed on the previous page, and your function prototypes. As other programmers may not be able to see your source code in your .c files but can see your h file, you should comment the use of all functions (at a minimum what each does, if you want to include information about parameters that would be useful) in the prototypes and the use of all of your constants in this file. Use descriptive names for your constants. io.c - this file will start with #include for your header file and include your input/output functions (input, output, summary). Note that while summary computes and outputs some averages, we will consider it an output function. compute.c - this file will start with #include for your header file and include all of your computation functions (compute, range, update, isTech, isSci and is Hum, other functions if you break compute into other functions). . All four files need to be included in your project. . Again, the main point of this assignment is to make sure you know how to pass parameters. Here are some rules to remember: if a parameter is being passed to a function and will not change in that function, pass it by copy. if a parameter is being passed to a function which will either input a value into that parameter or the parameter may be modified, pass it as an address (&) UNLESS it is a string in which case it is already being passed as an address. In the function, an address (or a string) is received as type * name as in char *first or int *numberOfStudents. To access a datum through the address (pointer) variable, you have to dereference it using * as in *numberOfStudents = *numberOfStudents + 1; NOTE that *numberofStudents++; does not increment the value as expected so don't use it. Do not pass a parameter as an address if it is not necessary because passing addresses requires dereferencing in the function and this is less efficient. Do not use arrays to pass a bunch of parameters in order to avoid deciding how parameters will be passed. The only arrays permitted in this assignment are the strings (first name, last name, major, minor, the input filename if you choose to input the file's name from the user), On Canvas with this assignment you will find three text files of sample data. Run your program on the first file (p2in1.txt). My output is shown below. Your output should be formatted but the formatting does not have to match mine. Your output values should match or be very close. When ready, run your program on the other two data files (p2in2.txt, p2in3.txt). Collect the outputs along with your commented source code for submission. First Frank Laney Kate Steve Ruth Todd Christina Steve George Andy Nancy Gail Peter Last Zappa Schooltree Bush Howe Underwood Rundgren Booth Hackett Duke Latimer Wilson Zappa Hammill Starting $32500 $34500 $50128 $56871 $52500 $32500 $50128 $29000 $30500 $58166 $58589 $37923 $39923 Maximum $62500 $44500 $62384 $86615 $87500 $62500 $ 62384 $34000 $ 35500 $111500 $112769 $73769 $50769 Of 13 students processed and 6 tech students processed average salary for all students: $55766.08 average salary for tech students: $70794.50 Frank Zappa MUS ART 12 0 5 1 2.853 Laney Schooltree MUS CIT 2 4 3 2 3.667 Kate Bush DSC ENG 0 6 5 1 3.124 Steve Howe CSC CIT 2 2 2 5 2.941 Ruth Underwood ASE MUS 6 2 0 1 3.425 Todd Rundgren MUS HIS 10 0 3 6 2.433 Christina Booth CYS HIS O 5 4 3 3.551 Steve Hackett ANT HIS O 2 0 1 3.098 George Duke HIS ANT 2 2 1 2 3.649 Andy Latimer CYS CIT 6 0 4 0 2.727 Nancy Wilson CIT MIN 8 4 2 1 3.456 Gail Zappa BUS N/A 10 4 1 2 3.172 Peter Hammill PSC ASE 1 2 3 2 3.812 Frank Zappa MUS ART 12 @ 51 2.853 Laney Schooltree MUS CIT 2 4 3 2 3.667 Kate Bush DSC ENG @ 651 3.124 Steve Howe CSC CIT 2 22.5 2.941 Ruth Underwood ASE MUS 6 2 0 1 3.425 Tood Rundgren MUS MIS 10 36 2.433 Christina Booth CYS HIS @ 5 4 3 3.551 Steve Hackett ANT HIS 2 0 1 3.998 George Duke NIS ANT 2 2 1 2 3.649 Andy Latimer CYS CIT 6 2 4 2.727 Nancy Wilson CIT MIN 8 4 2 1 3.456 Gail Zappa BUS N/A 10 4 1 2 3.172 Peter Hammill PSC ASE 1 2 3 2 3.812 This assignment will test your ability to write a C program that is made up of functions stored in different files. The main topic that this assignment will test you over is proper parameter passing. You will have to decide what parameters should be passed by copy and which should be passed as addresses and properly dereference those parameters in your functions. Incorrect parameter passing or a lack of demonstration that you know how to pass parameters properly will result in a low grade. This is discussed more later. The idea behind this program is to predict the earnings potential for students. The students' information will be stored in a text file. Your program will open the file, use a loop to input each student's information, compute the student's earning potential, output this student's earnings potential, and update some running totals. Upon completion of processing all students, a summary will be output This program must be broken into the following functions. Additional functions may be used as described below. 1. main - declare all variables needed for main, open the input file, use a while loop to input the next student, call the necessary functions to compute and output the student's earning potential, and update running totals. After the loop ends, close the file and output a summary 2. input - receive the FILE * variable along with all of the variables that will store input values. The function should consist of one fscanf instruction. It is recommended that this function be an int function returning the result of your fscanf. In main, you can then test the result of input against EOF (there are several ways you can go about this, my recommendation is given below). 3. compute - a computation function to compute three values: base salary, potential bonus, potential ceiling (maximum this student might expect during their career). Specifics for this function are given below. If desired, you can break this function into subfunctions so that this function can be more concise. If you do so, then this function calls other functions to perform the computations (these auxiliary functions are not called from main). This function is the one that returns to main the base, bonus and ceiling. 4. range - given the base, bonus and ceiling, this function computes the students expected starting salary and maximum career salary. 5. output - output to the console (using printfs) the current student's first and last name, starting and maximum salaries, in a formatted way. 6. update - given the total number of students so far, the total number of tech students so far, the starting and maximum salaries for this students, the total starting and total maximum salaries so far, the total starting and total maximum salaries for tech students so far, and this student's major, update totals. The totals are number of students, total starting and total maximum salaries, and if this student is a tech major then total number of tech majors, total starting and maximum salaries of tech majors. This should be a void function. 7. isTech - a function which receives a string that will be either a student's major or minor and will return true (non-0) if this student's major is one of the tech disciplines. See the list below, 8. isSci - same but for science disciplines, 9. isHum - same but for humanities disciplines. 10. summary - given the total number of students, total number of tech students, total starting salary, total maximum salary, total starting salary for tech majors and total maximum salary for tech majors, compute the average pay for all students (total starting + total maximum salaries)/(2* total number of students). If there were any tech majors, also compute the average pay for tech majors. Output the number of students, number of tech majors, and the average salary (if there were tech majors, output their average too). Assume there will be at least 1 student processed but there may not be any tech majors so the code to compute and output tech major's average salary needs to be done in an if statement to avoid a division by 0 error. If you look at the payroll.c sample program, you will see that iterating through the records in the input file was handled by a for-loop because the program started by inputting the number of employees. We don't have that luxury in this assignment because the data files do not store the number of students. Instead, we will use a while loop. My recommendation to implement this is as follows: while(input(...)!=EOF) {...} Here, the input function is expected to return the value returned by your fscanf statement. The ... in parens is the parameters passed to the input function. This is an int so input would become an int function rather than a void function. This also means that you do not call input from within the body of the loop but in the condition of the loop. An alternative approach, which in some cases repeats the last input twice and so may not be the best approach is to use while(!feof(...)) {...}. The ... in the 'feof condition is your FILE * variable. In this case, the input function would be part of the loop body. Tech majors are ASE, CIT, CSC, CYS, DSC and MIN. SCI majors are BIO, CHE, PHY and MAT. HUM majors are ANT, ART, ENG, HIS, MUS, PHI, and SOC. There could be other majors. The following are the formulas to use to compute the base, bonus and ceiling values. Any VALUE indicated in italics listed below should be stored in a constant using a #define statement. Any other value can be hard-coded into the program. The base salary is 50000 for tech majors 40000 for science majors 30000 for humanity majors 35000 for everyone else Base salaries are adjusted as follows +4000 for tech minors +2500 for science minors +3500 if the student has more than 5 years of work experience +3000 if the student has 4-5 years of work experience +2500 if the student has 3 years of work experience +1500 if the student has 1-2 years of work experience +1525 for a GPA > 3.25 -1000 for a GPA 2 years. If the student is a tech major and either a tech or science minor, add 15000 to the ceiling. If the student has a humanities major and minor, subtract 5000 from the ceiling. A student's starting salary is their base salary + bonus /3. A student's maximum salary is base + bonus + ceiling . Store your program in four files as described below. main.c - this file only contains main. The file should start with #include "header.h" where header is the name of your header file. header.h - this is your header file. It will store all necessary #include statements, your #define statements to define the constants as listed on the previous page, and your function prototypes. As other programmers may not be able to see your source code in your .c files but can see your h file, you should comment the use of all functions (at a minimum what each does, if you want to include information about parameters that would be useful) in the prototypes and the use of all of your constants in this file. Use descriptive names for your constants. io.c - this file will start with #include for your header file and include your input/output functions (input, output, summary). Note that while summary computes and outputs some averages, we will consider it an output function. compute.c - this file will start with #include for your header file and include all of your computation functions (compute, range, update, isTech, isSci and is Hum, other functions if you break compute into other functions). . All four files need to be included in your project. . Again, the main point of this assignment is to make sure you know how to pass parameters. Here are some rules to remember: if a parameter is being passed to a function and will not change in that function, pass it by copy. if a parameter is being passed to a function which will either input a value into that parameter or the parameter may be modified, pass it as an address (&) UNLESS it is a string in which case it is already being passed as an address. In the function, an address (or a string) is received as type * name as in char *first or int *numberOfStudents. To access a datum through the address (pointer) variable, you have to dereference it using * as in *numberOfStudents = *numberOfStudents + 1; NOTE that *numberofStudents++; does not increment the value as expected so don't use it. Do not pass a parameter as an address if it is not necessary because passing addresses requires dereferencing in the function and this is less efficient. Do not use arrays to pass a bunch of parameters in order to avoid deciding how parameters will be passed. The only arrays permitted in this assignment are the strings (first name, last name, major, minor, the input filename if you choose to input the file's name from the user), On Canvas with this assignment you will find three text files of sample data. Run your program on the first file (p2in1.txt). My output is shown below. Your output should be formatted but the formatting does not have to match mine. Your output values should match or be very close. When ready, run your program on the other two data files (p2in2.txt, p2in3.txt). Collect the outputs along with your commented source code for submission. First Frank Laney Kate Steve Ruth Todd Christina Steve George Andy Nancy Gail Peter Last Zappa Schooltree Bush Howe Underwood Rundgren Booth Hackett Duke Latimer Wilson Zappa Hammill Starting $32500 $34500 $50128 $56871 $52500 $32500 $50128 $29000 $30500 $58166 $58589 $37923 $39923 Maximum $62500 $44500 $62384 $86615 $87500 $62500 $ 62384 $34000 $ 35500 $111500 $112769 $73769 $50769 Of 13 students processed and 6 tech students processed average salary for all students: $55766.08 average salary for tech students: $70794.50 Frank Zappa MUS ART 12 0 5 1 2.853 Laney Schooltree MUS CIT 2 4 3 2 3.667 Kate Bush DSC ENG 0 6 5 1 3.124 Steve Howe CSC CIT 2 2 2 5 2.941 Ruth Underwood ASE MUS 6 2 0 1 3.425 Todd Rundgren MUS HIS 10 0 3 6 2.433 Christina Booth CYS HIS O 5 4 3 3.551 Steve Hackett ANT HIS O 2 0 1 3.098 George Duke HIS ANT 2 2 1 2 3.649 Andy Latimer CYS CIT 6 0 4 0 2.727 Nancy Wilson CIT MIN 8 4 2 1 3.456 Gail Zappa BUS N/A 10 4 1 2 3.172 Peter Hammill PSC ASE 1 2 3 2 3.812 Frank Zappa MUS ART 12 @ 51 2.853 Laney Schooltree MUS CIT 2 4 3 2 3.667 Kate Bush DSC ENG @ 651 3.124 Steve Howe CSC CIT 2 22.5 2.941 Ruth Underwood ASE MUS 6 2 0 1 3.425 Tood Rundgren MUS MIS 10 36 2.433 Christina Booth CYS HIS @ 5 4 3 3.551 Steve Hackett ANT HIS 2 0 1 3.998 George Duke NIS ANT 2 2 1 2 3.649 Andy Latimer CYS CIT 6 2 4 2.727 Nancy Wilson CIT MIN 8 4 2 1 3.456 Gail Zappa BUS N/A 10 4 1 2 3.172 Peter Hammill PSC ASE 1 2 3 2 3.812

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

Database Processing

Authors: David J. Auer David M. Kroenke

13th Edition

B01366W6DS, 978-0133058352

More Books

Students also viewed these Databases questions