Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Don't change anything in bubble.h, bubble.cpp, or student.h, only code in main.cpp file. I wrote the code in main.cpp, but I don't know why it's

Don't change anything in bubble.h, bubble.cpp, or student.h, only code in main.cpp file. I wrote the code in main.cpp, but I don't know why it's not printing anything after the second for loop. Not sure the storing, the allocating or the sorting is wrong, please help. c++

image text in transcribed

image text in transcribed

main.cpp

#include #include #include #include "student.h" #include "bubble.h" #include #include #include using namespace std;

struct classStats //grade stats structure { float max; float mean; float min; float median; char* name; };

int main() { ifstream file; // declare stream file.open("grades"); // open file float sum=0; struct classStats numbers; //stats for the class

student *stu[19]; //array of pointers

//allocating memory for(int i=0;i

//check for error if (file.fail()) { coutfirst=(char*)malloc(sizeof(char)*20); //allocating memory stu[i]->last=(char*)malloc(sizeof(char)*20); // allocating memory //storing students info scanf("%s", stu[i]->first); scanf("%s", stu[i]->last); scanf("%d", &(stu[i]->exam1)); scanf("%d", &(stu[i]->exam2)); scanf("%d", &(stu[i]->exam3)); //calculate the mean stu[i]->mean = (stu[i]->exam1 +stu[i]->exam2 +stu[i]->exam3) /3.0; sum= sum+stu[i]->mean; //the sum } file.close(); //closing file //sorting by bubble bubble(stu,19); //class stats stored struct numbers.max = stu[18]->mean; numbers.min = stu[0]->mean; numbers.mean = sum/19; //class average numbers.median = stu[19/2]->mean; //print class stats printf("%s MEAN: %.2f MIN: %.2f MAX: %.2f MEDIAN: %.2f ", numbers.name, numbers.mean, numbers.min, numbers.max, numbers.median);

//print student data for(int i=0;ifirst last mean; } printf("hi");

return 0; }

student.h

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

bubble.h

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

bubble.cpp

#include #include "student.h"

void bubble(student *array[], int size) { int x; int y; student *temp = NULL;

for(x = 0; x mean > array[y+1]->mean) { temp = array[y+1]; array[y+1] = array[y]; array[y] = temp; } } }

return; }

