Due Date:             See class website for due date of Lab #2 design and of Lab #2 assignment

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

 

Grade value;         10% (out of 100% for all grades) of total of lab grades.

 

Topic objectives:         Control structures                                                                      Structs

                                             Strings                                                                                             Pointers

                                             File input                                                                                        Recursion

                                             Modular programming structure                                         Program design

                                             Error checking                                                                            Programming style

 

The goal for this lab is to practice the design and development of structs for data representation and to manipulate arrays of structs. This lab will use strings and file input. This lab will have you create a simple recursive function as well. As in Lab #1 you will be required to create a design document and turn it in prior to the due date of the lab. All material that has previously been covered may also be used in this lab.

 

This assignment has an overview section, a task description section, an implementation requirements section, a grading scale, and a deductions section. If there is additional info needed it will be in a miscellaneous section at the end of this lab assignment. Read ALL of the assignment before you start trying to develop the 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), continue, or linked lists.

*--*--*--*--*--*--*--*--*--*--*--*--*--*--*--*--*--*--*--*--*--*--*--*--*--*--*--*--*--*--*--*--*--*--*--*--

 

In Lab #1 you started developing the Campus Activity System, CAS. Throughout the course of this semester you will work on your CAS. Each lab assignment will build on the previous assignments and will also implement changes to make the system more efficient and so on. In this Lab#2 you will be modifying this program to improve the data representation and you will be adding some functionality to the program. You will also be finding information about more of the UTA campus activities and groups. Your goal for this program will be to continue to develop a computer system that helps students learn about activities and groups on campus that they might want to get involved in.

 

The tasks for this Lab #2 assignment will be:

 

*                      Introduce the Campus Activities System to a new user.

*                     Define a struct data type to hold all the information about a campus activity/group

*                     Create an array of the structs to store the CAS data in and then populate the arrays with data.

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

1) Using the data in the array,

         A)   Search for activity and group choices and data by

         i.      Group number

         ii.     Group name

         iii.    Meeting day and time

         iv.    Purpose

B)    Count how many groups/activities have a specific purpose

C)    List all the groups/activities that meet a certain criteria

         i.      Member type including groups that allow supersets of the member type, i.e. if you are looking for groups that allow sophomores '2', then you must also include groups that allow all undergraduates 'U' and groups that allow all students 'A'.

         ii.     Size

D)   Calculate

         i.      Cost to join all groups/activities

         ii.     Average cost to join any activity of a particular purpose (e.g. average cost to join any social group)

         iii.    Average length of a group meeting

E)    Sort data in the arrays based on

         i.      Group number

         ii.     Group name

         iii.    Meeting time

         iv.    Next meeting date

2) Update the data in the arrays–this will take the user to a submenu for doing updates

3) 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) Various constants will be given for use in lab #2.

b) Group names have a max length of 50 characters for this lab.

c) All groups/activities will have a unique number.

d) Your program must check data VALUES at input but not data TYPES. The user is responsible for putting in the correct data type as long as your program clearly tells the user what to do. If the use inputs the wrong type (char when int is required), then this type of error is NOT counted as an execution error in your program.

 

Task Descriptions:

 

¨                     Introduce the Campus Activity 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. (You do NOT have to clear the screen after the menu. Just let it scroll off the screen as more data is printed.)

 

¨                     Define a struct data type to hold all the information about a campus activity/group

Define a struct data type that is global to the program. The struct should be able to hold all of the data listed below for any ONE group or activity. The struct type will then be used to create the array of struct variables to hold the data values.

 

For lab #2, the following data will be used:

 

1.     Number representing the group or activity

 

2.     Name of group or activity (can be multiple words but no word will start with a digit, i.e. “UTA Students4 Peace” is legal but “UTA Students 4 Peace” is not.)

 

3.     Meeting time consisting of

         a. time of day given as hour and minute and then an ‘a’ for a.m. or a ‘p’ for p.m.

         b. day of the week given as one letter (MTWRFSN)

         c. week of the month given as ‘1’ for first week, ‘2’ for second week, ‘3’ for third, ‘4’ for fourth

         d. next meeting date given as dd/mm (with the slash mark)

 

4.     Meeting location consisting of

         a. UTA building abbreviation (no more than 4 chars in length, all one word) Ex. NH, MAC, UC…

         b. a room number in the building (no more than 5 chars in length, all one word)

 

