// C code
// This code will compute the values of the sales
// ticket sales for concerts
// and sort the entries by those values
// Developer: Taylor Clemons
// Date: Jul 29, 2019
#include <stdio.h
#define MAXN 100 // max characters in a group/concert name
#define MAXG 50 // max concerts/groups #define MAXC 3 // max categories
char group [MAXG][MAXN]; int fans [MAXG][MAXC]; float prices [MAXC]; float sales [MAXG]; int count = 0;
void printArray () { printf ("%15s%5s%5s%5s%10s\n", "Concert", "s1", "s2", "s3", "Sales");
for (int i = 0; i < count; i++) { printf ("%15s", group [i]); for (int j = 0; j < MAXC; j++) { printf ("%5d", fans[i][j]); } // end for each category printf ("%10.2f\n", sales [i]);
} // end for each group } // end function printArray
void computeSales () {
for (int i = 0; i < count; i++) { sales [i] = 0;
for (int j = 0; j < MAXC; j++) {
sales [i] += prices [j] * fans [i][j];
} // end for each category } // end for each group } // end function computeSales
void switchRows (int m, int n) { char tc; int ti; float v;
// printf ("Switching %d with %d\n", m, n);
for (int i = 0; i < MAXN; i++) { tc = group [m][i]; group [m][i] = group [n][i]; group [n][i] = tc;
} // end for each character in a group name for(int i = 0; i < MAXC; i++) {
ti = fans [m][i]; fans [m][i] = fans [n][i]; fans [n][i] = ti;
} // 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");
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
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;
}
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
1. Test Case 1
1.a.
// C code
// This code will compute the values of the sales
// ticket sales for concerts
// and sort the entries by those values
// Developer: Taylor Clemons
// Date: Jul 29, 2019
#include <stdio.h
#define MAXN 100 // max characters in a group/concert name
#define MAXG 50 // max concerts/groups #define MAXC 3 // max categories
char group [MAXG][MAXN]; int fans [MAXG][MAXC]; float prices [MAXC]; float sales [MAXG]; int count = 0;
void intro () {
printf("Welcome to the concert ticket sales calculator.\nTaylor Clemons\nCMIS102\n");
printf("You will enter ticket prices in each of 3 categories to determine the values of sales\n");
}
void printArray () {
printf ("%15s%5s%5s%5s%10s\n", "Concert", "s1", "s2", "s3", "Sales");
for (int i = 0; i < count; i++) {
printf ("%15s", group [i]); for (int j = 0; j < MAXC; j++) {
printf ("%5d", fans[i][j]); } // end for each category printf ("%10.2f\n", sales [i]);
} // end for each group } // end function printArray
void computeSales () { for (int i = 0; i < count; i++) { sales [i] = 0; for (int j = 0; j < MAXC; j++) { sales [i] += prices [j] * fans [i][j];
} // end for each category
} // end for each group } // end function computeSales
void switchRows (int m, int n) { char tc; int ti; float v;
// printf ("Switching %d with %d\n", m, n);
for (int i = 0; i < MAXN; i++) { tc = group [m][i];
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
group [m][i] = group [n][i]; group [n][i] = tc;
} // end for each character in a group name for(int i = 0; i < MAXC; i++) { ti = fans [m][i]; fans [m][i] = fans [n][i]; fans [n][i] = ti;
} // 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) { intro (); getData (); computeSales (); printArray ();
printf ("\n --- Sorted ---\n"); sortBySales (); printArray (); printf("... bye ...\n"); return 0;
}
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
1.a. Test Case 1
2.
// C code
// This code will compute the values of the sales
// ticket sales for concerts
// and sort the entries by those values
// Developer: Taylor Clemons
// Date: Jul 29, 2019
#include <stdio.h
#define MAXN 100 // max characters in a group/concert name
#define MAXG 50 // max concerts/groups #define MAXC 3 // max categories
char group [MAXG][MAXN]; int fans [MAXG][MAXC]; float prices [MAXC]; float sales [MAXG]; float total; int count = 0;
void intro () {
printf("Welcome to the concert ticket sales calculator.\nTaylor Clemons\nCMIS102\n"); printf("You will enter ticket prices in each of 3 categories to determine the values of sales\n");
}
void computeTotals () {
total = 0; for (int ts = 0; ts < count; ts++) { total += sales[ts];
} printf("\n%15s%25.2f\n", "Total Sales", total);
}
void printArray () {
printf ("%15s%5s%5s%5s%10s\n", "Concert", "s1", "s2", "s3", "Sales");
for (int i = 0; i < count; i++) { printf ("%15s", group [i]);
for (int j = 0; j < MAXC; j++) { printf ("%5d", fans[i][j]); } // end for each category printf ("%10.2f\n", sales [i]); } // end for each group computeTotals();
} // end function printArray
void computeSales () { for (int i = 0; i < count; i++) { sales [i] = 0; for (int j = 0; j < MAXC; j++) { sales [i] += prices [j] * fans [i][j];
} // end for each category
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
} // end for each group } // end function computeSales
void switchRows (int m, int n) { char tc; int ti; float v;
// printf ("Switching %d with %d\n", m, n);
for (int i = 0; i < MAXN; i++) { tc = group [m][i]; group [m][i] = group [n][i]; group [n][i] = tc;
} // end for each character in a group name for(int i = 0; i < MAXC; i++) { ti = fans [m][i]; fans [m][i] = fans [n][i]; fans [n][i] = ti;
} // 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) { intro (); getData (); computeSales (); printArray (); printf ("\n --- Sorted ---\n"); sortBySales (); printArray (); printf("... bye ...\n"); return 0;
}
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
2. Test Case 1
3. I changed the following:
line 11: #define MAXC 4;
• Changed to allow 4 max categories
Line 22: printf("You will enter ticket prices in each of 4 categories to determine the values of sales\n");
• Changed to print 4 categories to alert user
Line 30: printf("\n%15s%30.2f\n", "Total Sales", total);
• Changed to align print of “Total Sales” with “Sales” column
Line 34: printf ("%15s%5s%5s%5s%5s%10s\n", "Concert", "s1", "s2
", "s3", "s4", "Sales");
• Changed to add “s4” to headers
// C code
// This code will compute the values of the sales
// ticket sales for concerts
// and sort the entries by those values
// Developer: Taylor Clemons
// Date: Jul 29, 2019
#include <stdio.h
#define MAXN 100 // max characters in a group/concert name
#define MAXG 50 // max concerts/groups
#define MAXC 4 // max categories
1
2
3
4
5
6
7
8
9
10
11
12
char group [MAXG][MAXN]; int fans [MAXG][MAXC]; float prices [MAXC]; float sales [MAXG]; float total; int count = 0;
void intro () { printf("Welcome to the concert ticket sales calculator.\nTaylor Clemons\nCMIS102\n");
printf("You will enter ticket prices in each of 4 categories to determine the values of sales\n");
}
void computeTotals () {
total = 0;
for (int ts = 0; ts < count; ts++) { total += sales[ts];
}
printf("\n%15s%30.2f\n", "Total Sales", total);
}
void printArray () { printf ("%15s%5s%5s%5s%5s%10s\n",
"Concert", "s1", "s2", "s3", "s4", "Sales");
for (int i = 0; i < count; i++) { printf ("%15s", group [i]); for (int j = 0; j < MAXC; j++) { printf ("%5d", fans[i][j]); } // end for each category printf ("%10.2f\n", sales [i]);
} // end for each group
computeTotals();
} // end function printArray
void computeSales () {
for (int i = 0; i < count; i++) { sales [i] = 0;
for (int j = 0; j < MAXC; j++) {
sales [i] += prices [j] * fans [i][j];
} // end for each category } // end for each group } // end function computeSales
void switchRows (int m, int n) { char tc; int ti; float v;
// printf ("Switching %d with %d\n", m, n);
for (int i = 0; i < MAXN; i++) { tc = group [m][i]; group [m][i] = group [n][i]; group [n][i] = tc;
} // end for each character in a group name
for (int i = 0; i < MAXC; i++) {
ti = fans [m][i]; fans [m][i] = fans [n][i]; fans [n][i] = ti;
} // 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
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99 100
101
102
103
104
105
106
107
108
109
int main(void) { intro (); getData (); computeSales (); printArray ();
printf ("\n --- Sorted ---\n");
sortBySales (); printArray (); printf("... bye ...\n"); return 0;
}
110 111
112
113
114
115
116
117
118
119
120
121
122
Test Case
Input
Expected Output
1
Rush
Walk_the_Moon
Owl_City
Hammerfall
Avantasia
Behemoth Insomnium
.
20
100
300
500
30
100
90
40
30
200
300
30
30
100
40
50
50
300
100
100
50
20
30
60
100
400
10
70
30
400
60
8
Concert
Rush
Walk_the_Moon
Owl_City
Hammerfall
Avantasia
Behemoth
Insomnium
Total Sales
— Sorted —
s1 100
300
500
30
100
90
40
s2 200
300
30
30
100
40
50
s3 300
100
100
50
20
30
60
s4 400
10
70
30
400
60
8
Sales 63000.00
21000.00
22900.00
7000.00
46000.00
10500.00
6100.00 176500.00
Concert
s1
s2
s3
s4
Sales
Insomnium
40
50
60
8
6100.00
Hammerfall
30
30
50
30
7000.00
Behemoth
90
40
30
60
10500.00
Walk_the_Moon
300
300
100
10
21000.00
Owl_City
500
30
100
70
22900.00
Avantasia
100
100
20
400
46000.00
Rush
100
200
300
400
63000.00
Total Sales ... bye ...
176500.00
3. Test Case 1
4.
Test Case
Input
Expected Output
1
Plini
Sithu_Aye
Intervals Polyphia
.
30
30
40
30
40
50
20
50
30
60
100
50
20
40
40
200
20
20
10
15
Concert
Plini
Sithu_Aye
Intervals
Polyphia
Total Sales
— Sorted —
s1 30
40
30
40
s2 20
50
30
60
s3 50
20
40
40
s4 20
20
10
15
Sales
10900.00
9700.00
8400.00
11200.00
40200.00
Concert
s1
s2
s3
s4
Sales
Intervals
30
30
40
10
8400.00
Sithu_Aye
40
50
20
20
9700.00
Plini
30
20
50
20
10900.00
Polyphia
40
60
40
15
11200.00
Total Sales ... bye ...
40200.00
1
Chuck_Ragan
The_Aquabats
Avail
NOFX GWAR
.
10
50
70
60
90
150
20
40
50
35
80
200
40
40
20
20
80
50
80
18
20
25
28
60
Concert
Chuck_Ragan
The_Aquabats
Avail
NOFX
GWAR
Total Sales
— Sorted —
s1 50
70
60
90
150
s2 40
50
35
80
200
s3 40
20
20
80
50
s4 18
20
25
28
60
Sales 4340.00
4100.00
4100.00
7940.00
12300.00
32780.00
Concert
s1
s2
s3
s4
Sales
The_Aquabats
70
50
20
20
4100.00
Avail
60
35
20
25
4100.00
Chuck_Ragan
50
40
40
18
4340.00
NOFX
90
80
80
28
7940.00
GWAR
150
200
50
60
12300.00
Total Sales ... bye ...
32780.00
4. Test Case 1
4. Test Case 2
Test Case
Input
Expected Output
Test case 1 has the smallest element as the final element
1
Chuck_Ragan
GWAR
Avail
NOFX
The_Aquabats
.
10
50
150
70
90
70
20
40
200
35
80
50
40
40
50
20
80
20
80
18
60
25
28
20
Concert
Chuck_Ragan
GWAR
Avail
NOFX
The_Aquabats
Total Sales
— Sorted —
s1 50
150
70
90
70
s2 40
200
35
80
50
s3 40
50
20
80
20
s4 18 60
25
28
20
Sales
4340.00
12300.00
4200.00
7940.00
4100.00
32880.00
Concert
s1
s2
s3
s4
Sales
The_Aquabats
70
50
20
20
4100.00
Avail
70
35
20
25
4200.00
Chuck_Ragan
50
40
40
18
4340.00
NOFX
90
80
80
28
7940.00
GWAR
150
200
50
60
12300.00
Total Sales ... bye ...
32880.00
Test case 2 has all elements sorted in order
2
The_Aquabats
Avail
Chuck_Ragan
NOFX GWAR
.
10
70
70
50
90
150
20
50
35
40
80
200
40
20
20
40
80
50
80
20
25
18
28
60
Concert
The_Aquabats
Avail
Chuck_Ragan
NOFX
GWAR
Total Sales
— Sorted —
s1 70
70
50
90
150
s2 50
35
40
80
200
s3 20
20
40
80
50
s4 20
25
18
28
60
Sales 4100.00
4200.00
4340.00
7940.00
12300.00
32880.00
Concert
s1
s2
s3
s4
Sales
The_Aquabats
70
50
20
20
4100.00
Avail
70
35
20
25
4200.00
Chuck_Ragan
50
40
40
18
4340.00
NOFX
90
80
80
28
7940.00
GWAR
150
200
50
60
12300.00
Total Sales ... bye ...
32880.00
5.
Test case 3 has all elements sorted in reverse order
3
GWAR
NOFX
Chuck_Ragan
Avail
The_Aquabats
.
10
150
90
50
70
70
20
200
80
40
35
50
40
50
80
40
20
20
80
60
28
18
25
20
Concert
GWAR
NOFX
Chuck_Ragan
Avail
The_Aquabats
Total Sales
— Sorted —
s1 150
90
50
70
70
s2 200
80
40
35
50
s3 50
80
40
20
20
s4 60
28
18
25
20
Sales
12300.00
7940.00
4340.00
4200.00
4100.00
32880.00
Concert
s1
s2
s3
s4
Sales
The_Aquabats
70
50
20
20
4100.00
Avail
70
35
20
25
4200.00
Chuck_Ragan
50
40
40
18
4340.00
13
NOFX
GWAR
Total Sales ... bye ...
90
150
80
200
80
50
28
60
7940.00
12300.00
32880.00
5. Test Case 1
5. Test Case 2
5. Test Case 3
6.
a) I would increase the max allowable for fans and increase spacing to align all the output with larger numbers.
b) If ticket prices or fans are negative, the price * fan is a negative value and is subtracted from the total which decreases the Sales and Total Sales numbers.
c) My recommendation for negative values would be to insert error detection and reject all negative values. In a program such as this, there should be no values below zero when dealing in whole persons and money.
6.b. (1) Negative ticket price
6.b. (2) Negative fans
7. To sort on the 1st fans column instead of the sales column, I adjusted the ’findMinSales’ and ’sortBySales’ function in the program. ’sortBySales’ is renamed to ’sortByFansCat1’ and ’findMinSales’ is renamed to ’findMinFansCat1’. ’sortByFansCat1’ is executed first, so I changed the name of the function executed within that function to ’findMinFansCat1’. ’findMinFansCat1’ does the ”heavy lifting” of sorting. The fans array is a two-dimensional array, and since only the first column needs to be sorted, I added the first index ([0]) after the variable index to ensure sorting only happened on each row in the first column.
Test Case
Input
Expected Output
Test case 1 sorts on column s1 (fans index[0])
1
Chuck_Ragan
GWAR
Avail
NOFX
The_Aquabats
.
10
50
150
70
90
70
20
40
200
35
80
50
40
40
50
20
80
20
80
18
10
25
28
20
Concert
Chuck_Ragan
GWAR
Avail
NOFX
The_Aquabats
Total Sales
s1 50
150
70
90
70
s2 40
200
35
80
50
s3 40
50
20
80
20
s4 18
10
25
28
20
Sales 4340.00
8300.00
4200.00
7940.00
4100.00
28880.00
— Sorted —
Concert
s1
s2
s3
s4
Sales
Chuck_Ragan
50
40
40
18
4340.00
Avail
70
35
20
25
4200.00
The_Aquabats
70
50
20
20
4100.00
NOFX
90
80
80
28
7940.00
GWAR
150
200
50
10
8300.00
Total Sales ... bye ...
28880.00
// C code
// This code will compute the values of the sales
// ticket sales for concerts
// and sort the entries by those values
// Developer: Taylor Clemons
// Date: Jul 29, 2019
#include <stdio.h
#define MAXN 100 // max characters in a group/concert name
#define MAXG 50 // max concerts/groups #define MAXC 4 // max categories
char group [MAXG][MAXN]; int fans [MAXG][MAXC]; float prices [MAXC]; float sales [MAXG]; float total; int count = 0;
void intro () { printf("Welcome to the concert ticket sales calculator.\nTaylor Clemons\nCMIS102\n");
printf("You will enter ticket prices in each of 4 categories to determine the values of sales\n");
}
void computeTotals () {
total = 0;
for (int ts = 0; ts < count; ts++) { total += sales[ts];
}
printf("\n%15s%30.2f\n", "Total Sales", total);
}
void printArray () { printf ("%15s%5s%5s%5s%5s%10s\n",
"Concert", "s1", "s2", "s3", "s4", "Sales");
for (int i = 0; i < count; i++) { printf ("%15s", group [i]); for (int j = 0; j < MAXC; j++) { printf ("%5d", fans[i][j]); } // end for each category printf ("%10.2f\n", sales [i]);
} // end for each group
computeTotals();
} // end function printArray
void computeSales () {
for (int i = 0; i < count; i++) { sales [i] = 0;
for (int j = 0; j < MAXC; j++) {
sales [i] += prices [j] * fans [i][j];
} // end for each category } // end for each group } // end function computeSales
void switchRows (int m, int n) { char tc; int ti; float v;
// printf ("Switching %d with %d\n", m, n);
for (int i = 0; i < MAXN; i++) { tc = group [m][i]; group [m][i] = group [n][i]; group [n][i] = tc;
} // end for each character in a group name
for (int i = 0; i < MAXC; i++) {
ti = fans [m][i]; fans [m][i] = fans [n][i]; fans [n][i] = ti;
} // end for each fan category v = sales [m]; sales [m] = sales [n]; sales [n] = v; } // end switch
int findMinFansCat1 (int m) {
float min = fans [m][0]; int target = m;
for (int i = m+1; i < count; i++)
if (fans [i][0] < min) {
min = fans [i][0]; target = i;
} // end new max found return target;
} // end function findMinSales
void sortByFansCat1 () { int target;
for (int i = 0; i < count; i++) { target = findMinFansCat1 (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++)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
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) { intro (); getData (); computeSales (); printArray ();
printf ("\n --- Sorted ---\n");
sortByFansCat1(); printArray (); printf("... bye ...\n"); return 0;
}
98 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
7. (Test Case 1) Sort Fans Column 1
Test Case
Input
Expected Output
Test case 2 sorts on column s4 (fans index[3])
2
Chuck_Ragan
GWAR
Avail
NOFX
The_Aquabats
.
10
50
150
70
90
70
20
40
200
35
80
50
40
40
50
20
80 20
80
18
10
25
28
20
Concert
Chuck_Ragan
GWAR
Avail
NOFX
The_Aquabats
Total Sales
s1 50
150
70
90
70
s2 40
200
35
80
50
s3 40
50
20
80 20
s4 18
10
25
28 20
Sales 4340.00
8300.00
4200.00
7940.00
4100.00
28880.00
— Sorted —
Concert
s1
s2
s3
s4
Sales
GWAR
150
200
50
10
8300.00
Chuck_Ragan
50
40
40
18
4340.00
The_Aquabats
70
50
20
20
4100.00
Avail
70
35
20
25
4200.00
NOFX
90
80
80
28
7940.00
Total Sales ... bye ...
28880.00
// C code
// This code will compute the values of the sales
// ticket sales for concerts
// and sort the entries by those values
// Developer: Taylor Clemons
// Date: Jul 29, 2019
#include <stdio.h
#define MAXN 100 // max characters in a group/concert name
#define MAXG 50 // max concerts/groups #define MAXC 4 // max categories
char group [MAXG][MAXN]; int fans [MAXG][MAXC]; float prices [MAXC]; float sales [MAXG]; float total; int count = 0;
void intro () { printf("Welcome to the concert ticket sales calculator.\nTaylor Clemons\nCMIS102\n");
printf("You will enter ticket prices in each of 4 categories to determine the values of sales\n");
}
void computeTotals () {
total = 0;
for (int ts = 0; ts < count; ts++) { total += sales[ts];
}
printf("\n%15s%30.2f\n", "Total Sales", total);
}
void printArray () { printf ("%15s%5s%5s%5s%5s%10s\n",
"Concert", "s1", "s2", "s3", "s4", "Sales");
for (int i = 0; i < count; i++) { printf ("%15s", group [i]); for (int j = 0; j < MAXC; j++) { printf ("%5d", fans[i][j]); } // end for each category printf ("%10.2f\n", sales [i]);
} // end for each group
computeTotals();
} // end function printArray
void computeSales () {
for (int i = 0; i < count; i++) { sales [i] = 0;
for (int j = 0; j < MAXC; j++) {
sales [i] += prices [j] * fans [i][j];
} // end for each category } // end for each group } // end function computeSales
void switchRows (int m, int n) { char tc; int ti; float v;
// printf ("Switching %d with %d\n", m, n);
for (int i = 0; i < MAXN; i++) { tc = group [m][i]; group [m][i] = group [n][i]; group [n][i] = tc;
} // end for each character in a group name
for (int i = 0; i < MAXC; i++) {
ti = fans [m][i]; fans [m][i] = fans [n][i]; fans [n][i] = ti;
} // end for each fan category v = sales [m]; sales [m] = sales [n]; sales [n] = v; } // end switch
int findMinFansCat4 (int m) {
float min = fans [m][3]; int target = m;
for (int i = m+1; i < count; i++)
if (fans [i][3] < min) {
min = fans [i][3]; target = i;
} // end new max found return target;
} // end function findMinSales
void sortByFansCat4 () { int target;
for (int i = 0; i < count; i++) { target = findMinFansCat4 (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++)
1
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) { intro (); getData (); computeSales (); printArray ();
printf ("\n --- Sorted ---\n");
sortByFansCat4(); printArray (); printf("... bye ...\n"); return 0;
}
7. (Test Case 2) Sort Fans Column 4