good day everyone there's something i've been trying to do in c++
its a program that finds the mean median and mode from a group
set of data, it should use vectors to read these data from the user
and then tabulate into:
grade distribution
class mark(x)
i've tried to the best of my knowledge, but here's what i could
get in the moment. please i'll be most greatful to anyone who'll help


using namespace std;

using std::string;

using std::vector;

class GradeBook

	GradeBook(string, vector<int> & );
	string getCourseName();
	void run();
	void displaycoursename(vector<int> &);
	void processgrade();
	int getmaximum();
	int getminimum();

	string coursename;
	void accessvector();



#include <iostream>
using namespace std;

using std::setw;

#include <vector>
using std::vector;

#include "GradeBook.h"

GradeBook::GradeBook(string name, vector<int> & result)
	coursename = name;
	score = result;
string GradeBook::getCourseName()
	return coursename;
void GradeBook::run()
void GradeBook::displaycoursename(vector<int> & osagie)
	cout << "\nyou have entered:" << endl;

	for(size_t i=0; i<osagie.size(); i++)
		cout <<"\n" <<osagie[i];

    cout << "\n       " << "SOLUTION\n" << endl;
	cout << "mark(x)" << "    " <<"frequency(f)"<<"    "<<"fx\n\n";

	for(size_t i=0; i<osagie.size(); i++)
		cout << setw(3) << osagie[i] << "\n";
	    cout << endl;

#include <iostream>
using namespace std;

using std::vector;

#include "GradeBook.h"

void collectdata(vector<int> &);

void main()
	GradeBook mean( "a program that finds the mean median and mode of data", grade );;


void collectdata(vector<int> & mark)
	int values;
	cout << "Enter statistical values to analyse\n"
	     << "when through press ctrl+Z\n\n\n";

which part do you need the help with?

Mean = average = Sum of Total elements / Number of elements

Median is the middle number in a sorted set of numbers

Mode is the most occurring number.

To find the Mean you can sum up the total and divide by the vector size
To find the median you need to sort the vector. Then check if the vector size is even, if so then you could do the following :

int Indx = vec.size() / 2;
float median = ( vec[Indx] + vec[Indx+1] ) / 2;

if you vec size is odd then you can simply do this :

float median  = vec[ vec.size()/2 ];

You can count up the frequency of each number if the array after you
are done.

This article has been dead for over six months. Start a new discussion instead.