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)
fx
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

#ifndef GRADEBOOK_H
#define GRADEBOOK_H

#include<iostream>
using namespace std;

#include<string>
using std::string;

#include<vector>
using std::vector;

class GradeBook
{
public:

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

private:
	string coursename;
	vector<int>score;
	void accessvector();

};

#endif


#include <iostream>
using namespace std;

#include<iomanip>
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()
{
	displaycoursename(score);
}
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;

#include<vector>
using std::vector;

#include "GradeBook.h"

void collectdata(vector<int> &);

void main()
{
	vector<int>grade;
	collectdata(grade);
	GradeBook mean( "a program that finds the mean median and mode of data", grade );
	mean.run();

}

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

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.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.