5.     Purpose of the group. The purpose must be one of the following as denoted by the letter preceding it:

         F – fun and social organization/activity just to meet like minded people

         V – volunteer organization/activity that does service activities of any type

         A – academic; offers some sort of academic focused purpose such as tutoring, mentoring, study group, etc.

         S – sports; opportunities to play or support teams

         P – professional; focused on providing support to student for future professions

         M – fine arts; music, dance, art, theatre and other types of arts activities

         L – leadership; opportunities for leadership on campus or learning skills for leadership

         C – cultural; offers support and education related to a specific culture or group of cultures

         O – other

 

6.     Member type. Specifies what types of students are eligible to be members. If more than one of these categories applies, then for Lab #2 select the category that includes the largest number of potential members. Member types are;

         A – all students

         G – graduate students only

         M – Master’s level graduate students only

         P – Doctoral level graduate students only

         U – undergraduate students only

         4 – seniors only

         3 – juniors only

         2 – sophomores only

         1 – freshmen only

         E – engineering majors only

         B – business majors only

         L – liberal arts majors only

         S – science majors only

         R – architecture students only

         N – nursing students only

         S – social work students only

 

7.     Size. Gives number of group members or activity participants

 

8.     Cost. Gives cost to participate in the group or activity for one year

 

9.     National affiliation. Y or N to indicate if this is part of a larger national group or local to UTA.

 

10.  State affiliation. Y or N to indicate if this is part of a larger state group or local to UTA.

 

 

The details for the members of the struct data type are described below:

 

o         Group/activity number - the numeric code associated with a specific group or activity. (ex. The Big Event = 004, SWE = 132, Student Senate = 488, etc.). For all the other pieces of data, the information that is in the same struct inside the array will refer to the same activity/group. (See the group/activity code list at the end of this assignment and you can add to it if desired.)

o         Group name - the string giving the name of the associated group/activity. This should be declared in the struct as a char pointer. Each name string should be read in to a temporary array, the length of the string should be found, space should then be malloced to the char pointer in the struct to hold the size of the name, then the name should be copied from the temp array to the struct char pointer space.

o         Meeting time - the hour and minute info for the meeting time of the associated group/activity. The time is represented as HH.MM as a floating point number. Make sure that the meeting hour and minute that are entered are valid.

o         Meeting half day - the a.m. or p.m. info for the meeting time of the associated group/activity. Make sure that the character that is entered is valid.

o         Meeting day - the day of the week info for the meeting time of the associated group/activity. Make sure that the character that is entered is valid, i.e. that it is one of the allowed characters.

o         Meeting week - the week info for the meeting of the associated group/activity. Make sure that the meeting week that is entered is valid, e.g. how many weeks could there be in a month?

o         Next meeting day – the date of the next meeting as a two digit number. Be sure to check for validity.

o         Next meeting month – the month of the next meeting as a two digit number. Be sure to check for validity.

o         Meeting building - the 4-letter building designation for the meeting location of the associated group/activity. Declare this as a 4 char array in the struct.

o         Meeting room - the 5-character room designation for the meeting location of the associated group/activity. Ex. 314A. Declare this as a 5 char array in the struct.

o         Group/activity purpose - the code of the purpose of the associated group/activity. Make sure that the character that is entered is valid, i.e. that it is one of the allowed characters.

o         Group/activity member type - the code of the types of students allowed to be members of the associated group/activity. Make sure that the character that is entered is valid, i.e. that it is one of the allowed characters.

o         Group/activity size - the number of people involved in the associated group/activity.

o         Group/activity cost - the amount in dollars and cents that it costs to participate in the associated group/activity. Make sure this amount is not negative but it can be free to participate.

 

 

 

 

¨                     Create an array of structs to store the group or activity data in and then populate the structs in the array with data.

 

For Lab #2, the data above will be stored in structs in one array. The array will have 20 structs in it for a maximum of twenty groups/activities being described. (Use constants for these numbers.)

 

For lab #2, you must implement at least two methods of input and file input must be one of the input methods. The three forms of the input and the input data file are described below.

 

