64 lines
1.2 KiB
C++
64 lines
1.2 KiB
C++
#include <iostream>
|
|
#include <vector>
|
|
#include <iomanip>
|
|
#include "stats.h"
|
|
|
|
using string = std::string;
|
|
|
|
//Placw in header!
|
|
template <typename T>
|
|
void printm(T m)
|
|
{
|
|
std::cout << m;
|
|
}
|
|
|
|
template <typename T>
|
|
void printlm(T m)
|
|
{
|
|
printm(m);
|
|
printm("\n");
|
|
}
|
|
|
|
typedef std::vector<double>::size_type vtype;
|
|
|
|
double promptd(string,bool*);
|
|
|
|
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;
|
|
}
|
|
|
|
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;
|
|
}
|
|
|