Please help me fix the errors, I've been try to fix it but it gives me new errors. I can only edit the code in studentMain.cpp, I cannot edit the code in bubble.cpp, bubble.h, and student.h.    //bubble.cpp #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; }   //bubble.h void bubble(student *array[], int size);   //student.h typedef struct student_info{ char *first; char *last; int exam1; int exam2; int exam3; float mean; } student;   //studentMain.cpp #include #include #include "student.h" #include "bubble.h" int main() {   // Create an array of 19 student pointers   student *students[19];   // Allocate space for each student in the array   for (int i = 0; i < 19; i++) {     students[i] = (student *)malloc(sizeof(student));   }   // Read in the data from the file   FILE *fp = fopen("students.txt", "r");   if (fp == NULL) {     printf("Error opening file\n");     return 1;   }   for (int i = 0; i < 19; i++) {     fscanf(fp, "%s %s %d %d %d", students[i]->first, students[i]->last, &students[i]->exam1, &students[i]->exam2, &students[i]->exam3);     // Calculate the student's mean     students[i]->mean = (students[i]->exam1 + students[i]->exam2 + students[i]->exam3) / 3.0;   }   fclose(fp);   // Sort the students using the bubble sort algorithm   bubble(students, 19);   // Find the mean, minimum, maximum, and median of the grades   float mean = 0.0;   float min = students[0]->mean;   float max = students[18]->mean;   float median = students[9]->mean;   for (int i = 0; i < 19; i++) {     mean += students[i]->mean;   }   mean /= 19.0;   // Print the class statistics   printf("CSCE 1040 MEAN %.2f MIN: %.2f MAX: %.2f MEDIAN: %.2f\n", mean, min, max, median);   // Print the student averages   for (int i = 0; i < 19; i++) {     printf("%s %s %f\n", students[i]->first, students[i]->last);     printf("%s %s %f\n", students[i]->first, students[i]->last, students[i]->mean);   }

Database System Concepts
7th Edition
ISBN:9780078022159
Author:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Chapter1: Introduction
Section: Chapter Questions
Problem 1PE
icon
Related questions
Question

Please help me fix the errors, I've been try to fix it but it gives me new errors. I can only edit the code in studentMain.cpp, I cannot edit the code in bubble.cpp, bubble.h, and student.h. 

 

//bubble.cpp

#include <stdlib.h>
#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;
}

 

//bubble.h

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

 

//student.h

typedef struct student_info{
char *first;
char *last;
int exam1;
int exam2;
int exam3;
float mean;
} student;

 

//studentMain.cpp

#include <stdio.h>
#include <stdlib.h>
#include "student.h"
#include "bubble.h"
int main()
{
  // Create an array of 19 student pointers
  student *students[19];
  // Allocate space for each student in the array
  for (int i = 0; i < 19; i++) {
    students[i] = (student *)malloc(sizeof(student));
  }
  // Read in the data from the file
  FILE *fp = fopen("students.txt", "r");
  if (fp == NULL) {
    printf("Error opening file\n");
    return 1;
  }
  for (int i = 0; i < 19; i++) {
    fscanf(fp, "%s %s %d %d %d", students[i]->first, students[i]->last, &students[i]->exam1, &students[i]->exam2, &students[i]->exam3);
    // Calculate the student's mean
    students[i]->mean = (students[i]->exam1 + students[i]->exam2 + students[i]->exam3) / 3.0;
  }
  fclose(fp);
  // Sort the students using the bubble sort algorithm
  bubble(students, 19);
  // Find the mean, minimum, maximum, and median of the grades
  float mean = 0.0;
  float min = students[0]->mean;
  float max = students[18]->mean;
  float median = students[9]->mean;
  for (int i = 0; i < 19; i++) {
    mean += students[i]->mean;
  }
  mean /= 19.0;
  // Print the class statistics
  printf("CSCE 1040 MEAN %.2f MIN: %.2f MAX: %.2f MEDIAN: %.2f\n", mean, min, max, median);
  // Print the student averages
  for (int i = 0; i < 19; i++) {
    printf("%s %s %f\n", students[i]->first, students[i]->last);
    printf("%s %s %f\n", students[i]->first, students[i]->last, students[i]->mean);
  }

  // Free the allocated memory for each student
  for (int i = 0; i < 19; i++) {
    free(students[i]);
  }

  return 0;
}

