Lab Assignment #4, CSE 1320-001 Fall 2008

 

Due Date:        Thursday, Dec. 11 at Midnight ABSOLUTELY NO LATE LABS accepted

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

 

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

 

Topic objectives:   Classes

                              Objects

                              Methods

                              Overloading

                             

The goal for this lab is to provide an application of 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 have worked on developing the team competition data analysis program.  For this last lab Lab #4 you will now look at how some of the team data and members might be captured and manipulated in an object oriented fashion.  You will implement at least two classes and you will have objects of these classes interact with each other.  You will use const data (from #include “C1320F08L4testdata.h”) like what you have used previously to generate objects of these classes. 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 #4 will be:

 

¨      Introduce the team data analysis system to a new user.

¨      Create two classes – one for student team members and one for teams – which contain all the data given below and the necessary methods to set, get and display that data as well as perform some specified functions.

¨      You will create arrays of member and team objects and populate them using the data that is given to you in the include file.

¨      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.   Get a list of all the student teams (by name) that compete in engineering competitions and print all of their data

iii.  List the members of a team and print all of their data

iv.  Count the members of a team

v.   Sort the team member array by last name or team name

vi.  Search for a particular team or team member by name

2) 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 #4:

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

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

c) Given team member count is GIVEMEMBERS.

d) Given teams is GIVETEAMS.

e) A student is on a max of one team.

 

 

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 a student team member class

For lab #4 you will create a class to hold a team member.  The team member class will need to hold the same data as the UTAstdt struct below. The data below should be private data. The class will also need member functions (methods) as described below the struct definition:

 

const struct UTAstdt{

            char *lastname;

            char *firstmidname;

            long int UTAID; //min valid value is 2000000000, max is 2000999999

            double cumGPA; //min valid is 0.0, max is 4.0

            char major[5];  // default value is “ENG”

            char *competition;  // when a value is stored here, verify that there is a matching team object

            char *teamname; // when a value is stored here, verify that there is a matching team object

            char gender;  // M, F or U for Unknown or Unreported; default is U

}

 

 

For the team member class in addition to the data elements from above, you must also include public member functions which allow a user to access the private data.  That means you must have at least a “set”, “get”, and “display” function for each piece of data listed above.  These member functions must be prototyped in the class definition file (for example, “teammember.h”) and then written in the associated function file (teammember.cpp). 

 

If the data can be validated then this should be done in the “set” functions to insure that only valid data will be stored in the data member of the class.  As an example, the function to set a gender value should only allow the value to be ‘M’, ‘F’, or ‘U’.  If the proposed value is not one of these three then the set function should handle that problem so that there is a valid value for gender.  For the teamname and competition, when these values are being set, the set function should verify that there is some existing object that has the same teamname and/or competition.  If no such object exists then the needed team object should be created.

 

As an additional function, you should have a display function for the class which will print out all of the data of the team member in a nice format.

 

Create a team class

Along with the teammember class you will also create a class to hold a team.  The team member class will need to hold the same data as the UTAteam struct below. The data below should be private data. The class will also need member functions (methods) as described below the struct definition:

 

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; must be after 2006

            int membercount;        // Number of team members; must be > 0

            struct UTAstdt *memberlist[MAXMEMBERS];  //this has to modified so that it holds OBJECT references for this lab

};

 

For the team class in addition to the data elements from above, you must also include public member functions which allow a user to access the private data.  That means you must have at least a “set”, “get”, and “display” function for each piece of data listed above.  These member functions must be prototyped in the class definition file (for example, “team.h”) and then written in the associated function file (team.cpp). 

 

If the data can be validated then this should be done in the “set” functions to insure that only valid data will be stored in the data member of the class.  Additionally, you should have a display function for the class which will print out all of the data of the team member in a nice format.

 

Notice that the memberlist data element is an array of pointers (or references) to team members.  The set function for this member should go through the teammember object array and should record a reference to every team member who is associated with this team.  This will capture all the members of the team that are currently in the member array.  The get and display functions for the memberlist should always run the set function first before doing these task – this is because the member array might be rearranged and the old references might not be accurate.  By running the set function before printing or returning the member list, the team object guarantees that the member list is always accurate for the current member array.

 

Create an array of team member objects

