This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#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; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <iostream> | |
#include <cstring> | |
#include <stdexcept> | |
class MyString { | |
char* str; | |
int length; | |
int capacity; | |
void ensure_capacity(int needLen) { |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#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; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#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; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#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) {} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#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) {} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include "Car.h" | |
#include <iostream> | |
#include <string.h> | |
using namespace std; | |
Car::Car() | |
{ | |
this->model = nullptr; | |
this->color = nullptr; | |
this->year = 0; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#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'; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <iostream> | |
using namespace std; | |
class Fraction { | |
private: | |
int numerator; | |
int denominator; | |
public: | |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <iostream> | |
using namespace std; | |
const int MAX_LEN = 100; | |
const char* expr; | |
int pos = 0; | |
bool is_digit(char ch); | |
char peek(); |
NewerOlder