






Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
Prepare for your exams
Study with the several resources on Docsity
Earn points to download
Earn points by helping other students or get them with a premium plan
Community
Ask the community for help and clear up your study doubts
Discover the best universities in your country according to Docsity users
Free resources
Download our free guides on studying techniques, anxiety management strategies, and thesis advice from Docsity tutors
A hands-on lab for developing a program that computes the value of ticket sales for concerts and displays the concert information in a sorted list. The lab uses C code and covers topics such as sequential, repetition, selection statements, functions, strings, and arrays. an analysis, test plan, and coding plan for the project.
Typology: Exams
1 / 12
This page cannot be seen from the preview
Don't miss anything!
CMIS 102 Hands-On Lab
Week 8 - Concerts
Overview This hands-on lab allows you to follow and experiment with the critical steps of developing a program including the program description, analysis, test plan, and implementation with C code. The example provided uses sequential, repetition, selection statements, functions, strings and arrays.
Program Description
Compute the value of the ticket sales for concerts and the total sales for a series of concerts. Then display the concert information in a sorted list.
Technologies used in this project:
strings stored as char arrays 2 dimensional char and int arrays getting data from the user into the various arrays using only part of an array for valid data computing array arithmetic – vector inner products to compute a value sorting using selection sort displaying data in arrays
Interaction
Outline:
Notes:
Analysis
Test Plan
To verify this program is working properly a variety of test cases should be used.
The following is just one test case, which only tests a very few aspects of the program.
You should be thinking about other data sets to test other aspects of the program, and also create more realistic test sets.
Test Case
Input Actual Output using repl.it – user input in red:
a 1 2 3 b 3 3 1 c 5 3 1 d 3 3 5 e 1 1 2 f 9 4 3 g 4 5 6 .
Enter ticket prices in each of 3 cateogories: 1 2 3 -- Enter group and fans in 3 categories
. to finish entries: a 1 2 3 b 3 3 1 c 5 3 1 d 3 3 5 e 1 1 2 f 9 4 3 g 4 5 6 . Concert s1 s2 s3 Sales a 1 2 3 14. b 3 3 1 12. c 5 3 1 14. d 3 3 5 24. e 1 1 2 9. f 9 4 3 26. g 4 5 6 32.
--- Sorted --- Concert s1 s2 s3 Sales e 1 1 2 9. b 3 3 1 12. c 5 3 1 14. a 1 2 3 14. d 3 3 5 24. f 9 4 3 26. g 4 5 6 32. ... bye ...
Task Description Notes 1 Hello world Get the basic environment working Get main method started Even change the message to Bye 2 #define stuff These tokens will be used in the array declarations, and throughout the code Getting the syntax of these declarations correct can be a challenge 3 Declare the arrays And count
The global variables this program will use. Get this syntax to work, and work with the define declarations 4 getData function Just get the declaration to compile correctly 5 Call getData in main Making sure we have the call syntax correct 6 Other function declarations
As specified in the pseudo-code. Again, we want to check with the compiler that we are using the correct syntax 7 TEST CODE: count = 1 values to one group
Give values for one concert in main: count = 1; // following requires #include <string.h> strcpy (group [0], "one"); fans [0][0] = 3; fans [0][1] = 12; fans [0][2] = 33; sales [0] = 23.23; 8 printArray Call this function from main. Focus on getting this function working Check the output for each step. Lots of steps: header line nested loops: loop over all groups, the group name, loop over the fan counts, sales 9 More test code Create another set of code like step 7 to test printArray more carefully 10 Call getData in main Start with a printf statement saying “got here” in getData 11 Print prompt For ticket prices of 3 categories, remove “got here” message 12 Get ticket prices Use for loop to get prices into sales array Add for loop to print the values in that array – temporary code 13 Get group loop For loop to get group name (index is i) Read group [i] Add test for name is period and break input loop if so TEST the period 14 Get fan numbers Nested for loop over the number of categories (index is j) Read fans [i][j] Increment count since this should be a valid group Temporary: set sales [i] to 44.56 or some other random number
15 Fix main Comment out the test code from steps 7 and 9 Insert the appropriate calls in main: getData (); printArray (); Test the code with real data! 16 computeSales Get this code working, using a loop Add the call to this function to main 17 Sorting Get the call to sorting active Add the print statement to say the following is sorted Print the “sorted” array (not sorted yet) 18 findMinSales Get this code working^ –^ starting at an index, find the index of the smallest sales in the rest of the list Use print statements to make sure this is working 19 switchRows Get this working – switch group name, the fans and the sales values 20 Final check Try a number of different data sets here.
} // end for each fan category v = sales [m]; sales [m] = sales [n]; sales [n] = v; } // end switch
int findMinSales (int m) { float min = sales [m]; int target = m; for (int i = m+1; i < count; i++) if (sales [i] < min) { min = sales [i]; target = i; } // end new max found return target; } // end function findMinSales
void sortBySales () { int target; for (int i = 0; i < count; i++) { target = findMinSales (i); if (target > i) switchRows (i, target); } // for each concert } // end function sortBySales
void getData () { // for (int i = 0; i < MAXG; i++) sales [i] = 0; printf ("Enter ticket prices in each of %d cateogories: ", MAXC); for (int i = 0; i < MAXC; i++) scanf ("%f", &prices [i]); printf ("-- Enter group and fans in %d categories\n", MAXC); printf (". to finish entries:\n"); for (int i = 0; i < MAXG; i++) { scanf ("%s", &group[i]); if (group [i][0] == '.') break; count++; for (int j = 0; j < MAXC; j++) scanf ("%d", &fans[i][j]); } // end for each group } // end function getData
int main(void) { getData (); computeSales (); printArray (); printf ("\n --- Sorted ---\n"); sortBySales (); printArray (); printf("... bye ...\n"); return 0; }
Learning Exercises for you to complete
NOTE: It is convenient to put each test case into its own data file so you don’t have to type a rather large set of input over and over again. Then you can just copy/paste the data into the interaction panel of the IDE you are using.