Skip to content

Instantly share code, notes, and snippets.

View itsjohncs's full-sized avatar

John Sullivan itsjohncs

View GitHub Profile
@itsjohncs
itsjohncs / cyoa.cpp
Created October 15, 2012 06:07
CS 10 SI Lab Session 3 - CYOA Example
#include <iostream>
using namespace std;
int main() {
cout << "You wake up to find yourself in the entry hall of a mansion. "
"There are two doors in the hall, one leading outside, another "
"leads further into the mansion.\n"
"\t1) Go outside\n"
"\t2) Go further into the mansion\n"
@itsjohncs
itsjohncs / main.cpp
Created October 15, 2012 07:39
CS 10 SI Lab Session 3 - Roulette Exercise
#include <iostream>
#include <cstdlib>
using namespace std;
int main() {
// What would happen if we replaced time(0) here with a number, like 2?
srand(time(0));
// The two question marks below mean that you should figure out the correct
@itsjohncs
itsjohncs / main.cpp
Created October 22, 2012 06:21
SI Classroom Session 4 - Conditional Review
#include <iostream>
using namespace std;
int main() {
int user_input = 0;
cout << "Please enter a number: ";
cin >> user_input;
if (user_input <= 1) {
@itsjohncs
itsjohncs / main.cpp
Created October 22, 2012 07:05
SI Classroom Session 4 - Converting While Loops into For Loops
#include <iostream>
using namespace std;
int main() {
string name;
cout << "Please enter your first name: ";
cin >> name;
int i = 0;
@itsjohncs
itsjohncs / main.cpp
Created October 22, 2012 07:28
Classroom Session 4 - Fruit Example
#include <iostream>
using namespace std;
int main() {
string fruit;
cout << "Please enter a fruit: ";
cin >> fruit;
while (!(fruit == "apple" || fruit == "orange" || fruit == "pineapple")) {
@itsjohncs
itsjohncs / gist:3954605
Created October 25, 2012 18:43
Maps? Arrays? Psh.
/*
* Example field (aka columns) names and values, that will be used in the
* CAML query. The values are the attributes of a single list item here.
* If the field name contains a space in SharePoint, replace it
* here with _x0020_ (including underscores).
*/
$field1Name = "Name";
$field2Name = "Email";
$field3Name = "PhoneNumber";
@itsjohncs
itsjohncs / gist:3963075
Created October 27, 2012 05:34
Sneaky computers.
if (result <= 10) {
handling();
} else if (result > 10) {
otherHandling();
} else {
handling(); // to be sure
}
@itsjohncs
itsjohncs / main.cpp
Created November 5, 2012 07:33
Classroom Session 6 - Test Harness Example: extract_name()
#include <iostream>
using namespace std;
/**
* @brief Extracts the name out of a greeting.
*
* For example, given the input "Hello, my name is John.", this function should
* return "John". Exclamatory statements should work as well ("... is John!").
* Also, any greeting may be used, ex: "Grettings fellow, my name is John!" will
@itsjohncs
itsjohncs / find.cpp
Created November 5, 2012 08:00
Classroom Session 6 - Johnnie Appleseed
#include <iostream>
using namespace std;
int main() {
string name = "Johnnie Appleseed's Amazing Fruit Stand!";
// What does each of these print out?
cout << name.find("Johnnie") << endl;
cout << name.find("s") << endl;
@itsjohncs
itsjohncs / main.cpp
Created November 6, 2012 21:14
Lab Session 6 - Answer to Exercise 4
#include <iostream>
using namespace std;
string extract_bolds(string input) {
string result;
string working = input;
while (working.find("<b>") != -1 && working.find("</b>") != -1) {
int first = working.find("<b>") + 3;