Skip to content

Instantly share code, notes, and snippets.

View jesyspa's full-sized avatar

Komi Golov jesyspa

View GitHub Profile
@jesyspa
jesyspa / encrypt.cpp
Created June 24, 2012 12:31 — forked from anonymous/Glitched Rail Fence Cipher Encryption
Rail Fence Cipher Encryption
#include <iostream>
#include <string>
#include <stdexcept>
std::string encrypt(std::string const& plaintext) {
if (plaintext.length() <= 4)
throw std::runtime_error("Invalid string length.");
std::string first;
std::string second;
@jesyspa
jesyspa / pointbad.cpp
Created June 24, 2012 19:25
Example of bad implementation of a 1D point class
class PointBad {
private:
int x_;
public:
PointBad(int x) : x_(x) {}
int GetX() {
return this->x_;
}
};
@jesyspa
jesyspa / pointgood.cpp
Created June 24, 2012 19:26
A better implementation of a 1D point
class PointGood {
private:
int x_;
public:
PointGood(int x) : x_(x) {}
int GetX() const {
return this->x_;
}
};
@jesyspa
jesyspa / pointbroken.cpp
Created June 24, 2012 19:27
A broken implementation of a 1D point
struct PointBroken {
private:
int x_;
public:
PointBroken(int x) : x_(x) {}
int GetX() const {
this->x_ = 7; // Compiler error: not allowed to modify this->x_.
return this->x_;
}
@jesyspa
jesyspa / anotherbrokenpoint.cpp
Created June 24, 2012 19:27
Another broken 1D point implementation
struct PointAgainBroken {
private:
int x_;
void SetXToSeven() {
this->x_ = 7;
}
public:
PointAgainBroken(int x) : x_(x) {}
int GetX() const {
#ifndef HAND_H
#define HAND_H
// string is not IO.
#include <string>
// For random
#include <cstdlib>
class hand
@jesyspa
jesyspa / gist:3884977
Created October 13, 2012 15:23
Context handler system
#include <memory>
#include <stack>
#include <vector>
#include <iostream>
#include <functional>
// Stores an overview of everything. It is very easy to get this wrong;
// try to keep as few things as possible directly in this class, and as
// much as possible in more focused classes.
class World;
@jesyspa
jesyspa / Slope.cpp
Last active December 11, 2015 10:38 — forked from IHolzman/Slope
// Don't forget to label as C++.
#include <iostream>
// No need to use the std namespace.
int main() {
// Arrows in the wrong direction, and forgot a newline at the end of the string.
std::cout << "This is used to find the slope of the line. Please enter two points.\n";
// No need to use new here.
float y1, y2, x1, x2;
#include <iostream>
#include <limits>
#include <sstream>
#include <string>
#include <vector>
int main() {
std::cin.ignore(std::numeric_limits<std::streamsize>::max(), '\n');
for (std::string line; std::getline(std::cin, line);) {
#include <iostream>
/*
* Programming Assignment 02
* This program will accept, from the user, the type of recreational equipment
* being rented, as well as the duration of the rental. It will then display a
* summary of the sale, first listing the duration of the rental, then the
* recreational equipment being rented, and then the total cost of the rental.
*
* Program Preconditions
* 1. The user will enter the type of equipment rental, which will be S for