For lab #2 the user must enter at least 12 activity/groups and no more than 20 activity/groups. Since the user has a choice, then the first piece of data that the program needs from the user is a count of how many activity/groups they are entering. The program should check to make sure this count is between 12 and 20. [Note for development: start with a smaller number of activity/groups then increase to 12 when program is working well ] If the user’s number exceeds 20, the program should inform the user that 20 is the maximum number of inputs allowed and have them reenter the count. Then your program must loop for count number of times (index= 0, 1, …count-1) to read and store input in one of the three following ways: Individual data method, line of data input method, or file of lines input method.

 

Individual data method (These can be done in any order)

a.     Ask the user for the activity/group code (don’t forget to supply a list of names and codes for them.) Read in their number, make sure it is a valid code and then store it in the Group/activity number member of the struct at the current index in the struct array.

b.     For the group size do the same things using the code descriptions where appropriate (don’t forget to supply a list of codes for them) and making sure to check that the input values are meaningful. Store them in the Group/activity size member in the same struct at index. [Note: checking validity where appropriate means to check the value IF there is something to check against. For meeting hours there is a clock to check against. For group size, as long as it is a positive number, there isn’t anything else to check against for this lab.]

c.     Ask the user for the week of the month that the activity/group meets. Make sure it is a valid number and then store it in the same struct.

d.     Ask the user for the meeting time in the format HH.MM. Make sure the hour values and the minute values are valid. Store the time value in the same struct.

d.     For the meeting half-day ask the user for the value and make sure it is valid. Store it in the same struct.

e.     For the remaining data values that are letter codes (Meeting day, Purpose, Activity/group member type), ask the user for the data using the single character descriptions (don’t forget to supply a list of abbreviations for them.) Read in their char, make sure it is a valid abbreviation and then store it in the appropriate members of the same struct.

f.      For the name string, read in each string into a temporary array, check to make sure the string length is valid, then if it is, copy the string into the character array in the same struct.. If the string is too long, copy only part of the string into the character array.

g.     For the remaining numeric values, read the associated values for that activity/group. Make sure they are valid values and then store them in the same struct..

 

Line of data input method

Your program may ask the user to enter all the information for one activity/group on the same line. This data would be an integer for activity/group code, an int for size, an int for week of the month, float or double for meeting hour and meeting minute, chars for half day and day of week, chars for purpose and member type, strings for building abbreviation, room number and group name, and a float or double for cost. You must tell the user exactly how to enter the line of data. The data for a single activity/group will be entered by the user as values on one line as follows. There must be one space only between the values, and the building must have 4 chars (blanks are OK), and the room number must have 5 chars.

 

> 132 43 1 12.0 p M 10/12 P E NH 110 15.00 Society of Women Engineers

 

which represents the SWE (Group 132) with 43 members meeting in the 1st week of the month at 12:00pm (which is noon) on Monday. The next meeting is 10/12. It is a professional organization for engineering students, it meets in Nedderman Hall room 110, the yearly cost is $15.00 and the group name is “Society of Women Engineers”.

 

Your program will read the first number and store it in group number member of the struct at [index], then read and store the size and store it in the group size member of the same struct. All the other pieces of data would be read into the appropriate members of the same struct except the name string which should be read into a temporary array as described earlier. Your program should read multiple input values within a single input command but multiple input (scanf) commands can be used. Your program should read in as many lines of input for activity/groups as were originally specified by the count up to the maximum of twenty lines of input (activity/groups).

 

File of lines input method

You may create a file that contains between 12 and 20 lines of activity/group data and you may read the data from this file. To do this will requires creating file variables, opening the file and linking it to the file variable, and then reading the data from the file variable in the same way that a line of data would be read from the screen. This must be done using C file commands. The first line of data in the file should have only one integer on it which is the count of the number of lines of activity/group data which follow in the file. All the other lines in the file will have the same format as the line of data described above.

 

Input verification:

When the user has entered count number of activity/groups, print out all the input activity/group data in an easily readable form, ex. use a table with headings, or columns with headings or rows with labels. It is required 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 arrays.

 

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

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.          Search for a type of activity/group by number

ii.        Search for a type of activity/group by name

iii.      Search for a type of activity/group by meeting day

iv.      Search for a type of activity/group by purpose

v.        Count how many groups/activities have a specific purpose

vi.      List all the activity/groups that accept a certain member type

