maximum via for itr
This commit is contained in:
parent
f67603bc36
commit
34044faf99
29
main.cpp
29
main.cpp
@ -1,5 +1,6 @@
|
|||||||
#include <iostream>
|
#include <iostream>
|
||||||
#include <list>
|
#include <list>
|
||||||
|
#include <vector>
|
||||||
#include <iomanip>
|
#include <iomanip>
|
||||||
|
|
||||||
using string = std::string;
|
using string = std::string;
|
||||||
@ -20,22 +21,20 @@ 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 maximum(std::vector<int>&);
|
||||||
|
int maximum(std::list<int>&);
|
||||||
|
|
||||||
|
|
||||||
int main() {
|
int main() {
|
||||||
printlm("Scale:");
|
printlm("Largest:");
|
||||||
bool s {};
|
bool s {};
|
||||||
std::list<double> lst {};
|
std::list<int> lst {};
|
||||||
do {
|
do {
|
||||||
auto v = promptd("Enter a double value: ", &s);
|
auto v = prompti("Enter a integer value: ", &s);
|
||||||
if (s) lst.push_back(v);
|
if (s) lst.push_back(v);
|
||||||
} while (s);
|
} while (s);
|
||||||
auto scalef = promptd("Enter double scalar: ", &s);
|
printm("Maximum: ");
|
||||||
if (!s) return -1;
|
printlm(maximum(lst));
|
||||||
printlm("Scaled:");
|
|
||||||
scale(lst, scalef);
|
|
||||||
for (const auto c : lst) printlm(c);
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -77,6 +76,14 @@ double avgfor(std::list<double> *values) {
|
|||||||
return sum / values->size();
|
return sum / values->size();
|
||||||
}
|
}
|
||||||
|
|
||||||
void scale(std::list<double> &values, double sf) {
|
int maximum(std::vector<int> &values) {
|
||||||
for (auto &c : values) c *= sf;
|
int m {};
|
||||||
|
for (const auto c : values) if (c > m) m = c;
|
||||||
|
return m;
|
||||||
|
}
|
||||||
|
|
||||||
|
int maximum(std::list<int> &values) {
|
||||||
|
int m {};
|
||||||
|
for (const auto c : values) if (c > m) m = c;
|
||||||
|
return m;
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user