studentMain.cpp: In function 'int main()':
studentMain.cpp:40:20: warning: format 'f' expects a matching 'double' argument
printf("%s %s f\n", students[i]->first, students[i]->last);
[-Wformat=]
40 |
I
|
|
double
bubble.h:1:13: error: variable or field 'bubble' declared void
1 | void bubble (student *array[], int size);
برای ما برای ار برس دار
bubble.h:1:13: error: 'student' was not declared in this scope
bubble.h:1:22: error: 'array' was not declared in this scope
1 | void bubble (student *array[], int size);
bubble.h:1:28: error: expected primary-expression before ¹]' token
1 | void bubble (student *array[], int size);
bubble.h:1:31: error: expected primary-expression before 'int'
1 | void bubble (student *array[], int size);
I
الای ارسی مالی
Transcribed Image Text:studentMain.cpp: In function 'int main()': studentMain.cpp:40:20: warning: format 'f' expects a matching 'double' argument printf("%s %s f\n", students[i]->first, students[i]->last); [-Wformat=] 40 | I | | double bubble.h:1:13: error: variable or field 'bubble' declared void 1 | void bubble (student *array[], int size); برای ما برای ار برس دار bubble.h:1:13: error: 'student' was not declared in this scope bubble.h:1:22: error: 'array' was not declared in this scope 1 | void bubble (student *array[], int size); bubble.h:1:28: error: expected primary-expression before ¹]' token 1 | void bubble (student *array[], int size); bubble.h:1:31: error: expected primary-expression before 'int' 1 | void bubble (student *array[], int size); I الای ارسی مالی
Expert Solution
Step 1: Introduction

Hello! I understand that diving into code can sometimes be overwhelming, especially when you're faced with error messages that might seem cryptic. However, no worries – we'll work through them step by step. Your code consists of the main student file, a utility for the bubble sort, and two headers that structure the functionalities. Let's systematically identify the issues and rectify them in studentMain.cpp.


steps

Step by step

Solved in 3 steps

Blurred answer
Follow-up Questions
Read through expert solutions to related follow-up questions below.
Follow-up Question

Hi, it is still giving me the same 5 errors as last time even after modifying the code. I tried reordering #include "student.h" and #include "bubble.h" in studentMain.cpp but it gave me more errors. Is this happening because I am compiling with the wrong command, I am compiling it all together like this: g++ studentMain.cpp bubble.cpp bubble.h student.h grades.txt. I have the modified code below and a reminder that I can only edit the code in the studentMain.cpp file: 

 

//studentMain.cpp

#include <stdio.h>
#include <stdlib.h>
#include "student.h"
#include "bubble.h"

int main()
{
  // Create an array of 19 student pointers
  student *students[19];
  // Allocate space for each student in the array
  for (int i = 0; i < 19; i++) {
    students[i] = (student *)malloc(sizeof(student));
  }
  // Read in the data from the file
  FILE *fp = fopen("students.txt", "r");
  if (fp == NULL) {
    printf("Error opening file\n");
    return 1;
  }
  for (int i = 0; i < 19; i++) {
    fscanf(fp, "%s %s %d %d %d", students[i]->first, students[i]->last, &students[i]->exam1, &students[i]->exam2, &students[i]->exam3);
    // Calculate the student's mean
    students[i]->mean = (students[i]->exam1 + students[i]->exam2 + students[i]->exam3) / 3.0;
  }
  fclose(fp);
  // Sort the students using the bubble sort algorithm
  bubble(students, 19);
  // Find the mean, minimum, maximum, and median of the grades
  float mean = 0.0;
  float min = students[0]->mean;
  float max = students[18]->mean;
  float median = students[9]->mean;
  for (int i = 0; i < 19; i++) {
    mean += students[i]->mean;
  }
  mean /= 19.0;
  // Print the class statistics
  printf("CSCE 1040 MEAN %.2f MIN: %.2f MAX: %.2f MEDIAN: %.2f\n", mean, min, max, median);
  // Print the student averages
  for (int i = 0; i < 19; i++) {
    printf("%s %s %f\n", students[i]->first, students[i]->last, students[i]->mean);
  }

  // Free the allocated memory for each student
  for (int i = 0; i < 19; i++) {
    free(students[i]);
  }

  return 0;
}

 

