Skip to content

Instantly share code, notes, and snippets.

@ereidland
ereidland / gist:5136514
Created March 11, 2013 18:39
Example 1 at Library
#include <iostream>
using namespace std;
void refFunc(int &);//Function headers. They do not require a name or body at this point.
void pointerFunc(int *);
int main()
{
int something = 32; //Declare something as 32.
@ereidland
ereidland / gist:5136797
Created March 11, 2013 19:07
Example 2 at Library
#include <iostream>
using namespace std;
#define ARRAY_SIZE 128
void lol(const int); //Function header for lol.
int main()
{
@ereidland
ereidland / gist:5136943
Created March 11, 2013 19:28
Example 3 at Library
#include <iostream>
#include <iomanip>
using namespace std;
int main()
{
//Note that in the below example I do not validate the numbers. This is bad practice. Don't do it.
int numStudents,
numScores, //Values can be separated by comma if they have the same base type.
@ereidland
ereidland / gist:5137527
Created March 11, 2013 20:38
Assignment 4 at Library
#include <iostream>
#include <iomanip>
#include <random>
using namespace std;
//See function bodies for comments on these.
int * createArray(int & size);
void findStats(int * arr, int size, int & min, int & max, double & average);
@ereidland
ereidland / gist:5278241
Last active December 15, 2015 14:58
Example 5 at Library
#define MAX_INVENTORY 100
//Arguments to use in cin.ignore:
#define IGNORE_ARGS 256, '\n'
#include <fstream>
#include <iomanip>
#include <iostream>
#include <string>
@ereidland
ereidland / alljs.php
Last active December 16, 2015 04:29
Loads all JavaScript files in a directory, and echos back their contents. Needs some work, but it works for a quick hack during development when dealing with lots of javascript files.
<?php
//To echo everything alphabetically:
// includeJS("./");
//includeJS can take an entry set or a path.
//For getting an entry set:
// getJSEntries($path [, $baseentries = []])
//$baseentries can be specified so that all file entries within $baseentries will be ignored.
//If $path is a file, it adds that file to the existing entries (specified by $baseentries).
//If $path is a folder, it does the same as the above for each file. Note that folder searches are recursive.
//The return result is the $baseentries array, merged with the sorted results of getJSEntries.
@ereidland
ereidland / C++ ref (at library).cpp
Created April 13, 2013 16:37
Reference at Library.
//Format for functions:
//type name (arguments)
//{}
char * myFunction (int lol)
{
//Variables:
//type name;
char * myArray;
//Initializing to new array:
@ereidland
ereidland / Example 6 at Library.cpp
Created April 13, 2013 16:57
Example 6 at Library.
#include <iostream>
using namespace std;
char * myFunction(const char * str)
{
//Declare the fixed size array of 32 ize.
char fixedSizeArray[32];
//Copy str into it.
strcpy(fixedSizeArray, str);
@ereidland
ereidland / Example 7 (Question 12).cpp
Created April 13, 2013 17:17
Example 7 at Library
//Question 12 answer
//Given this struct:
struct student
{
string name;
int credits;
double grades[6];
};
student * highestGrade(student students[], int numberOfStudents)
@ereidland
ereidland / Program 12(C++ I Lab).cpp
Last active December 16, 2015 10:08
Dynamic memory allocation, name sorting, and searching.
#include <stdio.h>
#include <iostream>
using namespace std;
#define LONG_NAME_SIZE 512
void main()
{
int numNames = 0;