Question
I know its a lot but im lost on it and looking for a direction This assignment will test your ability to write a C
I know its a lot but im lost on it and looking for a direction
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 students information, compute the students earning potential, output this students 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 students 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). The values in the input file are, in order, first name, last name, major, minor, years of experience, number of honors, number of extracurricular activities, number of volunteer activities and GPA.
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 students 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 students 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 students major or minor and will return true (non-0) if this students 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 majors 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 dont 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.50
The bonus is determined by the number of honors, extracurricular activities and volunteer activities. If these three categories sums to more than 4 then the bonus is their (sum 4) * 423. If the student has a tech major and minor, add 5000 to the bonus as a tech bonus. If the student has a humanities major, add -2500 as a humanities bonus. As a bonus should not be less than 0, if the computed bonus is negative, make it 0.
The ceiling starts at 10000. Add 25000 if the students work experience > 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 students starting salary is their base salary + bonus / 3. A students 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 isHum, other functions if you break compute into other functions).
All four files need to be included in your C 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 dont 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 files 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.
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started