2022-08-12 14:59:08 +01:00
|
|
|
#include <iostream>
|
2022-10-14 12:34:58 +01:00
|
|
|
#include <vector>
|
|
|
|
#include <iomanip>
|
2022-10-21 12:46:45 +01:00
|
|
|
#include "stats.h"
|
2022-10-14 12:34:58 +01:00
|
|
|
|
|
|
|
using string = std::string;
|
|
|
|
|
|
|
|
//Placw in header!
|
|
|
|
template <typename T>
|
2022-10-21 12:46:45 +01:00
|
|
|
void printm(T m)
|
|
|
|
{
|
|
|
|
std::cout << m;
|
2022-10-14 12:34:58 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
template <typename T>
|
2022-10-21 12:46:45 +01:00
|
|
|
void printlm(T m)
|
|
|
|
{
|
|
|
|
printm(m);
|
|
|
|
printm("\n");
|
2022-10-14 12:34:58 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
typedef std::vector<double>::size_type vtype;
|
|
|
|
|
|
|
|
double promptd(string,bool*);
|
|
|
|
|
2022-10-21 12:46:45 +01:00
|
|
|
int main()
|
|
|
|
{
|
|
|
|
std::setprecision(3);
|
|
|
|
printlm("Calculate the average and median of scores:");
|
|
|
|
bool s {};
|
|
|
|
std::vector<double> v {};
|
|
|
|
do
|
|
|
|
{
|
|
|
|
auto d = promptd("Enter a score (Enter a non number to finish entry) : ",&s);
|
|
|
|
if (s) v.push_back(d);
|
|
|
|
}
|
|
|
|
while(s);
|
|
|
|
printm("Score median is: ");
|
|
|
|
printlm(med(v, false));
|
|
|
|
printm("Score median (No Extremes) is: ");
|
|
|
|
printlm(med(v, true));
|
|
|
|
printm("Score average is: ");
|
|
|
|
printlm(avg(v, false));
|
|
|
|
printm("Score average (No Extremes) is: ");
|
|
|
|
printlm(avg(v, true));
|
|
|
|
return 0;
|
2022-10-14 12:34:58 +01:00
|
|
|
}
|
|
|
|
|
2022-10-21 12:46:45 +01:00
|
|
|
double promptd(string message, bool *status)
|
|
|
|
{
|
|
|
|
double tr {0.0};
|
|
|
|
*status = false;
|
|
|
|
std::cout << message;
|
|
|
|
if (!(std::cin >> tr))
|
|
|
|
{
|
|
|
|
std::cin.clear();
|
|
|
|
std::cin.ignore();
|
|
|
|
return 0.0;
|
|
|
|
}
|
|
|
|
*status = true;
|
|
|
|
return tr;
|
2022-08-26 15:09:27 +01:00
|
|
|
}
|
2022-10-14 12:34:58 +01:00
|
|
|
|