1answer.
Ask question
Login Signup
Ask question
All categories
  • English
  • Mathematics
  • Social Studies
  • Business
  • History
  • Health
  • Geography
  • Biology
  • Physics
  • Chemistry
  • Computers and Technology
  • Arts
  • World Languages
  • Spanish
  • French
  • German
  • Advanced Placement (AP)
  • SAT
  • Medicine
  • Law
  • Engineering
Whitepunk [10]
4 years ago
8

5. Create a variety of test cases focusing on the sorting algorithm, such as the final element is the smallest, the entire set i

s already sorted, etc. Explain the purpose of each test case, and check your code against each of those cases
Computers and Technology
1 answer:
andrew11 [14]4 years ago
7 0

Answer:

// C code

// This code will compute the values of the sales ticket sales for concerts

#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

// ***** totalSales ****

void totalSales()

{

float tsales;

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

tsales += sales [i];

}

printf("\n\t\tThe total sales are: $%.2f\n",tsales);

}

// ***********************************

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

//**********sort by fans*************

int minFans (int b) {

float min = fans [b][0];

int target = b;

for (int i = b; i < count; i++)

if (fans [i][0] < min) {

min = fans [i][0];

target = i;

} // end new max found

return target;

}

void sortByFans () {

int target = 0;

//int result;

 

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

target = minFans(i);

if (target > i)

//result = target;    

switchRows (i,target);

 

}

}

//********************************

void getData () {

// for (int i = 0; i < MAXG; i++) sales [i] = 0;

printf ("\nEnter 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 sales ---\n");

sortBySales ();

printArray ();

totalSales ();

printf("--- sorted by fans ---\n");

sortByFans ();

printArray ();

totalSales ();

printf("\t\t ... Bye ...\n");

return 0;

}

You might be interested in
Which letter is located at position (7,4) on this coordinate grid? A) B) C) D)
aleksklad [387]

It is letter d

gdstcccccccvdagjsbhbj cna cas

8 0
3 years ago
Consider the following code:
pishuonlain [190]

In python the % operator is modulo. Modulo returns the remainder of two numbers.

19 % 5 = 4 therefore,

print(x%y) would output 4

7 0
3 years ago
Calculate the cash used to retire debt for each of the six months. Since the company can't pay down more debt than there is cash
BabaBlast [244]

Answer:

The required cash used to retire a debt can be computed as follows:

Cash used to retire debt = cash available to retire a debt, if the cash available to retire debt is less than the loan balance from previous month. Otherwise, cash used to retire debt is equal to the loan balance from previous month.

The excel formula to perform this task is provided as follows:

D33 = IF(D32<C34,D32,C34)

The same formula is used to get the values for E33 to I33.

Explanation:

See the attached picture for table.

5 0
3 years ago
i emailed someone and im sure that they emailed back however it says nothing has arrived in my inbox what do I do
Lynna [10]

Answer:

report it or check ur spam mail or refresh the page

Explanation:

good luck figuring it out :)

8 0
3 years ago
If you want to use your computer for recording your band, you would benefit most from a(n)
notka56 [123]
A. MIDI interface.
RAID is a set of strategies for using more than one drive in a system.
3 0
3 years ago
Read 2 more answers
Other questions:
  • Function templates ___________.
    5·1 answer
  • if your instructors teaching style is very different from your learning preference your best choice is to one work on your weake
    10·1 answer
  • Write the equivalent c++ expression for the following algebraic expressions
    11·1 answer
  • Using truth table, prove that:<br><br> (A + B). C = (A . C)+ (B .C) ?
    7·1 answer
  • Do You assign the Needs Met rating before assigning the page quality (PQ) rating?
    11·1 answer
  • How do you use VMware Fusion to make a Tip Calculator?
    10·1 answer
  • This is my paragraph . The type of color is ude in this code line is ..............................
    5·1 answer
  • in windows 10, what feature is used to locate and launch software or applications installed on your device?
    8·1 answer
  • A.1111+1011. b. 10111+11111 c. 1111*1011 d. 1110*1101 perform the binary calculations.​
    12·1 answer
  • You recently created a new network segment for the development department. Because the hosts are now on a different network segm
    6·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!