Lab Assignment #2, CSE 1320-001 Fall 2008
Due Date: Wed. Nov. 5th at
NOON
(see instructions on website for how to turn this in)
Grade value; 10% out of 100% for all grades
Topic objectives: Linked lists
Recursion
File input
Bit operations (Extra credit)
(and all previous topics)
The goal for this lab is to provide an application of the topics covered in CSE1310 as well as material covered so far in CSE 1320 about the C programming language. This assignment is designed to practice those concepts by creating a program. Be sure to check the DEDUCTIONS section at the end of this assignment to avoid penalties. You may NOT use global variables, the exit command, goto, break (except in a switch), or continue.
-- • -- • -- • -- • -- • -- • -- • -- • -- • -- • -- • -- • -- • -- • -- • -- • -- • -- • -- • -- • -- • -- • -- • -- • --
Here at UTA we have lots of opportunities for engineering students to participate in fun, competitive team activities. You are going to write programs that will capture and analyze data about the teams and the team members. You’ll probably be surprised at all the things that UTA Engineering students do!
Throughout the course of the semester, you will work on developing the team competition data analysis program. Each lab builds on the previous labs. For Lab #2 (this lab) you will be given some constant data to #include just like Lab #1 and then you will also have to read in some additional data from a file and from the user. Using this data you will perform most of the tasks from Lab #1 along with some additional tasks all of which are listed below. You will still need to give the user a menu of choices and to report results from the program.
Your
tasks for the team program lab #2 will be:
¨
Introduce the team data analysis system to a new user.
¨
Create two-dimensional arrays to store student data in
and then populate the arrays with data.
¨
Create a singly linked list for all team info
1.
Put given constant team data into team linked list sorted by
team name
2.
Find additional team data from team member array and put into
team linked list
3.
Link the team captain in the member array to the team linked
list
4.
Read in team data from a file and put into team linked list
¨
Create and display a screen menu of the following
choices for the user.
1)
Using the data in the team member array and the team linked list, let the user
do the following tasks
i. Get a list of team
competitions that UTA participates in
ii. Count the number of people on a
given team
iii. List the members of a team
iv. Find the average GPA of a single team
v. Sort the members of a single team
by last name
vi. Search for a particular team or team
member by name
vii. Get a list of all the student teams (by name)
that compete in engineering competitions
viii.Find
the average age of a single team
ix. Count the number of students of each
class/year (Fr, So, …) on a single team
x. Find the average GPA of all students who participate on
teams
xi. Sort the members of a single team by student ID number and by
GPA
xii. Calculate data about the time needed to participate on each team using a recursive function as described below
xiii. Sort the team linked list
by competition and by number of team members
a. [Extra Credit] Search for a
particular team member by ID
b. [Extra Credit] Search for a
particular team by competition or by sponsor
c. [Extra Credit] Find the average age
of all students who participate on teams
d.
[Extra Credit] Count the number of
students of each class/year (Fr, So, …) on all teams
2)
Update the data in the arrays–this will take the user to a submenu for
doing updates
3)
Add data to the arrays - this will go to a submenu to allow new data to be
added
4)
End the program
Each of these tasks is described in more detail below. There
are also some simplifying assumptions for this lab. Many of these
simplifications will be eliminated in later labs.
Simplifying assumptions for the lab #2:
a) A maximum size for any team (MAXMEMBERS) will be given
b) A maximum number of teams (MAXTEAMS) will be given
c) The given number of team members in the const array is 27
(GIVEMEMBERS)
d) The given number of teams in the const array is 5 (GIVETEAMS)
Task Descriptions:
Introduce the team data analysis system to a new user.
For this task your system must provide an introduction/welcome screen to the user. The screen should briefly describe what the system will do. You may have the welcome screen stay up for a fixed period of time or you may let the user press a key to continue on with the program. Make sure you tell the user what to do if you want them to press a key.
Create two-dimensional array to put student data in
and then populate the arrays with data.
For lab #2 you will create a two dimensional array of student structs (just like in lab #1) that will hold all the team members of each team in the subarrays, i.e. each row is a team and the student struct in each column of that row is a team member.
The data to put into this 2D array will be given to you as a constant 1-dimensional array of student structs. This array will be in a separate data file (C1320F08L2testdata.h) that you will #include at the beginning of your program. The specification of the array you will be given in the #include file is as follows (Note that the struct has additional members from the struct type in the pre-lab):
const struct UTAstdt{
char
*lastname;
char
*firstmidname;
long
int UTAID;
double
cumGPA;
char
major[5];
char
*competition;
char
*teamname;
short
year; // 1 =Freshman, 2 =Soph, 3
=Jr, 4 =Sr, 5 =other UG, 7 =MS, 9 =PhD
char
gender; // M, F or U for Unknown
or Unreported
int
age;
char
*role;
// captain, driver, member, engineer, etc.
short
joinyear, joinmonth, joinday; // Date the member joined the team
struct
UTAstdt *nextstdt;
}
const struct UTAstdt giventeammembers[25] =
{
{“Patel”, “Joshua”, 2000457234, 3.245, “CE”, “Steel Bridge”, “Blaze”, 3, M, 20, "engineer", 2007, 10, 20, NULL},
// …another 23 records like this
{“Smith”, “Yan Akiba”, 2000943211, 2.87, “CS”, “ICPC”, “UTA Blue”, 3, U, 20, "member", 2008, 8, 30, NULL}
};
You will need to create a two-dimensional array that can hold up to MAXTEAM different teams with a maximum of MAXMEMBERS on each team. You will then go through the struct data in the giventeammembers array and sort them into the new two-dimensional array by copying each record out of the giventeammembers array and putting each unique team into one row of the two-dimensional array and each member of that team into the same row. So, for example, if Joshua Patel is the first person in the giventeammembers array then his record would be assigned into the first row of the two-dimensional array. Then the next record in giventeammembers that was in the Steel Bridge competition would be assigned after Joshua in that row.
Every value in each record in giventeammembers should be put into the new two-dimensional array. The program should verify that the student GPA is valid, i.e. between 0.0 and 4.0 in value. Any other GPA value should be reset to 0.0 . The program should also verify that the ID number is between 2000000000 and 2000999999. Any other ID value should be reset to 1999999999. The program should verify the class year value as one of the valid values, the age as a positive number, and the gender as one of the valid values.
All of the rest of the program will only use the two-dimensional array not the giventeammembers array. The two-dimensional array will not be full since there are many more spots in the array than there are team members in the constant array.
Input verification:
When the program has put all of the giventeammembers into
the two-dimensional array, it should print out all of the team data in the
two-dimensional array at each [indexteam][indexmember] in an easily readable form, ex. use a table with
headings, or columns with headings or rows with labels. It is strongly suggested that this
printing be written as a separate function that can be called at any time in
the program to print the current contents of the two-dimensional array.
Create a sorted singly linked list for all team info
For lab #2 you will create a linked list of team structs
that will hold data for each team.
Some of the data to put into this team linked list will be given to you
as a constant 1-dimensional array of team structs. This array will be in the same data file (C1320F08L2testdata.h)
as the student team member data.
The specification of the struct and the constant array you will be given
in the file is as follows:
struct
UTAteam{
char
*competition;
char
*teamname;
char
sponsor[10]; // Dept. or Lab that sponsors the team
char
*advisor; // Name of
faculty or staff advisor
int
compyear; // Year this team
competed in this competition
int
membercount; //
Number of team members
struct
UTAstdt *captain;
int hrsperwk; // Minimum hours of time needed per
week
short eventday, eventmonth,
eventyear; // Date of competition
struct UTAteam *prevteam;
struct
UTAteam *nextteam;
};
const
struct UTAteam giventeams[5] =
{
{"Steel
Bridge", "Blaze", "CE", "Dr. Jim Williams",
2008, -1, NULL, 4, 10, 10, 2008, NULL, NULL},
//
… more records like this
{"Imagine
Cup", "mUTAte", "GDC", "Dr. Carter Tiernan",
2008, 1, NULL, 2, 31, 1, 2009, NULL, NULL}
};
You will need to create a singly linked-list that will hold all the different teams sorted in order by team name. You will create this list by going through the struct data in the giventeams array and storing the teams into the linked list. The linked list should be created using the nextteam pointer in the struct. The struct pointers for captain and prevteam should be set to NULL for all teams initially.
For each team in the giventeams array, the first five values are given. The sixth value (number of team members) may or may not be correct. Your program should check this value from the giventeams array and do the following:
If the number of team members is positive, then store it in the linked list; else if it is -1, run the team member counting function (menu choice iv.a. below) and store the result in the linked list as the number of team members.
After all the data from the giventeams array is stored in the linked list, then some additional team verification should be done. The program (not you directly) should go through the two-dimensional team member array and make sure that every team in the team member array is in the team linked list. You should have a function that verifies this and adds any teams from the members array to the teams linked list in order if they are not there. If a team is added to the team linked list the following things should be done:
All character strings for teamname and competition should be treated as pointers and the pointer values assigned to the team linked list not the whole string.
If the team data needed is not in the member array (advisor and sponsor) then those values should be found by programmer research (search the UTA website) and then the info should be added to the team linked list (using the add functions – see below also) by allocating space to the advisor and sponsor pointers and storing the new data into these allocated string spaces.
Any team whose year is not given can be assumed to be 2008.
As the program goes through the
team member two-dimensional array, it should also find the team member for each
team whose role is captain (if such a member exists) and store the pointer for
the captain string into the captain pointer in the team struct
After
all the teams from the 2D team member array have been added to the team
linked-list then the program should read in data from a file called "C1320F08L2moreteams.txt"
and add these teams to the team linked-list in sorted order by team name. The data in this file should be read in
using file I/O as will be discussed in class. The file name may be passed as a command line parameter (to
be discussed) but it is not required.
Input verification:
When the program has put all of the teams into the team linked-list, it should print out all of the team data in the linked-list in an easily readable form. It is strongly suggested that this printing be written as a separate function that can be called at any time in the program to print the current contents of the team linked-list.
Create and display a screen menu of choices for the
user implementing all the functions.
Once all the data is read into the arrays your program should give the user a screen menu with the following choices: (use any number scheme you wish)
i- List the engineering team competitions that UTA participates in (give competition, sponsor and advisor as minimum info)
ii- List all the UTA engineering teams by name (give team name, competition, sponsor, number of team members as minimum info)
iii- List the members of a team by name (give first name, last name, team name, year/class, GPA, ID number, and role as minimum info)
iv- Get team member data/statistics for a given team
a. Count the total number of team members
b. Count the number of freshman, sophomores, etc.
c. Calculate the average GPA
d. Calculate the average age
e. Recursively calculate an estimate of hours of time needed per week for team
v- Get team member data/statistics for all teams together
a. Calculate the average GPA
b. [Extra Credit] Count the total number of team members on all teams
c. [Extra Credit] Count the number of freshman, sophomores, etc.
d. [Extra Credit] Calculate the average age
vi- Sort the members of a single team by
a. Last name
b. GPA
c. ID number
vii- Sort the team list by
a.
Team name
b.
Competition
c. Number of team members
viii- Search for a particular team member by
a. Last name
b. [Extra Credit] ID number
ix-Search for a particular team by
a. Team name
b. [Extra Credit] Competition
c. [Extra Credit] Sponsor
x- Update the team member data
xi- Update the team data
xii- Add new team member data
xiii- Add new team data
xiv- End the program
The competition list function (i) should print a list of all the competitions that are named in team array giving each competition only once. It is suggested that you number this list as you print it so that you can then used this list of competitions to search with in other functions. The team list function (ii) should print a list of all the teams that are named in the one-dimensional array. It is suggested that you number this list as you print it so that you can then used this list of teams to search with in other functions. The member list function (iii) should print a list of all the students that are named in the two-dimensional array for a given team chosen by the user.
The count function (iv.a.) should just count the number of members that are in the array for a given team chosen by the user. The count-by-class function (iv.b.) should count and print the number of students on the team in each of the valid class categories (1 =Freshman, 2 =Soph, 3 =Jr, 4 =Sr, 5 =other UG, 7 =MS, 9 =PhD). The GPA function (iv.c.) should call the count function (or refer to the team number data in the team array) to help perform its function for a given team chosen by the user. The average age function (iv.d.) should also call the count function to do its job. The hours per week estimation function (iv.e.) will use the following algorithms to determine the estimated hours required for that team activity at a given time of the year PRIOR to the event itself.
The
hours per week calculation will be based on the following: For any team there is a minimum hours
per week needed all year round and that minimum hours per week is stored as the
hrsperwk member of the team struct.
However, as the event approaches, more hours per week are needed with
the most hours needed immediately prior to the event. So, if we assume that the hours needed starts rising about 4
months before the competition (we’ll say 18 weeks and use the constant
PREPWEEKS to equal 18), then we want to make the following calculations:
Step
1: Get the event date from the
team struct and calculate a Gregorian calendar day number for that date. Write a function to implement this day
number calculation using the algorithm given on the class website in the file "calendaralgorithm.txt"
Step
2: Ask the user for a date PRIOR
to the event and get a day, month, and year for this date from user input from
the keyboard. Calculate the Gregorian
calendar day number for that date using the day number function just discussed.
Step
3: Subtract the PRIOR date from the
event date to get the number of days before the event.
Step
4: Divide this number by 7 to get
the number of weeks before the event.
Do integer division here.
Step
5: Write a small recursive
function with two input parameters, the number of weeks just calculated and the
minimum hours per week (from the team struct), to calculate the number of hours
that will be needed that week based on the algorithm below:
Week
calculation algorithm
If
number of weeks is greater than or equal PREPWEEKS or less than or equal to 0,
the
needed hours per week is just the minimum hours per week, hsperwk, from the
team struct.
Else
calculate the needed number of hours as a
running
sum of the minimum hours per week plus
the value returned by calling the calculate hours function with number_of_weeks + 1.
// If you are asking yourself "why +1 instead of -1 there?" the answer is that you want to count from the number of weeks UP to 18
// weeks to calculate the needed hours because the total hours need to increase the closer you get to the event; e.g. if you are 15 weeks
// from the event you might only need three times the minimum hours to work on the team project but if you are one week from the
// event you will need a lot more than the minimum hours that week.
The GPA function for all team members (v.a.) should find the average GPA of all members on all the team. For Extra Credit do the total team member count, the class member count and the average age functions for all the team members in the two-dimensional array.
The sort-by-last-name function (vi.a.) will mergesort the subarray for a single team chosen by the user within the two dimensional array. You must also sort the subarray for a single team by GPA (vi.b.) or by ID number (vi.c.). Any sorting algorithm may be used. Since these are small arrays, the bubble sort would be a reasonable choice.
The
sort-by-competition function (vii.b.) will sort the linked list of teams by
competition name. You must also
sort the linked list by number of team members (vii.c.). Even though the team linked list is
built in a sorted order by team name you must also implement a team name sort
function (vii.a.) so that if you have resorted it by competition or member
numbers, you can then sort it back into to team name order. A linked-list version of the bubblesort
would be fine to use or any other sort algorithm for a singly linked-list.
The search options (viii.a. and ix.a.) should call search functions that perform linear search on the appropriate subarrays of data. If you have one or more searches that use the same type of data, you may pass in the value to look for and the array to search and use the same search function for both. When the search is complete your program should print the search result(s) and then show the user the menu again. In case of ties, print all results.
For Extra Credit implement searches using the different search keys.
The update options (x. and xi.) should take the user to a second screen to allow them to update information in the arrays. This screen should ask the user which array they wish to update – the team member array or the team array.
To update the team member array (x.) the system should go to
another menu. This screen should
ask for a team member’s last name and search for that student. Once the student is determined, save
the two [indexteam][indexmember] values
and give the user a menu of the following options:
o Change lastname at [indexteam][indexmember]
o Change firstmidname at [indexteam][indexmember]
o Change UTAID at [indexteam][indexmember]
o Change cumGPA at [indexteam][indexmember]
o Change major at [indexteam][indexmember]
o Change competition at [indexteam][indexmember]
o Change teamname at [indexteam][indexmember]
o Change year at [indexteam][indexmember]
o Change gender at [indexteam][indexmember]
o Change age at [indexteam][indexmember]
o
Change role at [indexteam][indexmember]
o
Change
join day, month, or year at [indexteam][indexmember]
o Return to main menu
To update the team array (xi.) the system should go to another
menu. This screen should ask for a
team name and search for that team.
Once the team is determined, save a pointer to that struct in the team
linked-list and give the user a menu of the following options:
o Change competition
o Change teamname
o Change sponsor
o Change advisor
o Change compyear
o
Change membercount
o
Change
captain
o
Change
hrsperwk
o
Change
event day, month, or year
o Return to main menu
For any change the user wishes to make, do the same error
checking as in the original data entry section. Note that the structs use pointers for their strings. To update a string, the program must
ask the user for the new string, allocate new space (malloc or calloc) to the
pointer in the struct big enough for that string and then copy the user’s
string into the newly allocated space.
After each change is made, print all of the struct info for the team member or team that was updated.
The add options (xii. and xiii.) should take the user to a second screen to allow them to add new information in the arrays. This screen should ask the user which array they wish to add to – the team member array (xii.) or the team linked-list (xiii.). For a new team member, the program must determine if they are on an existing team or on a new team. (If a new team member is added on a new team, the program should automatically add this new team to the team linked=list after the new team member is added. This should work in a similar fashion to how the team list was originally verified with the team member data.)
For members or teams then the program should prompt the user to enter all of the member data for the struct type except for the struct pointers which should be initialized to NULL. The newly entered data should be saved in an empty member of the appropriate subarray or should be sorted into the linked list as appropriate.
When the user chooses “End the program” (xiv.) from the main menu, print a concluding message and then gracefully end the program.
Implementation
requirements:
The program should use the following data structures:
Struct with integer, character, floating point, and pointer elements for recording team member data
Struct with integer, character, and pointer elements for recording team data
Two-dimensional array of the team member structs
Singly linked-list of team structs
Pointers in function declarations to pass arrays and lists
Global constants given as input data
The program should use the following control structures:
Function calls to perform tasks
A while, do-while, or for loop to read the input data
If, if-else, or nested ifs to error check
A switch statement for implementing menus
Recursive number of hours function and mergesort implementations
The program should NOT use:
any topic not covered in class before the lab DUE date unless approved by the instructor
The program should be implemented as a set of functions with
a main routine and at
least one function for menu operations, two for the mergesort functions, one
for counting team members, one for calculating average GPA, one for calculating
the day of the year, and a recursive function for finding needed hours per
week. You may use more
functions than this but you must use at least this many. It is suggested that you also have a
function for printing the team member and team data but these are not required.
The program should perform the following actions in the given order:
Declare and initialize the variables
Read data from the given input file
Print a welcome screen for the user that introduces the system
Get the needed input value from the keyboard
Print the appropriate outputs
Let the user enter additional values until the user indicates that they are finished.
The program MUST have a program header which gives, at least, your name, the number of the lab assignment, your class and section, the assignment date, the due date, and a description of the program. If multiple files are used, each file should contain a similar header. See your instructor’s website for SPECIFIC instructions about the program header.
Each programmer-defined function, i.e. each function you write, MUST have a function header similar to those used in the examples in the textbook. This header should include at least the function name, the purpose of the function, and its inputs and outputs.
This program MUST be run with two different sets of test data for the team member constant data. You must create one data set in addition to the one that I will give you and run your program with both of them. You may run it two times within a single execution or you may execute the program two different times so that you have a total of two different data sets. The sample data set that you create must meet the guidelines given in the problem definition. The sample data set you create must be submitted as one of your source files that are turned in for this lab.
The program output must be recorded in a script file from OMEGA using the gcc compiler. If you do not know how to create a script file, it is your responsibility to ask the TA, look for help on the class website, or OIT how to use this function.
Read the lab submission instructions on the website for what material to turn in, what to call it, and how to turn it in.
Grading scale:
Code: (62%)
Program header and function headers for all
functions (3
points)
Comments (line comments and block comments) (4 points)
Modularity (division of the problem into small
tasks, each one assigned to its own function and called from main() or from
another function when appropriate--do not code the entire program in
main!) (5 points)
Style (indentation, consistency, meaningful
identifiers, lateral separation of code from line comments, etc.) (4 points)
Correct manipulation of the arrays and structs (4
points)
Correct manipulation of the linked lists and
structs (14 points)
Correct use of required control structures
including recursive needed-hours function (10 points)
Correct function structure as required (8 points)
Proper implementation of input error checking (4
points)
Correct use of file input (4 points)
Correct use of memory allocation for strings (2
points)
Output: (38%)
User clearly understands what is being requested for input (5 points)
Search
and sort tasks perform correctly on linked lists (7 points)
Print
and calculate tasks perform correctly (6 points)
Update
tasks perform correctly (4 points)
Input
verification shows valid values and list of inputs correctly saved and printed
(4 points)
Output gives clear information to explain the values to the user (7 points)
Output
contains all the given test data and one additional data set (5 points)
Deductions:
Use
of global variables will result in an overall grade of 0 (zero)
Use of
the exit, break, or continue command will result in an
overall grade of 0 (zero)
Use
of linked lists will result in 50 (fifty) point
deduction per use
Late
submission of softcopy of code and/or script file to appropriate TA will
result in an overall grade of 0 (zero) without prior instructor
approval
Use
of C language elements not yet discussed in class by the lab due date will
result in potential deduction of points – discuss with instructor before
using.
Miscellaneous:
Competitions include:
Steel Bridge Building Competition
ACM International Computer Programming Contest
Society of Automotive Engineers Formula SAE Race Car Team
Google’s Imagine Cup
Institute of Electrical and Electronic Engineers Robotics Competition
Autonomous Vehicle Laboratory competitions in Air vehicles and Ground vehicles
Concrete Canoe Competition
CanSat Satellite Payload Competition
IEEE Energy Challenge