feladat5 kezdet

This commit is contained in:
Damimani 2026-11-03 20:11:31 +01:00
parent 690758ae11
commit 7c659a3093
3 changed files with 143 additions and 1 deletions

View file

@ -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;
};

View file

@ -1 +1,110 @@
// Tóth Dániel Mátyás | IFPQYY | v1
// 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) {
}

View file

@ -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;
};