首页 > > 详细

讲解Python、asp辅导留学生、讲解Python设计、asp辅导留学生

EAS 240: Introduction to Programming for Engineers
Maximum allowed grace days: Five
Please note that this is a purely hypothetical situation. This is not a real event!
Problem Description: The company XYZ is looking for a system to keep track of each em-
ployee’s wages. Each employee’s name, salary and occupation must be stored in a database. The
system must also be able to generate a comma separated value (CSV) le based on a particular
position in the company (i.e. engineer, secretary, painter, etc.) or all salaries above or below any
given number (i.e. a list of people that make over/under x dollars/year). XYZ had complications
with their previous intern which led to his termination before he could complete the program. As
a result, most of the functionality of the employee-list system is still incomplete. They would like
to hire EAS240 interns to complete this system in C programming language.
The intern completed the main le employee list.c, but, did not have any chance to complete
most of the library les (the .c and the .h). As a result, the library les for the employee list (the
list of all the employees and the required information) have not yet been completed. Each student
must write their own implementation of the functions described below to complete the program
and make it functional. The function prototypes are given, but must be added to libel.h and the
corresponding de nitions in libel.c.
Main le (employee list.c):
Main function is found in employee list.c and begins by loading the employees that are already
saved in a le named \directory.txt". Loading the employee list is done by calling the function
load el(). A state machine is then entered to determine what the user would like to do. Options
1-4 are given: 1 adds a employee, 2 searches all employees by rst name, 3 generates a CSV, and
4 saves the changes to the le and exits the program. If any other number is entered, the program
remains at this menu. A more detailed description of each option is given below.
If the user enters 1, the function add person() is called, and the program enters a loop. The
user is prompted to enter ‘Y’ or ‘N’. If ‘Y’ is entered, the function is called again. The loop only
breaks when ‘N’ is entered. The program then returns to the main menu.
If the user enters 2, search el() is called. The user is prompted to enter ‘Y’ or ‘N’, if the user
enters ‘Y’ then search el() is called again. The searching continues until the user enters ‘N’. The
program then returns to the main menu.
1
If the user enters 3, a prompt is given to enter a string. If the string matches \Position" then
the function gen csv pos() is called; if the string matches \Salary" then gen csv sal() is called.
If any other string is entered, the user is reminded of the options and prompted again. After one
of the functions is called, the program returns to the main menu.
If the user enters 4, the program breaks out of the state machine, saves the employee list (by
calling save el()), and exits the program. Note that the employee list is only saved if the user
enters 4, NOT if the user presses ctrl+c.
Note: The main function is given in employee list.c. The above is an explanation
of main function. The employee list.c le should not be edited.
Structures:
The system uses two structures. The rst structure holds information about each employee. This
structure is to be named personal info. personal info is to have 3 character arrays (of length
MAXLEN de ned in libel.h) to hold the employee’s rst name, last name, position. The structure
must also hold a double for the salary. In the line directly below the structure, add the following
line:
typedef struct personal info pi;
This line literally renames ‘struct personal info’ to ‘pi’. This means that create a new instance
of this structure, ‘pi newpi;’ may be written instead of ‘struct personal info newpi;’ (it saves
quite a bit of typing).
The second structure is a list of all the employees. It contains an array of personal info structures,
and an integer to store the current number of people in the employee list. Name this structure
employee list. The maximum number of people in the array is MAXPPL, which is also de ned in
libel.h. Use ‘typedef struct employee list el;’ for this structure. Both structures must be
declared ONLY in libel.h
Hint: MAXLEN is already de ned to be 25, and may be found in libel.h. To make an array
of length MAXLEN, use: array[MAXLEN]; same with MAXPPL.
Functions:
1: Write a function to load a employee list from a le. A sample le may be seen in the sup-
plemental materials directory.txt. This function must take a pointer to a employee list, and a
const char * string (which is the lename). The rst element in directory.txt is an integer - the
number of people in the list. In this function, create a loop that initializes a employee list to the
elements of a le (directory.txt). Use the prototype below:
void load el(el * emp list, const char * filename);
After all the employees have been loaded from the le, print ''%d employees loaded.nn'', where
%d is the number of employees loaded.
Hint: fscanf(fp, "%s %s %s %lf",...); will read in a users rst name, last name, occupation,
and salary from the le pointer fp. You may want to put this fscanf in a loop to load each
employee in the le. You must still decide where to store the scanned variables (replace the \...").
2
2: Write a function to add an employee personal info (pi) to the employee list (el) us-
ing the prototype below:
void add person(el * emp list, pi person);
Add this prototype to libel.h and the de nition to libel.c. Read the employee list.c carefully.
The employee list.c prompts the user to enter the information as can be seen by running the
provided executable le (employee list.out). After the new employee information is entered, the
program will call the function add person() and pass this information to the function. In your
function de nition you need to add this new employee to the employee list.
3: Write a second function using the prototype below to search the employee list for a rst name.
void search el(el emp list, char find name[ ]);
Read the employee list.c carefully. The employee list.c prompts the user to enter a name to
search for, and then it will pass this name to the function search el. In your function de nition you
need to search for all the employees that match the searched rst name and print full information
of each employee that has the same st name with the format seen in the provided executable le.
Hint: To compare two strings, include the string.h library in your libel.c and use the func-
tion strcmp(char *, char *); no linker ags are needed for this library. strcmp() returns 0 (or
false) if the strings are the same. You can use !strcmp() to return true if they are the same. If
there is no employee found, print 'No entries with that name.nn'.
4: Write a function by using the prototype below to save the employee list in the same manner
as directory.txt.
void save el(el * emp list, const char * filename);
This can be done by replacing fscanf with fprintf in the load el function. Keep in mind each
eld of the personal info structure must be on its own line. So the fscanf mentioned in the hint
above must be modi ed (replace the spaces with linefeeds where necessary).
5: Complete the function gen csv sal in libel.c by lling in the statements in the while loop.
The rst if (in the while loop) should check if the variable (string) ml is equal to \less". If the
strings are equal, then generate a Comma Separated Variable (CSV) le of all the people in the
employee list with a salary LESS than sal.
The second (else if) statement should check if the string ml is equal to \more". If this is true,
generate a CSV of all the people in the employee list with a salary MORE than sal.
Populate the le using the le pointer fp and by using fprintf. Note that the sample CSV
sample csv.csv (provided with supplementary les) is very similar to the save el function. Con-
sider changing the fprintf line from that function to seperate elements by commas instead of
linefeeds. Also note that there is a linefeed after each employee.
6: Complete the function gen csv pos by adding the missing code. This function generates
a CSV based on occupation. The code should compare pos to the company position (occupation)
3
of each employee in the list. If the occupation is the occupation we are searching for, write it to
the CSV with the le pointer fp.
Note: Any function that opens a le, should also close that le (using fclose(fp))
before the function returns.
Final Steps:
Now that the system is implemented, test it by generating a CSV of all the employees (this can
be done by using all employees with salary greater than 0), a second CSV for all engineers, and
a third CSV for salaries over $100k. Open the CSVs in Microsoft Excel or LibreO ce Calc (in
Linux). Calculate the average wages for all employees and all engineers (compare the these two
numbers, are engineers of this company earning more than average?!). Also calculate the standard
deviation of wages (for all employees). List and comment on your ndings and results In a Word or
LibreO ce Writer le. This le should be printed to a PDF named \Report.pdf" and submitted
in the tarball with the code.
Bonus: (+5 points)
There is a function named gen file name. Discuss (in the same document as your ndings) what
the function returns, what the input parameters are, the signi cants of those input/output argu-
ments, and a brief synopsis of how the function generates a numbered lename.
Note: An executable le named \employee list.out" is provided in the supplementary folder of
the project. This le is the compiled le of the fully functional program, i.e., upon successful
accomplishment of this project your program should work exactly like \employee list.out". Feel
free to execute this program in terminal and try di erent options to familiarize yourself with the
program desired functionality.
Submission Guidelines: Export your comments and results from Final Steps and Bonus
to a PDF named Report.pdf. Before submitting your work to the automatic grading system, you
must compress all of your les into a tar le as usual. To do this, use the following command in
the Linux terminal:
tar -cvf project.tar libel.c libel.h results.pdf
This command will create the le project.tar containing your one library source and one header
les. Submit project.tar in the Project assignment area at https://autograder.cse.buffalo.
edu/.
WARNING: If the tar le does not exactly match the format described above, then the
autograder system will not be able to grade your work and will assign you a 0. If this happens,
then you will have to correct the le names and/or tar structure, create another tar le, and upload
it again.

联系我们
  • QQ:99515681
  • 邮箱:99515681@qq.com
  • 工作时间:8:00-21:00
  • 微信:codinghelp
热点标签

联系我们 - QQ: 99515681 微信:codinghelp
程序辅导网!