87 lines
1.6 KiB
C++
87 lines
1.6 KiB
C++
#include <iostream>
|
|
#include <list>
|
|
#include <vector>
|
|
#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 delzrfrst(std::list<double>&);
|
|
|
|
|
|
int main() {
|
|
printlm("Remove first zero from:");
|
|
bool s {};
|
|
std::list<double> lst {};
|
|
do {
|
|
auto v = promptd("Enter a double value: ", &s);
|
|
if (s) lst.push_back(v);
|
|
} while (s);
|
|
printlm("First zero removed:");
|
|
delzrfrst(lst);
|
|
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 delzrfrst(std::list<double> &values) {
|
|
for (auto itr {values.cbegin()}; itr != values.cend(); ++itr) {
|
|
if (*itr == 0) {
|
|
itr = values.erase(itr);
|
|
break;
|
|
}
|
|
}
|
|
}
|