Best writers. Best papers. Let professionals take care of your academic papers

Order a similar paper and get 15% discount on your first order with us
Use the following coupon "FIRST15"
ORDER NOW

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. // C code // This code will compute the values of the sales ticket sales for concerts // and sort the entries by those values // Developer: Faculty CMIS102 // Date: Jan 31, XXXX   #include   #define MAXN 100 // max characters in a group/concert name #define MAXG 50 // max concerts/groups   // ********* macro MAXC modified from 3 to 4 ************** #define MAXC 4 // max categories // ********************************************************  

What changes should be made to the code if the customer wished to

  1. 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.

    // C code
    // This code will compute the values of the sales ticket sales for concerts
    // and sort the entries by those values
    // Developer: Faculty CMIS102
    // Date: Jan 31, XXXX

    #include <stdio.h>

    #define MAXN 100 // max characters in a group/concert name
    #define MAXG 50 // max concerts/groups

    // ********* macro MAXC modified from 3 to 4 **************
    #define MAXC 4 // max categories
    // ********************************************************
    9
    char group [MAXG][MAXN];
    int fans [MAXG][MAXC];
    float prices [MAXC];
    float sales [MAXG];
    float total_sales = 0;
    int count = 0;

    void printArray () {

    // ******** added %5s space and corresponding s4 to the the display table column names ***********
    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
    } // 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

    // **************FUNCTION ADDED ******************
    void computeTotalSales () {
    for (int i = 0; i < count; i++) {
    total_sales+=sales[i];
    }//end for each group

    }
    // *************8*******************************

    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) {
    getData ();
    computeSales ();
    printArray ();
    printf (“\n — Sorted —\n”);
    sortBySales ();
    printArray ();

    //********* calling function to compute total sales ,
    // **********then display the total sales *******************
    computeTotalSales ();
    printf(“Total sales: %10.2f\n”,total_sales);
    // *************************************************************

    printf(“… bye …\n”);
    return 0;
    }

 
Looking for a Similar Assignment? Order now and Get 10% Discount! Use Coupon Code "Newclient"