// C code
// This code will compute the values of the sales ticket sales for concerts
// and sort the entries by those values
// Developer: Gary Tran, Student CMIS102
// Date: 07 Aug 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];
int count = 0;
//Function to display a Welcome Message.
void welcome(){
printf ("Welcome to the ticket Sales Calulator.\n"); printf ("Purpose: This application will help you calculate ticket Sales & help may be a success\n"); printf ("Created By: Martha Hagos for ypur convenience\n"); printf ("Created On: December 15, 2019 \n\n\n\n\n");
}
void printArray () {
printf ("%15s%5s%5s%5s%10s\n", "Concert", "s1", "s2", "s3", "s4" "Sales");
for (int i = 0; i < count; i++) {
for (int j = 0; j < MAXC; 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 = 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 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 categories: ", 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++) {
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
//Calculates the Total for all concerts
void totalSalesCalculator(){
//The Total
float total = 0;
int salesSize = sizeof(sales);
//Loop THrough the sizes
for (int i = 0; i < salesSize; i++){
total += sales[i];
}
printf("\nThe Total Sales is %.2lf \n\n", total
); }//end Total sales Calculation
int main(void) {
welcome ();
getData ();
computeSales ();
printArray ();
printf ("\n --- Sorted ---\n"); sortBySales ();
printArray ();
totalSalesCalculator();
return 0;
}