scale implement
This commit is contained in:
parent
77fdbf36dc
commit
f67603bc36
18
main.cpp
18
main.cpp
@ -20,20 +20,22 @@ 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("Average of:");
|
||||
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);
|
||||
printm("avgitr: ");
|
||||
printlm(avgitr(&lst));
|
||||
printm("avgfor: ");
|
||||
printlm(avgfor(&lst));
|
||||
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;
|
||||
}
|
||||
|
||||
@ -71,6 +73,10 @@ double avgitr(std::list<double> *values) {
|
||||
|
||||
double avgfor(std::list<double> *values) {
|
||||
double sum {};
|
||||
for (auto c : *values) sum += c;
|
||||
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;
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user