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