Skip to content

Instantly share code, notes, and snippets.

#include "MyString.hpp"
#include <cstring>
#include <stdexcept>
int MyString::created_count = 0;
void MyString::ensure_capacity(int needLen) {
if (needLen + 1 <= capacity) return;
int newCap = capacity > 0 ? capacity : 1;
while (newCap < needLen + 1) newCap *= 2;
#include <iostream>
#include <cstring>
#include <stdexcept>
class MyString {
char* str;
int length;
int capacity;
void ensure_capacity(int needLen) {
#include "DynamicArray.h"
#include <algorithm>
#include <cstdlib>
DynamicArray::DynamicArray() : ptr(nullptr), size(0) {}
DynamicArray::DynamicArray(int S) {
std::cout << "Construct by 1 param\n";
if (S < 0) S = 0;
size = S;
#include "DynamicArray.h"
#include <algorithm>
#include <cstdlib>
DynamicArray::DynamicArray() : ptr(nullptr), size(0) {}
DynamicArray::DynamicArray(int S) {
std::cout << "Construct by 1 param\n";
if (S < 0) S = 0;
size = S;
@vlaleli
vlaleli / cpu.cpp
Last active September 17, 2025 21:22
#include "cpu.h"
int CPU::cstr_len(const char* s){ int n=0; if(!s) return 0; while(s[n]!='\0') ++n; return n; }
char* CPU::cstr_dup(const char* s){
if(!s) return nullptr; int n=cstr_len(s); char* r=new char[n+1];
for(int i=0;i<n;++i) r[i]=s[i]; r[n]='\0'; return r;
}
CPU::CPU(const char* model, int cores, double freqGHz)
: m_model(cstr_dup(model)), m_cores(cores), m_freqGHz(freqGHz) {}
#include "cpu.h"
static int cstr_len(const char* s){ int n=0; if(!s) return 0; while(s[n]!='\0') ++n; return n; }
static char* cstr_dup(const char* s){
if(!s) return nullptr; int n=cstr_len(s); char* r=new char[n+1];
for(int i=0;i<n;++i) r[i]=s[i]; r[n]='\0'; return r;
}
CPU::CPU(const char* model, int cores, double freqGHz)
: m_model(cstr_dup(model)), m_cores(cores), m_freqGHz(freqGHz) {}
#include "Car.h"
#include <iostream>
#include <string.h>
using namespace std;
Car::Car()
{
this->model = nullptr;
this->color = nullptr;
this->year = 0;
#include <iostream>
#include <fstream>
using namespace std;
int str_len(const char* s) { int n = 0; if (!s) return 0; while (s[n] != '\0') n++; return n; }
void str_copy(char* dst, const char* src, int cap) {
if (!dst || cap <= 0) return;
int i = 0;
if (src) { while (src[i] != '\0' && i < cap - 1) { dst[i] = src[i]; i++; } }
dst[i] = '\0';
#include <iostream>
using namespace std;
class Fraction {
private:
int numerator;
int denominator;
public:
#include <iostream>
using namespace std;
const int MAX_LEN = 100;
const char* expr;
int pos = 0;
bool is_digit(char ch);
char peek();