Hi, I cannot fix the 5 errors after trying to fix the code. Even after fixing the code it is giving me more errors which I don't understand how to fix. 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 I can only edit the code in the studentMain.cpp file I cannot edit the code in the files bubble.cpp, bubble.h, and student.h:
//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
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
The correct way to compile your C++ files is by omitting the header files and any other non-source files like grades.txt in the g++ command. Just include the .cpp files. The header files will be automatically included by the preprocessor as specified in the #include directives.
Compile using:
g++ studentMain.cpp bubble.cpp -o output
Step by stepSolved in 6 steps with 1 images
- It's easy to get mixed up between latitude and longitude! Happily, at least sometimes, this is an easy fix to correct. Complete a method named fixLocation. fixLocation takes a Location object as its only parameter. Some of those location objects have their latitude and longitude swapped. If that's the case, correct them! Otherwise, leave them unaltered. You may be wondering: how will I know which locations are incorrect? The hint is that these are all locations from around the University of Illinois. That should help you determine when the latitude and longitude have been swapped. The Location object has Double latitude and longitude properties that you can access and modify in the usual way in Kotlin.arrow_forwardAs the first step in writing an application for the local book store, we will design and implement a Book class that will define the data structure of the application. Each book has a name, author, type (paperback, hardback, magazine), integer ID and pageCount. Provide some data validation in the appropriate method to ensure that the ID and pageCount are not negative. Design and implement a Book class with separation, i.e., separate all functions and methods into both the prototype and an implementation below the main. Provide constructor methods for Book(void), Book(name, author), and one for all components Book(name, author, type, ID, pageCount) Provide accessor (get and set) methods for each property as well as a display method. Provide data validation for the ID and pageCount in the appropriate methods. Provide a method to calculate the cost for buying books (with a 7.75% sales tax) according to the following chart: Hardcover: $29.95 per book Paperback:…arrow_forwardI have posted this multiple times and people keep giving me answers that don't correspond to the question or is unloadable. So please read this carefully. Answer the operand given below on the bottom left and the fill in its value that is on the bottom right. Please make it loadable before sending as previous tutors sent a black page and please answer what is being asked in the question !! Again bottom left is the operand and please fill in its value which is on the bottom right..arrow_forward
- 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…arrow_forwardThank you very much for explaining the absyract concept, it was very helpful and easier to understanc after you explained it. Today we are asked to modify the GridWriter class by adding additional collection style functionality, to throw an exception in case of an error. The GridWriter class should get two new methods: public int size() should return the number of GridItems stored in the GridWriter public GridItem get(int index) should return the stored GridItems by index. Consider the following code. The first line creates a GridWriter object. Then two items are added to the GridWriter. The index of the items will be 0, and 1. Notice how the for loop uses the size and get methods to print out the areas of the two items GridWriter gw = new GridWriter(40, 50); gw.add(new MyCircle(10, 10, 9)); gw.add(new MyRectangle(40, 0, 10, 10)); for (int i = 0; i < gw.size(); i++) { System.out.println(gw.get(i).getArea()); } Once you have these two methods working you…arrow_forwardTests: In the test_sun.py module, create tests for the planet objects. You can (and should) do this before you have written any Planet code at all. Implementation: In the sun.py module (see template), implement a Sun class as described in Section 10.4. Your Sun class should include the following methods: __init__, get_mass, get_radius, get_temperature, and __str__. Your __str__ method should include the following information for each planet: Name, distance from sun, radius, and mass. section 10.4arrow_forward
- It will use a class called NameHelper (which you will write). This class will provide methods to load the data files and to fetch name rankings by year. The JavaFX class will be using NameHelper according to the following UML, so make sure your data helper has the methods defined below: What does the (~) mean in the attached diagram.arrow_forwardFollow all code styling and submission instructions as outlined for previous labs. Derive a MinHeap class from the BST class of your Lab 4 code. Define/Override only the Search/Insert/Delete methods in the new class. Write a new main for this lab which: Will only be a test program for the MinHeap. Declares and creates a MinHeap object as necessary. Declares and creates the Dollar objects as necessary. Inserts the 20 Dollar objects specified in Lab 4 in the same order. Performs all 4 traversals after the inserting the 10th and the last objects - in total there will be 8 outputs which should be clearly demarcated. No user input is necessary, no data validation is necessary. For submission - upload all class files from Lab 4 as necessary as well as your new MinHeap class and the main. Remember to also include adequate number of screenshots of the program execution. The Discussion forum will be monitored and responded to all week during the Finals. Office Hours will only be held on…arrow_forward
- Database System ConceptsComputer ScienceISBN:9780078022159Author:Abraham Silberschatz Professor, Henry F. Korth, S. SudarshanPublisher:McGraw-Hill EducationStarting Out with Python (4th Edition)Computer ScienceISBN:9780134444321Author:Tony GaddisPublisher:PEARSONDigital Fundamentals (11th Edition)Computer ScienceISBN:9780132737968Author:Thomas L. FloydPublisher:PEARSON
- C How to Program (8th Edition)Computer ScienceISBN:9780133976892Author:Paul J. Deitel, Harvey DeitelPublisher:PEARSONDatabase Systems: Design, Implementation, & Manag...Computer ScienceISBN:9781337627900Author:Carlos Coronel, Steven MorrisPublisher:Cengage LearningProgrammable Logic ControllersComputer ScienceISBN:9780073373843Author:Frank D. PetruzellaPublisher:McGraw-Hill Education