Question: The code i am not allowed to change void bubble(student *array[], int size); typedef struct student_info { char *first; char *last; int exam1; int exam2;

The code i am not allowed to change

void bubble(student *array[], int size);

typedef struct student_info {

char *first;

char *last;

int exam1;

int exam2;

int exam3;

float mean;

}student;

#include

#include "student.h"

void bubble(student *array[], int size)

{

int x;

int y;

student *temp = NULL;

for (x = 0; x < size; x++) {

for (y = 0; y < size - 1; y++) {

if (array[y]->mean > array[y + 1]->mean) {

temp = array[y + 1];

array[y + 1] = array[y];

array[y] = temp;

}

}

}

return;

}

My code i have written:

i am am getting an error about bubble in main. saying that it has been declared void how else I pass the the array of pointers to bubble?

#include

#include

#include "bubble.h"

#include "student.h"

struct classStats {

float mean;

float min;

float max;

float median;

char* name;

};

int main() {

FILE *fptr;

int i;

float sum = 0;

fptr = fopen("grades", "r");

student stuff;

student *stuff[19];

struct classStats stat;

if (fptr == NULL) {

printf("Error opening file ");

return 0;

}

for (i = 0; i<19; i++) {

stuff[i]->first = (char *)malloc(sizeof(char) * 20);

stuff[i]->last = (char *)malloc(sizeof(char) * 20);

fscanf(fptr, "%s%s%d%d%d", stuff[i]->first, stuff[i]->last, &stuff[i]->exam1, &stuff[i]->exam2, &stuff[i]->exam3);

stuff[i]->mean = (stuff[i]->exam1 + stuff[i]->exam2 + stuff[i]->exam3) / 3;

sum = sum + stuff[i]->mean;

}

fclose(fptr);

void bubble(student *array[19], int size);

stat.name = (char *)malloc(sizeof(char) * 20);

stat.name = (char *)malloc(sizeof(char) * 20);

fscanf(fptr, "%s", stat.name);

stat.max = stuff[18]->mean;

stat.min = stuff[0]->mean;

stat.mean = sum / 19;

stat.median = stuff[19 / 2]->mean;

printf("%s MEAN:%.2f MIN:%.2f MAX:%.2f MEDIAN:%.2f ", stat.name, stat.mean, stat.min, stat.max, stat.median);

for (i = 0; i<19; i++) {

printf("%s %s %.2f ", stuff[i]->first, stuff[i]->last, stuff[i]->mean);

}

return 0;

}

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!