Lab Assignment #1, CSE 1320-001 Fall 2008

 

Due Date:         Wed. Oct. 15th at NOON

(see instructions on website for how to turn this in)

 

Grade value;     10% out of 100% for all grades

 

Topic objectives:    Arithmetic and relational operators, Control structures

                              Functions, Recursion

                              Structures, Multi - dimensional arrays

                              Pre-processor directives, Global constants

                              Pointers

                              Searching, Sorting

                              Modular programming structure, Error checking, Programming style

                             

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.   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.  For this lab (#1) you will be given a list of student team members with info about each student and a list of some of the teams they participate on.  Your task will be write a program to separate the students into various lists based on characteristics about each student, to create a complete list of the teams that students participate on, and then to determine certain information for and from each list you create.  You will have to give the program’s user a set of choices that will then guide the program.  You will have to accept user input for some data needed for some of the lists.  You will also have to report to the user the results that the program determines and the lists that are created.

 

Your tasks for the team program lab #1 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 one-dimensional array for all team info and populate the array

1.      Put given constant team data into team array

2.      Find additional team data from team member array and put into team array

3.      Research teams added in (2.) to find advisors and sponsors info and put in team array

¨                  Create and display a screen menu of the following choices for the user.

1) Using the data in the arrays, 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.   [Extra Credit] Find the average GPA of all students who participate on teams

xi.   [Extra Credit] Sort the members of a single team by student ID number and by GPA

xii.  [Extra Credit] Search for a particular team member by ID

xiii.[Extra Credit] Search for a particular team by competition or by sponsor

xiv.[Extra Credit] Find the average age of all students who participate on teams

xv. [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 #1:

a) Each student is a member of only one competitive team

b) A maximum size for any team (MAXMEMBERS) will be given

c) A maximum number of teams (MAXTEAMS) will be given

 

 

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 #1 you will create a two dimensional array of student structs 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 (C1320F08L1testdata.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.

            struct UTAstdt *nextstdt;

}         

const struct UTAstdt giventeammembers[25] =

{

{“Patel”, “Joshua”, 2000457234, 3.245, “CE”, “Steel Bridge”, “Blaze”, 3, M, 20, "engineer", NULL},

// …another 23 records like this

{“Smith”, “Yan Akiba”, 2000943211, 2.87, “CS”, “ICPC”, “UTA Blue”, 3, U, 20, "member", 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 one-dimensional array to put team data in and then populate the arrays with data.

For lab #1 you will create an array of team structs that will hold data for each team.  Some of the data to put into this team array will be given to you as a constant 1-dimensional array of team structs.  This array will be in the same data file (C1320F08L1testdata.h) as the student team member data.  The specification of the 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;

            struct UTAteam *nextteam;

};

 

const struct UTAteam giventeams[5] =

{

{"Steel Bridge", "Blaze", "CE", "Dr. Jim Williams", 2008, -1, NULL, NULL},

// … more records like this

{"Imagine Cup", "mUTAte", "GDC", "Dr. Carter Tiernan", 2008, 1, NULL, NULL}

};

 

You will need to create a one-dimensional array that can hold up to MAXTEAM different teams.  You will then go through the struct data in the giventeams array and store them into the new array.

 

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 new array; else if it is -1, run the team member counting function (menu choice iv.a. below) and store the result in the array as the number of team members. 

The two struct pointers should be set to NULL for all teams initially.

 

After all the data from the giventeams array is stored in the new array, 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 array.  You should have a function that verifies this and adds any teams from the members array to the teams array if they are not there.  If a team is added to the team array 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 array not the whole string.

If the 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 array (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.

 

All of the rest of the program will only use the one-dimensional array not the giventeams array.   The one-dimensional array will not be full since there are many more spots in the array than there are teams in the constant array.

 

Input verification:

When the program has put all of the teams into the one-dimensional array, it should print out all of the team data in the array at each [indexteam] 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 array.

 

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

v-   [Extra Credit] Get team member data/statistics for all teams together

      a. Count the total number of team members on all teams

b. Count the number of freshman, sophomores, etc.

c. Calculate the average GPA

d. Calculate the average age

 

vi-  Sort the members of a single team by

      a. Last name

      b. [Extra Credit] GPA

      c. [Extra Credit] ID number

vii- Search for a particular team member by

a.       Last name  

b.      [Extra Credit] ID number

viii-Search for a particular team by

      a. Team name

      b. [Extra Credit] Competition

      c. [Extra Credit] Sponsor

 

ix-  Update the team member data

x-   Update the team data

xi-  Add new team member data

xii- Add new team data

 

xiii- 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. 

 

For Extra Credit do the same four 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. 

 

For Extra Credit the subarray for a single team can be sorted by GPA or by ID number.  Any sorting algorithm may be used.  Since these are small arrays, the bubble sort would be a reasonable choice.

 

The search options (vii.a. and viii.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 (ix. and x.) 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 (ix.) 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                   Return to main menu

 

To update the team array (x.) 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 the [indexteam] value and give the user a menu of the following options:

 

o                   Change competition at [indexteam]

o                   Change teamname at [indexteam]

o                   Change sponsor at [indexteam]

o                   Change advisor at [indexteam]

o                   Change compyear at [indexteam]

o                   Change membercount at [indexteam]

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 (xi. and xii.) 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 (xi.) or the team array (xii.).  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 array after the new team member is added.  This should work in a similar fashion to how the team array was originally verified with the team member data.) 

 

For the appropriate array 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 array or subarray.

 

When the user chooses “End the program” (xiii.) 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

One-dimensional array of team structs

Pointers in function declarations to pass arrays

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 mergesort implementation

 

The program should NOT use:

global variables

exit

goto

break

continue

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, and one for calculating average GPA.  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

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:   (61%)

Program header and function headers for all functions    (4 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!)  (8 points)

Style (indentation, consistency, meaningful identifiers, lateral separation of code from line comments, etc.)  (8 points)

Correct manipulation of the arrays and structs (10 points)

Correct use of required control structures including recursive mergesort (10 points)

Correct function structure as required (8 points)

Proper implementation of input error checking (4 points)

Correct use of memory allocation for strings (5 points)

Output:   (39%)

            User clearly understands what is being requested for input (5 points)

            Search and sort tasks perform correctly (7 points)

            Print and calculate tasks perform correctly (4 points)

            Update tasks perform correctly (6 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 (8 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