//bubble.cpp

#include <stdlib.h>
#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;
}

 

//bubble.h

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

 

//student.h

typedef struct student_info{
char *first;
char *last;
int exam1;
int exam2;
int exam3;
float mean;
} student;

 

//grades.txt

CSCE1040
Erica     Sanders   75 89 67
Kelley    Cummings  74 70 79
Jamie     Reynolds  64 52 66
Shawna    Huff      80 88 61
Muriel    Holmes    81 74 79
Marion    Harmon    77 64 69
Catherine Moss      51 80 73
Kristin   Fernandez 86 69 81
Elsa      Alvarado  63 77 67
Cora      Spencer   76 79 71
Valerie   Olson     85 78 79
Anne      Singleton 85 87 65
Rene      Boone     85 85 77
James     Morgan    69 86 51
Cedric    Haynes    72 73 88
Elijah    Snyder    65 92 91
Roger     Howard    79 95 71
Archie    Black     70 81 63
Melvin    Watkins   66 67 72

 

bubble.h:1:13: error: variable or field 'bubble' declared void
1 | void bubble (student *array[], int size);
م م م م کی برسی مالی
bubble.h:1:13: error: 'student' was not declared in this scope
bubble.h:1:22: error: 'array' was not declared in this scope
1 | void bubble (student *array[], int size);
عا م کی برسی مالی
bubble.h:1:28: error: expected primary-expression before ¹]' token
1 | void bubble (student *array[], int size);
I
bubble.h:1:31: error: expected primary-expression before 'int'
1 | void bubble (student *array[], int size);
I
Transcribed Image Text:bubble.h:1:13: error: variable or field 'bubble' declared void 1 | void bubble (student *array[], int size); م م م م کی برسی مالی bubble.h:1:13: error: 'student' was not declared in this scope bubble.h:1:22: error: 'array' was not declared in this scope 1 | void bubble (student *array[], int size); عا م کی برسی مالی bubble.h:1:28: error: expected primary-expression before ¹]' token 1 | void bubble (student *array[], int size); I bubble.h:1:31: error: expected primary-expression before 'int' 1 | void bubble (student *array[], int size); I
Solution
Bartleby Expert
SEE SOLUTION
Knowledge Booster
Array
Learn more about
Need a deep-dive on the concept behind this application? Look no further. Learn more about this topic, computer-science and related others by exploring similar questions and additional content below.
Similar questions
Recommended textbooks for you
Database System Concepts
Database System Concepts
Computer Science
ISBN:
9780078022159
Author:
Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:
McGraw-Hill Education
Starting Out with Python (4th Edition)
Starting Out with Python (4th Edition)
Computer Science
ISBN:
9780134444321
Author:
Tony Gaddis
Publisher:
PEARSON
Digital Fundamentals (11th Edition)
Digital Fundamentals (11th Edition)
Computer Science
ISBN:
9780132737968
Author:
Thomas L. Floyd
Publisher:
PEARSON
C How to Program (8th Edition)
C How to Program (8th Edition)
Computer Science
ISBN:
9780133976892
Author:
Paul J. Deitel, Harvey Deitel
Publisher:
PEARSON
Database Systems: Design, Implementation, & Manag…
Database Systems: Design, Implementation, & Manag…
Computer Science
ISBN:
9781337627900
Author:
Carlos Coronel, Steven Morris
Publisher:
Cengage Learning
Programmable Logic Controllers
Programmable Logic Controllers
Computer Science
ISBN:
9780073373843
Author:
Frank D. Petruzella
Publisher:
McGraw-Hill Education