Skip to content

Instantly share code, notes, and snippets.

View drpventura's full-sized avatar

Philip R. Ventura, Ph.D. drpventura

View GitHub Profile
@drpventura
drpventura / main.cpp
Created December 3, 2016 18:00
Code from final exam video.
#include <iostream>
#include <fstream>
#include <cstdlib> // for rand
#include "utils.h"
using namespace std;
/**
* NOTE: You may add other headers
* as well as your own functions
@drpventura
drpventura / helpers.h
Last active November 28, 2016 19:33
Example showing growth of O(n) search. See video at https://youtu.be/PB4wHHS_f3A
#include <iostream>
#include <iterator>
#include <random>
#include <chrono>
using namespace std;
#ifndef LSEARCH_UTILS_H
#define LSEARCH_UTILS_H
@drpventura
drpventura / main.cpp
Created October 22, 2016 18:13
Splitting a string based on a regular expression
// based on code taken from
// http://en.cppreference.com/w/cpp/regex/regex_iterator#Example,
// last access 10/22/2016
#include <regex>
#include <iostream>
using namespace std;
int main() {
// some words to pick apart
@drpventura
drpventura / Roster.cpp
Last active June 1, 2022 18:30
Shows a class that is a wrapper over a vector of objects. Includes using STL copy, and find_if, along with C++11 for each loop. See video at https://youtu.be/usBts0ccGsw.
#include <iterator>
#include <algorithm>
#include "Roster.h"
Roster::Roster() { }
void Roster::add(Student& student) {
students.push_back(student);
}
@drpventura
drpventura / Student.cpp
Last active March 28, 2023 04:24
Student class moved to separate .h and .cpp files. See video at https://youtu.be/gyA7uDlazkc.
#include "Student.h"
using namespace std;
Student::Student(string theName, double theGpa) : name(theName), gpa(-1) {
set_gpa(theGpa);
}
// accessor
@drpventura
drpventura / main.cpp
Last active September 29, 2016 02:12
Introduction to classes, accessors, mutators, friend functions. See video at https://youtu.be/81jbKLL-CZM.
#include <iostream>
using namespace std;
class Student {
//private:
string name;
double gpa;
public:
@drpventura
drpventura / vector-ex.cpp
Last active August 28, 2016 22:29
Introduction to vectors, and stl for IO. See video at: https://youtu.be/u79ulGcaHMs.
#include <iostream>
#include <vector>
#include <iterator>
#include <algorithm>
#include <fstream>
using namespace std;
vector<int> get_evens(const vector<int>& nums) {
vector<int> results;
@drpventura
drpventura / main.cpp
Last active August 28, 2016 21:22
STL copy function, and comparing builtin arrays with std::array container class. See the video at https://youtu.be/L3IOAsgTpu4.
#include <iostream>
#include <algorithm>
#include <iterator>
#include <array>
using namespace std;
void cube(int& l) {
l = l * l * l;
}
#include <iostream>
#include <algorithm>
using namespace std;
void cube(int& l) {
l = l * l * l;
}
int main() {