Compare commits
4 Commits
f8c0961b3f
...
ca5e6e8331
Author | SHA1 | Date | |
---|---|---|---|
ca5e6e8331 | |||
891ee1959a | |||
798006c8d0 | |||
672289a9cf |
81
main.cpp
81
main.cpp
@ -1,63 +1,50 @@
|
|||||||
#include <iostream>
|
#include <string>
|
||||||
#include <vector>
|
#include <vector>
|
||||||
#include <iomanip>
|
#include <algorithm>
|
||||||
#include "stats.h"
|
#include <iostream>
|
||||||
|
|
||||||
using string = std::string;
|
using string = std::string;
|
||||||
|
using svector = std::vector<string>;
|
||||||
|
|
||||||
//Placw in header!
|
string prompts(const string&,bool*);
|
||||||
template <typename T>
|
void sortVStringsAsc(svector &v);
|
||||||
void printm(T m)
|
|
||||||
{
|
|
||||||
std::cout << m;
|
|
||||||
}
|
|
||||||
|
|
||||||
template <typename T>
|
int main() {
|
||||||
void printlm(T m)
|
svector inputs;
|
||||||
{
|
bool s{true};
|
||||||
printm(m);
|
while (s) {
|
||||||
printm("\n");
|
auto inp = prompts("Enter a string (Invalid to begin processing): ",&s);
|
||||||
}
|
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);
|
|
||||||
}
|
}
|
||||||
while(s);
|
sortVStringsAsc(inputs);
|
||||||
printm("Score median is: ");
|
for (const auto &c : inputs) std::cout << c << "\n";
|
||||||
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;
|
||||||
}
|
}
|
||||||
|
|
||||||
double promptd(string message, bool *status)
|
void sortVStringsAsc(svector &v) {
|
||||||
{
|
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 0.0;
|
return "";
|
||||||
}
|
}
|
||||||
*status = true;
|
*success = true;
|
||||||
return tr;
|
return tr;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user