From 7c659a3093420549eba0b04953d9a83f88952513 Mon Sep 17 00:00:00 2001 From: Damimani Date: Tue, 3 Nov 2026 20:11:31 +0100 Subject: [PATCH] feladat5 kezdet --- feladat5/feladat5/CMyString.h | 26 ++++++ feladat5/feladat5/CMyStringException.cpp | 111 ++++++++++++++++++++++- feladat5/feladat5/CMyStringException.h | 7 ++ 3 files changed, 143 insertions(+), 1 deletion(-) diff --git a/feladat5/feladat5/CMyString.h b/feladat5/feladat5/CMyString.h index 07b4e2d..e080569 100644 --- a/feladat5/feladat5/CMyString.h +++ b/feladat5/feladat5/CMyString.h @@ -1,2 +1,28 @@ // Tóth Dániel Mátyás | IFPQYY | v1 #pragma once +class CMyString { // memóriát kétszeresére növeld amikor növelni kell gyerek +public: + CMyString(); + CMyString(const char* psz); + CMyString(char ch, size_t repeat = 1); + CMyString(const CMyString& str); + ~CMyString(); + size_t size() const; + size_t capacity() const; + const char* c_str() const; + void clear(); + char getat(size_t index) const; + void setat(size_t index, char ch); + void reserve(size_t newcapacity); + void erase(size_t pos, size_t count); + bool empty() const; + void display() const; + void shrink_to_fill(); + void reverse(); + void append(const char* psz, unsigned offset = 0, unsigned count = -0); + CMyString& operator=(const CMyString& str); +private: + char* m_pchData; + size_t m_nDataLength; + size_t m_nAllocLength; +}; \ No newline at end of file diff --git a/feladat5/feladat5/CMyStringException.cpp b/feladat5/feladat5/CMyStringException.cpp index 8b09439..0da902b 100644 --- a/feladat5/feladat5/CMyStringException.cpp +++ b/feladat5/feladat5/CMyStringException.cpp @@ -1 +1,110 @@ -// Tóth Dániel Mátyás | IFPQYY | v1 \ No newline at end of file +// Tóth Dániel Mátyás | IFPQYY | v1 +#include "CMyString.h" +#include "CMyStringException.h" + +CMyString::CMyString(){ + m_nDataLength = 0; + m_nAllocLength = 1; + m_pchData = new char[m_nAllocLength]; + m_pchData[0] = '\0'; +} +CMyString::CMyString(const char* psz){ + m_nDataLength = 0; + if (psz == nullptr) + { + m_nAllocLength = 1; + } + else + { + while (psz[m_nDataLength]) + { + m_nDataLength++; + } + m_nAllocLength = m_nDataLength + 1; + } + m_pchData = new char[m_nAllocLength]; + int i = 0; + while (i < m_nAllocLength) + { + m_pchData[i] = psz[i]; + i++; + } + m_pchData[i] = '\0'; +} +CMyString::CMyString(char ch, size_t repeat = 1){ + m_nDataLength = repeat; + m_nAllocLength = repeat + 1; + m_pchData = new char[m_nAllocLength]; + int i = 0; + while (i < repeat) + { + m_pchData[i] = ch; + i++; + } + m_pchData[i] = '\0'; +} +CMyString::CMyString(const CMyString& str){ + if (str.empty()) + { + m_nDataLength = 0; + } + else + { + m_nDataLength = str.size(); + } + m_nAllocLength = m_nDataLength + 1; + m_pchData = new char[m_nAllocLength]; + int i = 0; + const char* cont = str.c_str(); + while (cont[i]) + { + m_pchData[i] = cont[i]; + i++; + } + m_pchData[i] = '\0'; +} +CMyString::~CMyString(){ + delete m_pchData; +} +size_t CMyString::size() const { + +} +size_t CMyString::capacity() const { + +} +const char* CMyString:: c_str() const { + +} +void CMyString::clear() { + +} +char CMyString::getat(size_t index) const { + +} +void CMyString::setat(size_t index, char ch) { + +} +void CMyString::reserve(size_t newcapacity) { + +} +void CMyString::erase(size_t pos, size_t count) { + +} +bool CMyString::empty() const { + return m_nDataLength == 0; +} +void CMyString::display() const { + +} +void CMyString::shrink_to_fill() { + +} +void CMyString::reverse() { + +} +void CMyString::append(const char* psz, unsigned offset = 0, unsigned count = -0) { + +} +CMyString& CMyString::operator=(const CMyString& str) { + +} \ No newline at end of file diff --git a/feladat5/feladat5/CMyStringException.h b/feladat5/feladat5/CMyStringException.h index 07b4e2d..d07b91e 100644 --- a/feladat5/feladat5/CMyStringException.h +++ b/feladat5/feladat5/CMyStringException.h @@ -1,2 +1,9 @@ // Tóth Dániel Mátyás | IFPQYY | v1 #pragma once +class CMyStringException { +public: + CMyStringException(char* input); + const char* what(void); +private: + char* msg; +}; \ No newline at end of file