1
0

Compare commits

..

No commits in common. "ca5e6e833113589ee9bb5ed81d96265edce5a225" and "f8c0961b3fb0842e41ac7eca155a0a64040e5c08" have entirely different histories.

View File

@ -1,50 +1,63 @@
#include <string>
#include <vector>
#include <algorithm>
#include <iostream> #include <iostream>
#include <vector>
#include <iomanip>
#include "stats.h"
using string = std::string; using string = std::string;
using svector = std::vector<string>;
string prompts(const string&,bool*); //Placw in header!
void sortVStringsAsc(svector &v); template <typename T>
void printm(T m)
{
std::cout << m;
}
int main() { template <typename T>
svector inputs; void printlm(T m)
bool s{true}; {
while (s) { printm(m);
auto inp = prompts("Enter a string (Invalid to begin processing): ",&s); printm("\n");
if (s) inputs.push_back(inp); }
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);
} }
sortVStringsAsc(inputs); while(s);
for (const auto &c : inputs) std::cout << c << "\n"; 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; return 0;
} }
void sortVStringsAsc(svector &v) { double promptd(string message, bool *status)
sort(v.begin(), v.end(), [] (const string &x, const string &y) {return x.length() < y.length();}); {
} double tr {0.0};
*status = false;
double sumList(const std::vector<double> &l) {
double sum = 0.0;
for (const auto &c : l) sum += c;
return sum;
}
class A {
std::vector<string> s;
};
string prompts(const string &message, bool *success) {
string tr{""};
*success = false;
std::cout << message; std::cout << message;
if (!(std::cin >> tr)) { if (!(std::cin >> tr))
{
std::cin.clear(); std::cin.clear();
std::cin.ignore(); std::cin.ignore();
return ""; return 0.0;
} }
*success = true; *status = true;
return tr; return tr;
} }