CSCE 1040 Homework 1 Assignment You are to write a program that processes grade data using structures. Use scanf to input data and printf to output the results. You may also use C++style I/O if you prefer You are to work individually Include your name in the code comments. Failure to include your name may lead to a grade of zero. Name your file Hwkl.cpp.Failure to name the file correctly may lead to a grade of zero. Submit your program to the Canvas page for the Homework I The input data will be a data file that you redirect into your program. The data file can be found at -dmk0080 public/1040 hwk/one/versionA/grades on the CSE server The assignment must be submitted by the due date listed in Canvas. There are files to get you started on this assignment located in grades - the data file student.h- structure to hold the student information bubble.h- bubble sort function prototype bubble.cpp bubble sort that sorts an array of student pointers hwkl.cpp-a main program to get you started Your program is to use two data structures to read in student grade data, perform some calculations, sort the students in ascending order by average, determine some class statistics, and output the results. The first data structure is classStats and should have variables mean (loat), min (float), max (float), median (float), and name (character pointer). You will need to create this structure yourself, placing it above main) in hwkl.cpp and create one variable of type classstats (not a pointer) in your main program The second data structure is called student and will have variables tirst (character pointer), last (character pointer), examl (integer), exam2 (integer), exam3 (integer), and mean (float) This structure is in the file student.h. Take a moment to study this structure to understand it before using it. You will need to create an array of 19 student pointers and will need to allocate space for each in your main program using malloc ) The data file contains the name of the course followed by 19 students, each student having three exam grades. Use the array of student pointers to store the information as read in using scanf. An example data file is below CSCE1040 Erica Kelley Cummings 74 70 79 Jamieeyolds 64 52 66 Shawna Hufi Muriel Marion Harmon Catherine Moss Kristin Fernandez 86 69 81 Sander 75 89 67 0 88 61 81 74 79 77 64 69 51 B0 73 Holmes Cora Valerie Olson Anne Rene James Cedric Haynes Elijah Snyder 65 92 91 Roger Archie Alvarado 63 77 67 Spencer 76 79 71 85 78 79 singleton 85 87 65 5 85 77 69 86 51 72 73 88 Boone Morgan Howard Black 79 95 71 0 81 63 Me lvin Watkins 66 67 72 Page 1 of 2 (A) Use the three grades to determine the student's mean and store it with the name and exam grades in the student structure Assumed each exam is weighted the same. Once all the students are read in and the averages determined, sort the students using the bubble sort code in bubble.c, which takes an array of student pointers and the array size as arguments. Take a moment to study bubble.c to understand how it works before using it. After sorting the students based on mean, find the mean, minimum, maximum, and median of the grades and store them in the classStats structure. Use printf to output the data. Your output should appear as below (include the line of digits), which displays the class statistics and the student averages. Do not worry about rounding. If some students are out of order because they have the same mean, do not wory about it as long as you used the bubble sort 12345678901234567890123456789012345678901234567890123456789 CSCE1040 MEAN: 74.91 MIN: 60.66 MAX: 82.66 MEDIAN: 76.33 JamieReynolds 60.66 Moss 68.00 Watkins 68.33 Morgan 68.66 Alvarado 69.00 Harmon 70.00 1a k 71.33 Kelley Cummings 74.33 pencer 75.33 Huff 76.33 Sanders 77.00 Haynes 77.66 Holmes 78.00 Kristin Fernandez 7B.66 Anne Singleton 79.00 Olson 80.66 Howard 1.66 Boone 82.33 Snyder 82.66 Catherine Melvin James Marion Archie Cora Erica Cedric Nuriel Valerie Roger Elijah Hint 1: Break the programming into smaller phases. Read in the data and output it to make sure it works. Then add code to calculate the student averages. Next, add code to sort the students using the bubble sort. After that, add code to determine the class statistics. Finally, output the results Hint 2: To compile your code, you can use g++epp to compile all epp files in your directory at one time. NOTE: You are not allowed to modify the bubble sort code, nor should you include any of the bubble files in your upload We will compile with our own copies of these files. Please zip you files into a HW1 zip file and upoad this to Canvas for the graders convenience Page 2 of 2 (A) CSCE 1040 Homework 1 Assignment You are to write a program that processes grade data using structures. Use scanf to input data and printf to output the results. You may also use C++style I/O if you prefer You are to work individually Include your name in the code comments. Failure to include your name may lead to a grade of zero. Name your file Hwkl.cpp.Failure to name the file correctly may lead to a grade of zero. Submit your program to the Canvas page for the Homework I The input data will be a data file that you redirect into your program. The data file can be found at -dmk0080 public/1040 hwk/one/versionA/grades on the CSE server The assignment must be submitted by the due date listed in Canvas. There are files to get you started on this assignment located in grades - the data file student.h- structure to hold the student information bubble.h- bubble sort function prototype bubble.cpp bubble sort that sorts an array of student pointers hwkl.cpp-a main program to get you started Your program is to use two data structures to read in student grade data, perform some calculations, sort the students in ascending order by average, determine some class statistics, and output the results. The first data structure is classStats and should have variables mean (loat), min (float), max (float), median (float), and name (character pointer). You will need to create this structure yourself, placing it above main) in hwkl.cpp and create one variable of type classstats (not a pointer) in your main program The second data structure is called student and will have variables tirst (character pointer), last (character pointer), examl (integer), exam2 (integer), exam3 (integer), and mean (float) This structure is in the file student.h. Take a moment to study this structure to understand it before using it. You will need to create an array of 19 student pointers and will need to allocate space for each in your main program using malloc ) The data file contains the name of the course followed by 19 students, each student having three exam grades. Use the array of student pointers to store the information as read in using scanf. An example data file is below CSCE1040 Erica Kelley Cummings 74 70 79 Jamieeyolds 64 52 66 Shawna Hufi Muriel Marion Harmon Catherine Moss Kristin Fernandez 86 69 81 Sander 75 89 67 0 88 61 81 74 79 77 64 69 51 B0 73 Holmes Cora Valerie Olson Anne Rene James Cedric Haynes Elijah Snyder 65 92 91 Roger Archie Alvarado 63 77 67 Spencer 76 79 71 85 78 79 singleton 85 87 65 5 85 77 69 86 51 72 73 88 Boone Morgan Howard Black 79 95 71 0 81 63 Me lvin Watkins 66 67 72 Page 1 of 2 (A) Use the three grades to determine the student's mean and store it with the name and exam grades in the student structure Assumed each exam is weighted the same. Once all the students are read in and the averages determined, sort the students using the bubble sort code in bubble.c, which takes an array of student pointers and the array size as arguments. Take a moment to study bubble.c to understand how it works before using it. After sorting the students based on mean, find the mean, minimum, maximum, and median of the grades and store them in the classStats structure. Use printf to output the data. Your output should appear as below (include the line of digits), which displays the class statistics and the student averages. Do not worry about rounding. If some students are out of order because they have the same mean, do not wory about it as long as you used the bubble sort 12345678901234567890123456789012345678901234567890123456789 CSCE1040 MEAN: 74.91 MIN: 60.66 MAX: 82.66 MEDIAN: 76.33 JamieReynolds 60.66 Moss 68.00 Watkins 68.33 Morgan 68.66 Alvarado 69.00 Harmon 70.00 1a k 71.33 Kelley Cummings 74.33 pencer 75.33 Huff 76.33 Sanders 77.00 Haynes 77.66 Holmes 78.00 Kristin Fernandez 7B.66 Anne Singleton 79.00 Olson 80.66 Howard 1.66 Boone 82.33 Snyder 82.66 Catherine Melvin James Marion Archie Cora Erica Cedric Nuriel Valerie Roger Elijah Hint 1: Break the programming into smaller phases. Read in the data and output it to make sure it works. Then add code to calculate the student averages. Next, add code to sort the students using the bubble sort. After that, add code to determine the class statistics. Finally, output the results Hint 2: To compile your code, you can use g++epp to compile all epp files in your directory at one time. NOTE: You are not allowed to modify the bubble sort code, nor should you include any of the bubble files in your upload We will compile with our own copies of these files. Please zip you files into a HW1 zip file and upoad this to Canvas for the graders convenience Page 2 of 2 (A)

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Beginning Apache Cassandra Development

Authors: Vivek Mishra

1st Edition

1484201426, 9781484201428

More Books

Students also viewed these Databases questions

Question

List one of the facultys publications in APA style.

Answered: 1 week ago