homework/cpp/myfuncOOP.cpp

38 lines
883 B
C++
Raw Normal View History

2024-05-23 10:49:57 +00:00
#include "myfuncOOP.hpp"
MyfuncOOP::MyfuncOOP(const char* alfabet, const char* slowo, uint8_t* wynik)
: alfabet(alfabet), slowo(slowo), wynik(wynik) {
}
void MyfuncOOP::countCharacters() {
int alfabet_length = myStrlen(alfabet);
for (int i = 0; i < alfabet_length; ++i) {
wynik[i] = 0; // Initialize counts to zero
}
for (int i = 0; i < alfabet_length; ++i) {
for (int j = 0; slowo[j] != '\0'; ++j) {
if (alfabet[i] == slowo[j]) {
wynik[i]++;
}
}
}
}
const uint8_t* MyfuncOOP::getResults() const {
return wynik;
}
int MyfuncOOP::myStrlen(const char* str) {
int length = 0;
while (str[length] != '\0') {
++length;
}
return length;
}
// MyfuncOOP zliczacz(alfabet, slowo, wynik);
// zliczacz.countCharacters();
// const uint8_t* results = zliczacz.getResults();