vii.    List all the activity/groups that are equal or greater than a certain size

viii.  Calculate cost to join all groups/activities

ix.      Calculate average cost to join a groups/activities of a particular purpose

x.        Sort data by group number

xi.      Sort data by group name

xii.    Sort data by meeting time

xiii.  Sort data by next meeting date

xiv.  List all the activity/groups

xv.    Update the data in the arrays

xvi.  End the program

 

i. The search by group number should use recursive binary search to determine if the group number is in the array(list). It should find any group with the matching group number, then print a sentence stating that matching code/day was or was not found and if found, it should also print the code and the name and other data of the group/activity.

 

ii, iii, iv. The other search functions should let the user choose group name or meeting day or purpose code and then look through the list to find the first activity/group that matches that type, then print a sentence stating that matching code/day was or was not found and if found, it should also print the code and the name of the group/activity.

 

v. The count function should let the user choose a purpose code and then go through the data and count (#) how many groups/activities have that purpose. The output should be a sentence stating that the number of groups/activities with that purpose is #.

 

vi. The member type list function should let the user choose a member type (using the codes your program gives them) and then should print all the groups/activities that allow that member type. This one is a little tricky in that some groups are subgroups of others, e.g. if the user chooses type 3 for juniors then any group that accepts U undergrads also accepts juniors and any group that accepts A all students also accepts juniors. Make sure to print a message at the top of the list explaining what is being printed.

 

vii. The size list functions should let the user choose a size value and then should print all the groups/activities that are of that size or larger. Make sure to print a message at the top of the list explaining what is being printed.

 

viii. The calculate function simply goes through and sums up all the costs for all the groups/activities. Print this sum with a message.

 

ix. The calculate average cost function asks the user to choose a purpose (from the list of purpose codes), then goes through the list sums all the costs of groups with that purpose and then divides by the number of those groups to get the average cost of that type of group.

 

x, The sort data by group number will do a recursive merge sort on the list and order the structs in the list from smallest group number to largest group number. Print all the sorted data.

 

xi. The sort data by group name will do a selection sort on the list and order the list alphabetically by name. Print all the sorted data.

 

xii. The sort data by meeting time will do a bubble sort on the list and order the list from earliest time in the morning to latest time at night ignoring what day the groups meet. Print all the sorted data.

 

xiii. The sort by next meeting time can use any sort method to order the list from soonest date to latest date. If two meetings have the same date, sort those by earlier to latest meeting time. If the meeting time is also the same, any order is OK. Print all the sorted data.

 

xiv. The list activity/groups function is the same as the print function described for input verification.

 

xv. The update option should take the user to a second screen to allow them to update information in the arrays. This screen should ask for a activity/group code from the user and search for that activity/group. Once the correct activity/group is determined save its [rowindex] and give the user a menu of the following options:

 

o                      Change Group name at [rowindex]

o                      Change Meeting time, half day, day, or week at [rowindex]

o                      Change Meeting building, or room at [rowindex]

o                      Change Purpose at [rowindex]

o                      Change Member type at [rowindex]

o                      Change Size at [rowindex]

o                      Change Cost at [rowindex]

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. After each change is made, print all of the activity/group info for the activity/group at [rowindex]. [Hint: If you write your data entry section with little functions for each input check then you can reuse them all here.]

 

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

 

Implementation requirements:

 

DESIGN YOUR PROGRAM FIRST BEFORE CODING. The design should include a list of the functions you expect to write with brief (one line) descriptions and a diagram showing what function calls what other functions. This diagram should start with the main function at the top and all others below it. Each function should accomplish one main purpose and each function at a lower level should have a more specific purpose than the function that calls it. This design documentation is required to be turned in for Lab 2. The lab design is due at least ONE WEEK before the lab is due. The design may be text, graphics, handwritten or whatever. If not computer generated, please scan it in (go to the computer lab or library). E-mail your design document to the Lab2 TA (not same as Lab1 TA) for you turn it in. Use a name for your document that starts with “Lab2 Design xxx1234” where xxx1234 is your login ID. Design documents must be turned in in order for Lab assignments to be graded.

 

Program requirements

 

For Lab #2 the program should use the following data structures:

Struct data type to hold all activity/group data for one group

Array of structs to hold data for up to 20 groups

Global CONSTANTS for specific index and/or maximum values given in this assignment. Constants can be done with

#define or with the const declaration. Examples:

 

#define GROUPMAX 20

const int GROUPMIN = 12;

 

The program should use the following control structures:

Function calls to perform tasks

Recursive binary search

Recursive merge sort

A while or for loop to read the input data

If, if-else, nested ifs, or switches to error check and implement the menu options

 

The program should NOT use:

global variables

exit

break (except in switch)

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 getting input, one for printing, one for a binary search function, one for a general search function, three for sorting, and two for calculating. You may use many more functions than this but you must use at least this many.

 

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 values from the keyboard

Print the appropriate outputs

Let the user enter additional values until the user indicates that they are finished.

 

The program should 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, should 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 program must be run and the output 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.

 

Programs turned in for credit must compile and run without any compilation errors or runtime errors. Programs may be partially complete but all completed functions must run without any errors. A program has a runtime error if it runs but then crashes in any situation, i.e. if there is any set of choices the user can make that will make the program crash. EXCEPTION: Your program must check data VALUES at input but not data TYPES. The user is responsible for putting in the correct data type as long as your program clearly tells the user what to do. If the user inputs the wrong type (e.g. char when int is required), then this type of error is NOT counted as an execution/runtime error in your program.

 

 

Grading scale:

Code:     (54%)

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!) (3 points)

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

