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]
3 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]3 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
A type of bridge that relies on a curved, semi-circular structure for support
inna [77]
Arch bridges have a semicirclar, curved support.
8 0
3 years ago
A good way to assess your CPU usage is to:_______.
inna [77]
C is likely the best answer here.
8 0
3 years ago
Which is the most likely reason why scientists change a model?
frozen [14]

C.) New discoveries make the current model inaccurate. Since science is all about observation and experimentation, it is logical that whenever new findings are gathered, scientific models must be modified to adapt to the information. As new ideas and concepts are uncovered, models should be updated to make them correct.

5 0
3 years ago
Read 2 more answers
how much should an organization consider moving into the cloud before full outsourcing starts making more business sense
PIT_PIT [208]

Answer:

47

Explanation:

capital steez

8 0
3 years ago
Read 2 more answers
A mobile device user has entered her user ID and password to access an online account. The user immediately receives a text mess
tensa zangetsu [6.8K]

Answer:

A. Multifactor authentication

Explanation:

Multifactor authentication is a security system process that requires a user to verify his or her identity by providing two categories of credentials.

A mobile device user has entered her user ID and password to access an online account, she immediately receives a text message with a unique PIN or One Time Password (OTP) that must be entered before she is granted access to the account. This is an example of a multifactor authentication security method.

8 0
3 years ago
Other questions:
  • Why is driving a privilege?
    15·2 answers
  • WILL GIVE BRAINLIEST TO FIRST AND BEST ANSWER!
    10·1 answer
  • What can you use with your keywords to narrow your search if you complete an internet search using a search engine and do not ge
    15·2 answers
  • The ____________ mechanism consists of a lever arm attached to the mousetrap spring.
    15·1 answer
  • What are options in the Advanced tab in the Share Workbook dialog box? Check all that apply.
    14·2 answers
  • What two pieces of information would you need in order to measure the masses of stars in an eclipsing binary system?
    9·1 answer
  • Which camera mode gives the photographer the greatest amount of control?
    7·2 answers
  • Hello 10 points if my Chromebook is on 26 percent how much time do I have left theoretically
    8·2 answers
  • Ania has written this SimpleStopwatch class. In which line is she measuring the elapsed time?
    13·1 answer
  • 3.5 code practice question 1
    5·2 answers
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!