Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Hello, I started this program and I am having it bug out on me, I am not sure what is wrong. Any help ASAP would

Hello, I started this program and I am having it bug out on me, I am not sure what is wrong. Any help ASAP would be greatly appreciated.

the problem:

Homework 08B

COMSC-44

Find the Median

You are given a file with a list of grades. You are asked to find the Median grade for

the class.

Definition of Median

If an array of numbers is sorted in ascending order, then the median number would be

the number in the middle. For example, given the numbers: {92, 13, 54, 72, 87}, the

median number would be 72. This is easier to see if you arrange the numbers in

ascending order:

{13, 54,

72

, 87, 92} . As you can see, when arranged in order, the number 72 is clearly

in the middle. If the number of numbers is even (not odd as shown above), then the

average of the two numbers in the middle defines the Median. For example, suppose

we had six numbers, instead of 5. Arranging them in order we might see: {13, 54, 72,

74, 87, 92}. In this case, both 72 and 74 are in the middle. The average of these two

number is 73. Therefore, the Median of these 6 numbers is 73.

You will be given two files, GradeListO.txt and GradeListE.txt. Write a program that will

determine the median grade in GradeList for either of these two cases (one has an

Odd number of grades and the other has an Even number of grades). Your program

should allow the user to choose which of the two files should be selected for this

computation. You may use either a Bubble Sort or a Selection Sort in implementing

this program. Likewise, you may use either arrays or vectors to in doing this

computation. Be sure to identify whose Median Calculator this is (i.e. your name in the

title). Call your program:

YourName

-Hwrk8B.cpp

What Ive gotten so far:

#include #include #include using namespace std;

int main() { const int NUM_GRADES = 50; int grades[NUM_GRADES]; string filename; int temp; int index; int median;

int count = 0; ifstream inputFile;

cout << "Please enter the name of the grading file you wish to use: "; cin >> filename;

inputFile.open(filename);

if(inputFile) { while (count < NUM_GRADES && inputFile >> grades[count]) { count++; } index = count

inputFile.close();

//for (int index = 0; index < count; index++) //cout << grades[index] << endl;

for (int i = 0; i < index; i++) { for(int j = 0; j < index-i-1; j++) { if (grades[j] < grades[j + 1]) { temp = grades[j]; grades[j] = grades[j+1]; grades[j+1] = temp; } if(index%2 == 0) { median = (grades[i/2] + grades[i/2-1])/2.0; } else { median = grades[i/2]; } } }

cout << "The median is " << median << endl; } else { cout << "File name wrong, please try again." << endl; }

return 0; }

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

Spatio Temporal Database Management International Workshop Stdbm 99 Edinburgh Scotland September 10 11 1999 Proceedings Lncs 1678

Authors: Michael H. Bohlen ,Christian S. Jensen ,Michel O. Scholl

1999th Edition

3540664017, 978-3540664017

Students also viewed these Databases questions