Correct definition of struct

         All members defined as needed (7 pts)

         Correct use of char * as defined for name (1 pts)

Correct use of required file input (5 pts)

Correct input of name string as defined

         Use of dynamic space allocation (3 pts)

         Use of string functions (2 pts)

Correct implementation of bubble sort for ints and floats (2 points)

Correct implementation of selection sort for strings (2 points)

Correct implementation of recursive binary search (it is allowed to use textbook as source) (5 pts)

Correct implementation of recursive merge sort (it is allowed to use textbook as source) (5 pts)

Correct use of required control structures (3 points)

Correct function structure as required (2 points)

Proper implementation of data input and input error checking (3 points)

Output:  (46%)

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

                  Linear search (find) tasks perform correctly (3 points)

                  Binary search tasks perform correctly (5 pts)

                           Necessary precondition insured prior to searching (2 pts)

                  Bubble sort tasks perform correctly (3 points)

                  Selection sort tasks perform correctly (3 points)

                  Merge sort tasks perform correctly (6 points)

                  List member type task perform correctly (3 points)

                  Calculate tasks perform correctly (3 points)

                  Update tasks perform correctly (5 points)

                  Input verification shows valid values and list of inputs correctly saved and printed (3 points)

                  Output gives clear information to explain the values to the user (3 points)

                  Output contains all the given test data and one additional data set (4 points)

Grading Deductions:

                  Use of global variables will result in an overall grade of 0 (zero)

                  Use of the exit, break (outside a switch), or continue command will result in an overall grade of 0 (zero)

                  Labs which have execution errors in them and do not terminate normally will receive an overall grade of 0 (zero)

EXCEPTION: Your program must check data VALUES at input but not data TYPES. The user is responsible for putting in the correct data type as long as your program clearly tells the user what to do. If the user inputs the wrong type (e.g. char when int is required), then this type of error is NOT counted as an execution/runtime error in your program.

                  Labs which have compilation errors in them and do not compile will receive an overall grade of 0 (zero)

                  Use of linked lists will result in 50 (fifty) point deduction per use

                  No submission of design document to appropriate TA 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 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:

 

Activity/group code list:

The Big Event = 004

Oozeball = 008

Bed Races = 010

JCEO/ESC = 130

SWE = 132

SHPE = 133

NSBE = 134

TSPE = 135

ACM = 140

GDC = 141

IEEE = 150

IIE = 160

BMESS = 170

BMES = 171

SACNAS = 221

Concert choir = 512

Marching band = 525

Student Senate = 488

FLOC = 490

UTA Volunteers = 491

BSA = 610

FSI = 630

 

Sample data:

008 120 3 6.0 p F 10/9 S A MAC VB1 20.00 Oozeball

490 88 3 12.30 p W 10/7 V A UC 212A 0.0 Freshman Leaders on Campus

132 43 1 12.0 p M 10/12 P E NH 110 15.00 Society of Women Engineers