For Lab #4, we will go back to using arrays instead of linked lists.  You will create an array of GIVEMEMBER number of team member objects and then will use the data in the giventeammembers array to populate these objects with information.  This means that you will need to look at the values in each giventeammember and put it into the corresponding object using the set function for that member.  For example if you have a temporary member object called Temp then you would need to do an assignment similar to the following to put the GPA from a giventeammember into Temp:

 

Temp.set_GPA(giventeammembers[i].cumGPA); 

 

Once you have put all of the data from a giventeammember into the Temp object, then you can assign Temp directly to one of the elements in the team member object array.  This would then be repeated for all the members in the giventeammembers array until they are all recorded in the team member object array

 

The giventeammembers array will be given in the #include file as before and will be of the form:

           

const struct UTAstdt giventeammembers[GIVEMEMBERS] =

{

{“Patel”, “Joshua”, 2000457234, 3.245, “CE”, “Steel Bridge”, “Blaze”, ‘M’},

// …another 23 records like this

{“Smith”, “Yan Akiba”, 2000943211, 2.87, “CS”, “ICPC”, “UTA Blue”, ‘U’}

};

 

Input verification:

When the program has put all of the giventeammembers information into the team member object array, it should print out all of the team members object data 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 array.

 

 

Create an array of team objects

Also for Lab #4, we will use an array for the teams.  You will create an array of MAXTEAMS (this is corrected - it previously said GIVETEAMS. 12.8.08 Dr. T) number of team objects and then will use the data in the giventeams array to populate the team object array.  This will be done in a fashion exactly similar to that described above for the team members.

 

The giventeams array will be given in the #include file as before and will be of the form:

 

const struct UTAteam giventeams[5] =

{

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

// … more records like this

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

};

 

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 set_membercount function should check this value from the giventeams array when it is being put into the team object array and do the following: 

If the number of team members is positive, then store it; else if it is -1, run the team member counting function (menu choice iv.) and store the result as the number of team members. 

 

Input verification:

When the program has put all of the teams into the team object array, it should print out all of the team data 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 object 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, advisor, year of competition and number of team members)

iii-  List the members of a team by name (give all the team member info)

iv-  Count the total number of team members for a particular team

v-   Sort the member object array by

      a. Last name

      b. Team name

vi- Search for a particular team member by last name  

vii-Search for a particular team by team name

viii- End the program

 

The competition list function (i) should print a list of all the competitions that are named in team object array giving each competition only once.  It is suggested that you number this list as you print it so that you can then use 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 team object 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 team member object array for a given team chosen by the user. This function can use the team object for that team and the member array there to find the team members if desired.

 

The count function (iv) should just count the number of members that are in the array for a given team chosen by the user. 

 

The sort-by-last-name function (v.a.) and the sort-by-team-name function (v.b.) will sort the teammember object array using any sorting algorithm.  (HINT: Do you really need two separate sorting functions to do this?)

 

The search options (vi. and vii.) should call search functions that perform linear search on the appropriate arrays 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.

 

When the user chooses “End the program” (viii.) from the main menu, print a concluding message and then gracefully end the program.

 

Implementation requirements:

The program should use the following data structures:

Classes with private data elements and public member functions for recording team member data and team data

Arrays of team member objects and of team objects

Global constants given as input data

 

The program should use the following control structures:

Member functions 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

 

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 two main classes, a team member class and a team class, which contain all the member functions needed to access the data elements in those classes.  The rest of the program structure will be the main routine, the print functions for the arrays, the count function, the sort functions, and the search functions. ((If we had time to talk about container classes, the print, count, sort, and search functions would be member functions of the container class.))  Try to keep the non-member functions to a minimum.

 

The program should perform the following actions in the given order:

Declare and initialize the variables/objects

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 class and function, i.e. each class and function you write, MUST have a class or function header similar to those used in the examples in the textbook.  This header should include at least the name, the purpose of the class/function, and the info.

 

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

Program header and class and function headers (4 points)

Comments (line comments and block comments)      (4 points)

Modularity  (7 points)

Style  (7 points)

Correct manipulation of the classes

      Class declaration of private data and public member functions (12 points)

      Member function definitions

            Set functions with error checking (12 points)

            Get functions (4 points)

            Display functions (6 points)

      Use of arrays of objects (5 points)

Correct functions developed for printing, counting, searching and sorting  (4 points)

Output:        (35%)

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

            Minimum use of non-member functions other than those required (3 points)

            Search and sort tasks perform correctly (6 points)

            Print and count tasks perform correctly (4 points)

            Object data is verified before being stored in object (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 (4 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)

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