Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include "Napis.h"
- int main()
- {
- char tekstChar = 'l', tekstChars[10] = "Bb";// a asa
- std::string tekst = "Aa", tekst2 = "bB";//Alka
- Napis<char> tap(tekstChars), pap("bB"), nap, map("aA"), bap(tekstChar);
- //Napis<wchar_t>
- std::cout << "map: " << map << " pap: " << pap << " tap: " << tap << " bap: " << bap << "\n";
- std::cout << "map: " << map++ << " pap: " << pap-- << " tap: " << --tap << " bap: " << ++bap << "\n";
- std::cout << "map: " << map << " pap: " << pap << " tap: " << tap << " bap: " << bap << "\n";
- nap = map + pap;
- std::cout << nap;
- std::cout << std::boolalpha;
- std::cout << "\n(map == pap) = " << (map == pap) << "\n(map != tap) = " << (map != tap) << "\n(map == bap) = " << (map == bap) << " \n";
- std::cout << "((tekst <=> tekst2) < 0) = " << ((tekst <=> tekst2) < 0) << std::endl;
- std::cout << "((pap <=> map) > 0) = " << ((pap <=> map) > 0) << std::endl;
- std::cout << "((pap <=> map) == 0) = " << ((pap <=> map) == 0) << std::endl;
- std::cout << "((pap <=> map) < 0) = " << ((pap <=> map) < 0) << std::endl;
- tekstChar = 'k';
- return 0;
- }
- #pragma once
- #include <iostream>
- #include <fstream>
- #include <compare>
- #include <vector>
- #include <string>
- using std::ostream;
- template <typename T>
- class Napis
- {
- private:
- int lenght;
- std::vector<T> writing;
- public:
- Napis() noexcept;
- Napis(T newThings);
- Napis(const T* newThings);
- Napis(std::vector<T> newThings);
- template <typename T> friend std::basic_ostream<T>& operator<<(std::basic_ostream<T>& os, const Napis<T>& dt);
- std::vector<T> whatIsInside();
- bool operator ==(const Napis<T>& v);
- bool operator !=(const Napis<T>& v);
- std::strong_ordering operator <=>(const Napis<T>& v);
- Napis operator +(const Napis<T>& v);
- Napis<T>& operator =(const Napis<T>& v);
- Napis<T>& operator ++();
- Napis<T>& operator --();
- Napis<T> operator ++(int);
- Napis<T> operator --(int);
- int howLong() noexcept;
- char at(int i);
- };
- template<typename T>
- Napis<T>::Napis() noexcept
- {
- lenght = 0;
- }
- template<typename T>
- Napis<T>::Napis( const T* newThings)
- {
- lenght = strlen(newThings);
- for (int i = 0; i < lenght; i++)
- {
- writing.push_back(*newThings);
- newThings++;
- }
- }
- template<typename T>
- Napis<T>::Napis(T newThings)
- {
- lenght = 1;
- for (int i = 0; i < lenght; i++)
- {
- writing.push_back(newThings);
- newThings++;
- }
- }
- template<typename T>
- Napis<T>::Napis(std::vector<T> newThings)
- {
- lenght = newThings.size();
- for (int i = 0; i < lenght; i++)
- {
- writing.push_back(newThings.at(i));
- }
- }
- template<typename T>
- int Napis<T>::howLong() noexcept
- {
- return this->lenght;
- }
- template<typename T>
- std::vector<T> Napis<T>::whatIsInside()
- {
- return this->writing;
- }
- template<typename T>
- char Napis<T>::at(int i)
- {
- return this->writing.at(i);
- }
- template<typename T>
- std::basic_ostream<T>& operator<<(std::basic_ostream<T>& os, const Napis<T>& dt)
- {
- for (size_t i = 0; i < dt.writing.size(); i++)
- {
- os << dt.writing.at(i);
- }
- return os;
- }
- template<typename T>
- Napis<T> Napis<T>::operator+(const Napis& v)
- {
- Napis result;
- for (size_t i = 0; i < this->writing.size(); i++)
- {
- result.writing.push_back(this->writing.at(i));
- }
- for (size_t i = 0; i < v.writing.size(); i++)
- {
- result.writing.push_back(v.writing.at(i));
- }
- return result;
- }
- template<typename T>
- Napis<T>& Napis<T>::operator++()
- {
- char c = ' ';
- for (size_t i = 0; i < this->writing.size(); i++)
- {
- c = this->writing.at(i);
- this->writing.at(i) = std::toupper(c);
- }
- return *this;
- }
- template<typename T>
- Napis<T>& Napis<T>::operator--()
- {
- char c = ' ';
- for (size_t i = 0; i < this->writing.size(); i++)
- {
- c = this->writing.at(i);
- this->writing.at(i) = std::tolower(c);
- }
- return *this;
- }
- template<typename T>
- Napis<T> Napis<T>::operator++(int)
- {
- Napis result(this->writing);
- ++(*this);
- return result;
- }
- template<typename T>
- Napis<T> Napis<T>::operator--(int)
- {
- Napis<T> result(this->writing);
- --(*this);
- return result;
- }
- template<typename T>
- bool Napis<T>::operator==(const Napis<T>& v)
- {
- if (this->lenght == v.lenght)
- {
- for (int i = 0; i < this->lenght; i++)
- {
- if (this->writing.at(i) != v.writing.at(i))
- {
- return false;
- }
- return true;
- }
- }
- return false;
- }
- template<typename T>
- bool Napis<T>::operator!=(const Napis& v)
- {
- return !(*this == v);
- }
- template<typename T>
- std::strong_ordering Napis<T>::operator<=>(const Napis& v)
- {
- if (this != &v)
- {
- if (this->lenght == v.lenght)
- {
- for (int i = 0; i < this->lenght; i++)
- {
- if (this->writing.at(i) != v.writing.at(i))
- {
- return std::strong_ordering::equal;
- }
- }
- return std::strong_ordering::equal;
- }
- }
- return std::strong_ordering::equal;
- }
- template<typename T>
- Napis<T>& Napis<T>::operator =(const Napis& v) {
- if (this != &v)
- {
- this->lenght = v.lenght;
- this->writing = v.writing;
- }
- return *this;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement