83 lines
1.6 KiB
C++
83 lines
1.6 KiB
C++
#include <iostream>
|
|
#include <list>
|
|
#include <iomanip>
|
|
|
|
using string = std::string;
|
|
|
|
//Place in header!
|
|
template <typename T>
|
|
void printm(T m){
|
|
std::cout << m;
|
|
}
|
|
|
|
template <typename T>
|
|
void printlm(T m){
|
|
printm(m);
|
|
printm("\n");
|
|
}
|
|
|
|
int prompti(string,bool*);
|
|
double promptd(string,bool*);
|
|
double avgitr(std::list<double>*);
|
|
double avgfor(std::list<double>*);
|
|
void scale(std::list<double>&,double);
|
|
|
|
|
|
int main() {
|
|
printlm("Scale:");
|
|
bool s {};
|
|
std::list<double> lst {};
|
|
do {
|
|
auto v = promptd("Enter a double value: ", &s);
|
|
if (s) lst.push_back(v);
|
|
} while (s);
|
|
auto scalef = promptd("Enter double scalar: ", &s);
|
|
if (!s) return -1;
|
|
printlm("Scaled:");
|
|
scale(lst, scalef);
|
|
for (const auto c : lst) printlm(c);
|
|
return 0;
|
|
}
|
|
|
|
int prompti(string message, bool *status) {
|
|
int tr {};
|
|
*status = false;
|
|
std::cout << message;
|
|
if (!(std::cin >> tr)){
|
|
std::cin.clear();
|
|
std::cin.ignore();
|
|
return 0;
|
|
}
|
|
*status = true;
|
|
return tr;
|
|
}
|
|
|
|
double promptd(string message, bool *status) {
|
|
double tr {};
|
|
*status = false;
|
|
std::cout << message;
|
|
if (!(std::cin >> tr)){
|
|
std::cin.clear();
|
|
std::cin.ignore();
|
|
return 0.0;
|
|
}
|
|
*status = true;
|
|
return tr;
|
|
}
|
|
|
|
double avgitr(std::list<double> *values) {
|
|
double sum {};
|
|
for (auto itr = values->cbegin(); itr != values->cend(); ++itr) sum += *itr;
|
|
return sum / values->size();
|
|
}
|
|
|
|
double avgfor(std::list<double> *values) {
|
|
double sum {};
|
|
for (const auto c : *values) sum += c;
|
|
return sum / values->size();
|
|
}
|
|
|
|
void scale(std::list<double> &values, double sf) {
|
|
for (auto &c : values) c *= sf;
|
|
}
|