Skip to content

Instantly share code, notes, and snippets.

View grayed's full-sized avatar
💭
C to C#: how much in this halftone

Vadim Zhukov grayed

💭
C to C#: how much in this halftone
  • self-employed, teacher at MIREA
  • Russia/Moscow
  • X @persgray
View GitHub Profile
@grayed
grayed / unbalanced-search-binary-tree.cpp
Last active May 22, 2024 13:02
Не сбалансированное бинарное дерево поиска
#include <iostream>
#include <iterator>
#include <string>
#include <vector>
class Tree {
struct TreeNode {
TreeNode *left, *right;
TreeNode *parent;
@grayed
grayed / matrix-file.cpp
Last active May 15, 2024 12:06
Saving and loading matricies
#include <climits>
#include <iostream>
#include <fstream>
#include <cstring>
#include <new>
using namespace std;
/*
* data access layer - взаимодействует с данными непосредственно во внешних источниках
@grayed
grayed / lazy-copy.cpp
Created May 8, 2024 10:50
Lazy copying (fixed)
#include <climits>
#include <iostream>
#include <cstring>
#include <new>
using namespace std;
class Matrix {
struct MatrixData {
double *nums;
@grayed
grayed / lazy-copy-matrix
Created May 8, 2024 10:24
Lazy copying (invalid)
#include <climits>
#include <iostream>
#include <cstring>
#include <new>
using namespace std;
class Matrix {
struct MatrixData {
double *nums;
@grayed
grayed / copyclass.cpp
Last active April 24, 2024 12:56
Copy constructor and Co.
#include <climits>
#include <iostream>
#include <cstring>
#include <new>
using namespace std;
class Matrix {
double *nums;
size_t nrows, ncols;
@grayed
grayed / twodimarr.cpp
Last active April 17, 2024 12:51
TwoDimArray
#include <chrono>
#include <cstring>
#include <iostream>
#include <vector>
using namespace std;
class TwoDimArray {
double *data;
size_t nrows, ncols;
public:
@grayed
grayed / virt.cpp
Created April 3, 2024 13:38
Virtual functions
#include <iostream>
using namespace std;
class Animal {
string latin_name;
public:
Animal(string latin_name) : latin_name{latin_name} {}
virtual ~Animal() { cerr << "Animal::~Animal called for " << latin_name << endl; }
virtual string get_display_name() const { return latin_name; }
virtual int foo() = 0;
@grayed
grayed / refptr.cpp
Created March 13, 2024 13:06
Ptr and ref C++
#include <iostream>
using namespace std;
int ma8in() {
int a = 3, b = 7, c, nums[100] = { 11, 22, 33 };
int *p1 = &a, *p2 = &b, *p3 = &c, *pn = nums;
void *p = p1; p3 = (int*)p;
c = a + b;
cout << "a=" << a << ", b=" << b << ", c=" << c
<< ", *p1=" << *p1 << ", *p2=" << *p2 << ", *p3=" << *p3 << endl;
@grayed
grayed / anidiag.cpp
Created March 6, 2024 12:53
Animals with diagnosis
#include <ctime>
#include <iostream>
using namespace std;
class Animal {
string name;
time_t birth_date;
public:
Animal(string name, time_t birth_date) : name(name), birth_date(birth_date) {}
string get_name() const { return name; }
time_t get_birth_date() const { return birth_date; }
@grayed
grayed / calcstr.cpp
Created February 21, 2024 12:46
КМБО-07-23 калькулятор со string
#include <cmath>
#include <cstdlib>
#include <iostream>
using namespace std;
float calc(string op, float x, float y);
int main() {
float x, y, res;