Page 1 of 12
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 a
ays.
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 a
ays
ï‚· 2 dimensional char and int a
ays
ï‚· getting data from the user into the various a
ays
ï‚· using only part of an a
ay for valid data
ï‚· computing a
ay arithmetic – vector inner products to compute a value
ï‚· sorting using selection sort
ï‚· displaying data in a
ays
Interaction
Outline:
1. Get the ticket price for each 3 categories.
a. float float float
2. Get the band name and numbers of fans for each category of each concert.
a. String int int int
. NOTE: spaces are not allowed in the band names, so use underscores instead of spaces.
c. Period will end the input.
3. Internal computations:
a. Compute the value of the sales for each concert.
. Compute the total value of the ticket sales.
c. Sort the concerts by value of the ticket sales.
4. Display the resulting data in a nice format.
Notes:
1. This program is not expected to behave nicely if the input does not follow the specifications
above.
2. All numbers this program will handle should be of moderate size. The exact meaning of
moderate is made precise by the data types, print statements, and a
ay sizes.
Page 2 of 12
Analysis
1. Since we are going to do sorting, we will need to hold the data in a
ays.
2. We will use functions to simplify the code, and reflect a modular approach to the design of the
project.
3. We will use global variables to reduce the amount information transfe
ed in parameter lists.
4. We will use a fixed number of categories, but let the number of concerts by determined by the
user at run time, up to a maximum value.
5. The user will end inputting the group information with a flag value, a period.
6. Basic data types
a. ticket prices – float
. name of concert
and – char a
ay
c. number of concerts and number of fans in each category at each concert – int
d. number of concerts – int.
e. value of tickets – float
7. We will use nested loops to handle most operations:
a. reading the ticket prices
. reading the group name and attendance
c. computing the value of the ticket sales
d. printing the a
ay of data
e. sorting the a
ays by the value of the ticket sales
Page 3 of 12
Pseudo-code:
Global variables:
ï‚· Constants using define declarations
o MAXN – the maximum number of characters in a band name
o MAXG – the maximum number of concerts
ands/groups
o MAXC – the maximum number of categories
ï‚· A
ays:
o char group [MAXG][MAXN] – the name of each group
o int fans [MAXG][MAXC] – the number of fans at a concert by category
o float prices [MAXC] – the ticket price of each category
o float sales [MAXG] – the total value of the tickets for each concert
ï‚· int count
o the actual number of active concerts
ands/groups
o this number is determined at run time in the getData function
o used throughout the rest of the program to only look at data in the group, fans and sales
a
ays that is actually active.
Pseudo-Code:
1. main
a. getData – get ticket prices by category & get data for the concerts
. computeSales – compute sales for each concert
c. printA
ay – print raw concert data
d. sortBySales – sort the concerts by value of sales, use selection sort
i. findMinSales – find min sales in unsorted rest of a
ay
ii. switchRows – as needed
e. printA
ay – print sorted concert data
2. getData
a. prompt for ticket prices
. get ticket prices into prices a
ay
c. prompt for band name and fans in each category at each concert
d. insert data into appropriate a
ays, ending with a period
i. loop on concert
1. get group name
2. loop inside on number of categories
3. computeSales
a. for each group
i. sales for that group = 0
ii. for each category
1. sales = sales + price of category * number of fans in that category
Page 4 of 12
2.
4. printA
ay
a. print column headers
. for each group
i. print the group name
ii. for each category
1. print the number of fans in that category
iii. print the sales for that concert/group
5. sortBySales
a. COMMENTS: for each row (group + fans + sales)
i. for each row index, starting at index 0
ii. the rows that have indices less than the cu
ent index are sorted, and are
already the smallest sales elements in the entire data set.
iii. thus, the next step is to find the smallest sales row in the remaining elements
and switch that row with the cu
ent index row
. for index = 0 to number of active rows, step index by 1
i. target = findMinSales (index)
ii. if target not equal to index, switchRows (target, index)
6. findMinSales (index)
a. set target as index
. min
c. for the rest of the a
ay, starting at index+1, indexing by i
i. if sales [i] < min
1. target = i
2. min = sales [target]
d. return target
7. switchRows (m, n)
a. Temporary locations
i. char tc
ii. int ti
iii. float v
. switch group names by stepping through all the letters (i) in each char a
ay:
i. tc = group [m][i]
ii. group [m][i] = group [n][i]
iii. group [n][i] = tc
c. switch fan entries, stepping by (i) over the fans a
ay:
i. ti = fans [m][i]
ii. fans [m][i] = fans [n][i]
iii. fans [n][i] = ti
d. switch sales:
i. v = sales [m]
ii. sales [m] = sales [n]
iii. sales [n] = v
Page 5 of 12
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
ealistic test sets.
Test
Case
Input Actual Output using repl.it – user input in red:
1 1 2 3
a 1 2 3
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
3 3 1
c 5 3 1
d 3 3 5
e 1 1 2
f 9 4 3
g 4 5 6
.
XXXXXXXXXXConcert s1 s2 s3 Sales
XXXXXXXXXXa XXXXXXXXXX14.00
XXXXXXXXXXb XXXXXXXXXX12.00
XXXXXXXXXXc XXXXXXXXXX14.00
XXXXXXXXXXd XXXXXXXXXX24.00
XXXXXXXXXXe XXXXXXXXXX XXXXXXXXXX
XXXXXXXXXXf XXXXXXXXXX26.00
XXXXXXXXXXg XXXXXXXXXX32.00
--- Sorted ---
XXXXXXXXXXConcert s1 s2 s3 Sales
XXXXXXXXXXe XXXXXXXXXX XXXXXXXXXX
XXXXXXXXXXb XXXXXXXXXX12.00
XXXXXXXXXXc XXXXXXXXXX14.00
XXXXXXXXXXa XXXXXXXXXX14.00
XXXXXXXXXXd XXXXXXXXXX24.00