View the step-by-step solution to:

# #include < stdio.

#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];

int count = 0;

void printArray () {

printf ("%15s%5s%5s%5s%10sn",

"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.2fn", 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 %dn", 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 computeTotalSalesForConcerts () {

int salesTot=0;

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

salesTot=salesTot+sales[i];

} // end for each group

printf("Total sales for all the concerts: %d",salesTot);

} // end function computeSales

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 categoriesn", MAXC);

printf (" . to finish entries:n");

for (int i = 0; i < MAXG; i++) {

scanf ("%s", &group[i]);

if (group [i] == '.')

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 ();

computeTotalSalesForConcerts();

printf("... bye ...n");

return 0;

}

____________________________________________________

I am trying to create a variety of test cases focusing on the sorting algorithm, such as the final element is the smallest, the entire set is already sorted, etc. Explain the purpose of each test case, and check your code against each of those cases.

Try using different inputs: a. What changes would you suggest to handle larger, more realistic numbers? b. What happens if any of the numbers, such as the ticket prices, are negative? c. What are your recommendations concerning negative input values?

What changes should be made to the code if the customer wished to sort on the number of fans in category 1, the first of the three (or four) categories? Make those changes, test your code and confirm that it is working correctly.

### Why Join Course Hero?

Course Hero has all the homework and study help you need to succeed! We’ve got course-specific notes, study guides, and practice tests along with expert tutors.

### -

Educational Resources
• ### -

Study Documents

Find the best study resources around, tagged to your specific courses. Share your own to gain free Course Hero access.

Browse Documents
• ### -

Question & Answers

Get one-on-one homework help from our expert tutors—available online 24/7. Ask your own questions or browse existing Q&A threads. Satisfaction guaranteed!

Ask a Question