Skip to content
This repository has been archived by the owner on Jun 21, 2024. It is now read-only.

Commit

Permalink
______________________________________________________
Browse files Browse the repository at this point in the history
  • Loading branch information
DimaYanuschik committed Jun 20, 2024
1 parent a43c979 commit 1f9e303
Showing 1 changed file with 37 additions and 35 deletions.
72 changes: 37 additions & 35 deletions trunk/po0_220227/task_05/src/List.h
Original file line number Diff line number Diff line change
@@ -1,46 +1,48 @@

#pragma once
#prag

#include <iostream>
#include <list>
#include <cmath>

template <typename T>
class List {
private:
std::list<T> container;

class Pair
{
public:
Pair() = default;
Pair(const int firstNumber, const double secondNumber);
Pair(const Pair& other) = default;
~Pair() = default;

Pair& operator=(const Pair& a) = default;
bool operator==(const Pair& a) const = default;

friend std::ostream& operator<<(std::ostream& out, const Pair& a)
{
out << a.GetFirstNumber() << ":" << a.GetSecondNumber() << std::endl;
return out;
void fillElements(const std::initializer_list<T>& elements) {
container.assign(elements);
}

friend std::istream& operator>>(std::istream& in, Pair& a)
{
std::cout << "Enter first number(int)" << std::endl;
in >> a.firstNumber;
std::cout << "Enter second number(double)" << std::endl;
in >> a.secondNumber;
return in;
void addElementAtPosition(const T& element, size_t position) {
auto it = container.begin();
std::advance(it, position);
container.insert(it, element);
}

inline void SetFirstNumber(const int fNum) { firstNumber = fNum; };
inline void SetSecondNumber(const double sNum) { secondNumber = sNum; };

inline int GetFirstNumber() const { return firstNumber; };
inline double GetSecondNumber() const { return secondNumber; };
void removeElementAtPosition(size_t position) {
auto it = container.begin();
std::advance(it, position);
container.erase(it);
}

private:
int firstNumber = 0;
double secondNumber = 0.0;
void findAndAddAverage(size_t position) {
if (container.empty()) {
return;
}

T sum = 0;
for (const auto& element : container) {
sum += element;
}
T average = sum / static_cast<T>(container.size());
addElementAtPosition(average, position);
}

friend Pair operator+(const Pair& lhs, const Pair& rhs)
{
return Pair(lhs.firstNumber + rhs.firstNumber, lhs.secondNumber + rhs.secondNumber);
void printElements() const {
for (const auto& element : container) {
std::cout << element << " ";
}
std::cout << std::endl;
}
};
};

0 comments on commit 1f9e303

Please sign in to comment.