minor fixes
This commit is contained in:
parent
56abebdcc8
commit
80614e6fbb
|
@ -5,8 +5,15 @@
|
|||
* Author: alexander
|
||||
*/
|
||||
|
||||
#include "exercises.hpp"
|
||||
#include <vector>
|
||||
#include <list>
|
||||
#include <math.h>
|
||||
#include <algorithm>
|
||||
|
||||
#include "exercises.hpp"
|
||||
#include "templates.hpp"
|
||||
|
||||
using namespace std;
|
||||
|
||||
void exercise_1()
|
||||
{
|
||||
|
@ -21,12 +28,16 @@ void exercise_1()
|
|||
insert_sorted(v, newIntValue);
|
||||
print(v); // -9 -9 -4 -3 3 3 4 6 8 9 10
|
||||
|
||||
cout << endl;
|
||||
|
||||
list<double> l(size);
|
||||
generator(l, -10.0, 10.0);
|
||||
l.sort();
|
||||
print(l); // -9.31992 -6.76971 -5.98545 -2.1297 -1.9722 -0.292701 0.715274 3.43089 4.35249 9.45377
|
||||
insert_sorted(l, newDoubleValue);
|
||||
print(l); // -9.31992 -6.76971 -5.98545 -2.1297 -1.9722 -0.292701 0.715274 2.2 3.43089 4.35249 9.45377
|
||||
|
||||
cout << endl;
|
||||
}
|
||||
|
||||
void exercise_2()
|
||||
|
@ -39,10 +50,12 @@ void exercise_2()
|
|||
print(v); // 1-ый вектор - печать исходного вектора
|
||||
copy(v.begin(), v.end(), ostream_iterator<int> { cout, " " }); // 2-ой вектор - печать целочисленного вектора
|
||||
|
||||
cout << endl;
|
||||
|
||||
for_each(v.begin(), v.end(), [&](const double &i)
|
||||
{
|
||||
error += pow(i - static_cast<int>(i), 2);
|
||||
});
|
||||
|
||||
cout << endl << error << endl;
|
||||
cout << endl << "Ошибка между цифровым и аналоговым сигналом равна " << error << endl;
|
||||
}
|
||||
|
|
|
@ -7,7 +7,5 @@
|
|||
|
||||
#pragma once
|
||||
|
||||
#include "templates.hpp"
|
||||
|
||||
void exercise_1();
|
||||
void exercise_2();
|
||||
|
|
|
@ -9,7 +9,7 @@
|
|||
|
||||
int main()
|
||||
{
|
||||
// exercise_1();
|
||||
exercise_1();
|
||||
exercise_2();
|
||||
|
||||
return 0;
|
||||
|
|
|
@ -8,20 +8,15 @@
|
|||
#pragma once
|
||||
|
||||
#include <iostream>
|
||||
#include <vector>
|
||||
#include <random>
|
||||
#include <algorithm>
|
||||
#include <iterator>
|
||||
#include <list>
|
||||
|
||||
using namespace std;
|
||||
|
||||
template<template<typename, typename> class TContainer, typename TItem, typename TIterator, typename T>
|
||||
void generator(TContainer<TItem, TIterator> &c, const T &rangeStart, const T &rangeEnd)
|
||||
{
|
||||
random_device rd;
|
||||
mt19937 mersenne(rd());
|
||||
uniform_real_distribution<double> urd(rangeStart, rangeEnd);
|
||||
std::random_device rd;
|
||||
std::mt19937 mersenne(rd());
|
||||
std::uniform_real_distribution<double> urd(rangeStart, rangeEnd);
|
||||
generate(c.begin(), c.end(), [&]()
|
||||
{
|
||||
return urd(mersenne);
|
||||
|
@ -31,8 +26,8 @@ void generator(TContainer<TItem, TIterator> &c, const T &rangeStart, const T &ra
|
|||
template<template<typename, typename> class TContainer, typename TItem, typename TIterator>
|
||||
void print(const TContainer<TItem, TIterator> &c)
|
||||
{
|
||||
copy(c.begin(), c.end(), ostream_iterator<TItem> { cout, " " });
|
||||
cout << endl;
|
||||
copy(c.begin(), c.end(), std::ostream_iterator<TItem> { std::cout, " " });
|
||||
std::cout << std::endl;
|
||||
}
|
||||
|
||||
template<template<typename, typename> class TContainer, typename TItem, typename TIterator>
|
||||
|
|
Loading…
Reference in New Issue