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 promptd(string,bool*);
|
||||||
double avgitr(std::list<double>*);
|
double avgitr(std::list<double>*);
|
||||||
double avgfor(std::list<double>*);
|
double avgfor(std::list<double>*);
|
||||||
|
void scale(std::list<double>&,double);
|
||||||
|
|
||||||
|
|
||||||
int main() {
|
int main() {
|
||||||
printlm("Average of:");
|
printlm("Scale:");
|
||||||
bool s {};
|
bool s {};
|
||||||
std::list<double> lst {};
|
std::list<double> lst {};
|
||||||
do {
|
do {
|
||||||
auto v = promptd("Enter a double value: ", &s);
|
auto v = promptd("Enter a double value: ", &s);
|
||||||
if (s) lst.push_back(v);
|
if (s) lst.push_back(v);
|
||||||
} while (s);
|
} while (s);
|
||||||
printm("avgitr: ");
|
auto scalef = promptd("Enter double scalar: ", &s);
|
||||||
printlm(avgitr(&lst));
|
if (!s) return -1;
|
||||||
printm("avgfor: ");
|
printlm("Scaled:");
|
||||||
printlm(avgfor(&lst));
|
scale(lst, scalef);
|
||||||
|
for (const auto c : lst) printlm(c);
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -71,6 +73,10 @@ double avgitr(std::list<double> *values) {
|
|||||||
|
|
||||||
double avgfor(std::list<double> *values) {
|
double avgfor(std::list<double> *values) {
|
||||||
double sum {};
|
double sum {};
|
||||||
for (auto c : *values) sum += c;
|
for (const auto c : *values) sum += c;
|
||||||
return sum / values->size();
|
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