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> //std::cin, std::cout | |
| int main(){ | |
| char response;//single letter that holds the user's response (y/n) | |
| std::cout <<"\n Quit program (y/N)? "; | |
| std::cin >>response; | |
| //single expression if statement: |
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> //cin, cout | |
| /**Functions: | |
| *- Functions return a value (using the keyword "return"). | |
| * | |
| *- Functions that don't return a value are called subroutines (subs), | |
| * however they technically return a weird type called a void (holds no data) | |
| * | |
| *- In C++, functions are treated as variables in respect to their syntax. | |
| * |
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> // std::cin, std::cout, std::string() | |
| ///finds GCF using Euclid's Algorithm ( https://en.wikipedia.org/wiki/Euclidean_algorithm#Implementations (converted to C++)) | |
| template <class T> | |
| T gcf(T a, T b){ | |
| //throw error if numbers aren't whole ( % = remainder: aka 'modulus') | |
| if (a % 1 != 0 || b % 1 != 0) // could be simplified to `if (a % 1 || b % 1)` (as 0 == false) | |
| throw std::string("GCF(): Numbers given weren\'t whole"); //error stops execution |
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> //the library we will be using | |
| using namespace std;//no need to add the 'std::' scope | |
| class Fish{ | |
| //Not the proper way to define a class | |
| // should be in a separate fish.h file with an implementation fish.cpp file | |
| private: | |
| int _length;//how long | |
| string _name, _type; | |
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> //std::string std::cin std::cout | |
| class Fish { | |
| //these are private variables | |
| std::string _type, _name; | |
| int _length; | |
| public: //these are 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> // std::string, std::cout, std::cin | |
| //#include <inttypes.h> | |
| //this function is recursive (calls itself) | |
| long int fac(short int base, long int value = 1){ // factorial | |
| // negative numbers give errors | |
| if (base < 0) | |
| throw "fac(): Can't factorial negative numbers."; |
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
| #ifndef VECTOR2_H | |
| #define VECTOR2_H | |
| template <class TYPE> | |
| class Vector2 { | |
| public: | |
| TYPE x, y; | |
| Vector2(TYPE xVal = 0, TYPE yVal = 0) : x(xVal), y(yVal) {} |
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
| #ifndef ARG_PARSE_H | |
| #define ARG_PARSE_H | |
| #include <string.h> // strcmp, strcat | |
| #include <stdlib.h> // atoi | |
| char* findOccurance(char*,char*); | |
| void getArgs(int, char**, char*, ...); | |
| char hasArg(int,char**, char*); | |
| char* strAfter(int, char**, char*); |
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
| char* findOccurance(char* source, char* query){ | |
| char* queryCopy = query; | |
| while ( *source != '\0') { | |
| if (*(source++) == *query) { | |
| query++; | |
| while (*query != '\0' && *source == *query) { | |
| source++; | |
| query++; |
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
| replaced by https://github.com/robobibb/trophy |