Skip to content

Instantly share code, notes, and snippets.

View simoncourtenage's full-sized avatar

Simon Courtenage simoncourtenage

  • London, UK
View GitHub Profile
@simoncourtenage
simoncourtenage / guesses.php
Created October 9, 2019 14:21
Guesses model
<?php
defined('BASEPATH') OR exit('No direct script access allowed');
class Guesses extends CI_Model {
private $names = array('Taylor Swift',"Lionel Messi","Dwayne Johnson","Brad Pitt","Rihanna");
// the images must be in the same order as the names
private $imageurls
= array(
'https://www.gannett-cdn.com/presto/2019/09/17/USAT/70408641-17f0-4a80-8f7c-596abf9da9a8-AP_People-Taylor_Swifts_House.JPG?width=540&height=&fit=bounds&auto=webp',
'https://pmcwwd.files.wordpress.com/2019/05/messi-1.jpg?w=640&h=415&crop=1',
<!doctype html>
<html>
<head>
<link href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.5/css/bootstrap.min.css" rel="stylesheet">
</head>
<body style="padding:20px">
<div>
<!--
Display the image using the image url sent back by the model.
<!doctype html>
<?php
// we don't always want to display the right name and wrong
// name in the same order, so randomly mix them up
$choice = rand(0,1);
if ($choice == 1) {
// display correct name last
$name1 = $wrongname;
$name2 = $name;
}
@simoncourtenage
simoncourtenage / Guesser.php
Created October 9, 2019 14:18
Guesser controller
<?php
defined('BASEPATH') OR exit('No direct script access allowed');
class Guesser extends CI_Controller {
function __construct()
{
// call base class constructor
parent::__construct();
// Load the guesses model. This will create a new
// attribute object in the controller called 'guesses', which
@simoncourtenage
simoncourtenage / Price.cpp
Created September 28, 2019 10:02
Price class and use - including how to declare friend functions
#include <iostream>
using namespace std;
class Price {
int pounds;
int pence;
public:
Price(float f) {
pounds = static_cast<int>(f);
#include <iostream>
#include <string>
struct Student {
std::string name;
int grade;
};
/*
Calculate average grade for an array of students
@simoncourtenage
simoncourtenage / fileio.cpp
Created September 17, 2019 16:22
C++ reading file and splitting up strings
#include <iostream>
#include <fstream>
#include <sstream>
int main()
{
// create an ifstream object to read the file
// Note this file is in the same directory as the code since the
// filename doesn't contain any directory information
std::ifstream in("data.txt");
@simoncourtenage
simoncourtenage / grade7.cpp
Last active September 9, 2019 11:14
Grade program using functions
#include <iostream>
#include <string>
struct Student {
std::string name;
int grade;
};
/*
@simoncourtenage
simoncourtenage / grade6.cpp
Created September 9, 2019 10:52
Grade program using array of structs
#include <iostream>
#include <string>
struct Student {
std::string name;
int grade;
};
int main()
@simoncourtenage
simoncourtenage / grade5array.cpp
Created September 9, 2019 10:42
Example Grade program using arrays
#include <iostream>
#include <string>
int main()
{
std::string progName = "Grade Analysis";
std::cout << "Welcome to the " << progName << " program\n"
<< "How many students to be entered (max 10)? " << std::endl;