Xcode 6 and SWIFT

dasdas-copy2

From the 2014 WWDC

Apple unveiled the new programming language that it wants developers to use in making iOS and OSX apps this week. This sent me scrambling to a place where I could download large files for free (not my house) to get the new version of XCode so I could try it out. I also liked the idea of starting on the ground floor with every other developer on the day it was released.

About 24 hours later, I finally have the new XCode beta downloaded and installed on my computer (storage space on my MacBook Air is always at a premium). I have not yet been able to install the new iOS on my phone because I simply have too many pictures cluttering up the storage space there too – I’ll deal with that later, when I can hook up to my external drive – and I have not been able to download Yosemite yet for some other reason. I know this isn’t the storage problem – at least not yet. But I still haven’t worked out the kinks on that one.

So… what can we expect from this new SWIFT / XCode combination? One thing that I’m certain a lot of people have been looking forward to, is a more integrated coding space. Bret Victor gave a talk at the 2012 CUSEC (Canadian University Software Engineering Conference) presenting this idea in a pretty solid demo that illustrated everything from side-by-side coding and output for graphics and even a simple sorting loop. In both examples, we see how easily this kind of work environment leads to debugging before you are even finished typing in the buggy line of code.

I was going to clip a section of the talk to show the moments where Bret really nailed his idea, but the whole talk is just so remarkable, I suggest you watch it all – if you haven’t already. And if you have, watch it again. It’s that good.

Back to today…

Does this mean that I’ve been cranking out new Swift code all day? No. Sadly.

There’s a couple (maybe three) roadblocks in place for me before I can do that.

  1. Even though I have XCode up and running, I can’t figure out how to start playing with Swift in the playground.
  2. I have studying for that Chemistry content exam I need to take.
  3. I keep getting distracted by writing posts for my blogs.

That said. I’m back to it. By the way, I really have to hand it to KhanAcademy. It’s made studying a much more engaging pursuit. I highly recommend this site for any student in a class covered by his material.

Here’s a clip of video from the Swift announcement at WWDC. Compare it to what you just saw from Ken Victor.

Advertisements

Wow, Finally smoothed out that clown problem

ImageThis version of the clown application uses a vector (clown car) to handle the objects (clowns).

Each clown has a Name, and ID number, hit points(hps), and three attacks. The way this program works is that it seeds the vector with the clown objects at the beginning (this was part of the vector handling problem), then allows them to fight it out in the clown car – every time a clown’s hps falls to zero, the clown is dead and if thrown from the car (i.e., they no longer populate the vector. This proceeds until only one clown remains. The last clown standing is declared the winner.

As the battle occurs, cout statements indicate who attacks whom and what damage is inflicted. (note: every attack is a ‘hit’). If a clown is killed, this is also announced and then the vector is printed out to show what clowns remain in the car.

I believe there are no bugs remaining in this program. When I was working on it, I included a large number of debugging statements. These have been removed for clarity in the final product. I also removed the dialog asking what clown to eject – and removed the function that handled that query.

Code:

//

//  main.cpp

//  clowncar

//

//  Created by Jack on 5/4/14.

//

#include <iostream>

#include <vector>

#include <time.h>

#include <stdio.h>

#include <stdlib.h>

#include <cstdlib>

#include <ctime>

usingnamespacestd;

using std::vector;

class IdNumbers{     // a place to store a counter for creating idNumbers

public:

    IdNumbers(){

    }

static int getANewNumber(){

counter++;

return counter;

    }

protected:

static int counter;

}; //end IdNumbers

class Clown{   // the clown objects

public:

    Clown(){};

    ~Clown(){};

    Clown(int clownId){

idNum = clownId;

    };

    Clown(string nameOfClown, IdNumbers theNumber, string attackIn1, int attackIn1Damage, string attackIn2, int attackIn2Damage, string attackIn3, int attackIn3Damage ){

clownName = nameOfClown;

idNum = theNumber.getANewNumber();

attack1 = attackIn1;

attack2 = attackIn2;

attack3 = attackIn3;

attack1Damage = attackIn1Damage;

attack2Damage = attackIn2Damage;

attack3Damage = attackIn3Damage;

hitPoints = 100;

dead = false;

    };

int getClownId(void){

return idNum;

    }

string getName(void){

return clownName;

    }

void printClown(void){

cout<<“idNumber = “<<idNum<<endl;

cout<<“name = “<<clownName<<endl;

    };

void printClown2(void){

        cout<<“Clown idNumber = “<<idNum<<“, name = “<<clownName<<endl;

    };

void printClown3(void){

        cout<<“Clown Name = “<<clownName<<“, hp = “<<hitPoints<<endl;

    };

int getNumAttacks(void){

return numAttacks;

    };

string getAttack1(){

return attack1;

    };

string getAttack2(){

return attack2;

    };

string getAttack3(){

return attack3;

    };

int getDamage1(){

        returnattack1Damage;

    };

int getDamage2(){

        returnattack2Damage;

    };

int getDamage3(){

        returnattack3Damage;

    };

int getHP(){

return hitPoints;

    };

void setHP(int damage){

this->hitPoints = this->hitPoints – damage;

if (hitPoints <= 0){

dead = true;

        }

    }

bool getDead(){

return dead;

    }

private:

string clownName;

int idNum;

int numAttacks = 3;

string attack1;

int attack1Damage;

string attack2;

int attack2Damage;

string attack3;

int attack3Damage;

int hitPoints;

bool dead;

};    //end clown

//functions

void printVectorContents(vector<Clown> &);

void printVectorContents2(vector<Clown> &);

void askWhoToPop(vector<Clown> &);

void popClown(vector<Clown> &, int);

void popThisClown(vector<Clown> &car, int popWho);

void directFight(vector<Clown> &car);

int IdNumbers ::counter = 0;

//*********************************************************************************************

int main(int argc, const char * argv[])

{

IdNumbers theCounter;

    srand (time(NULL));                     //<—–should seed random numbers appropriately…

    vector<Clown> clowncar;     //sets up a vector for fish

int vectorSize = 0;

    vectorSize = clowncar.size(); //get array size

Clown pennywise(“Pennywise”, theCounter, “bite”, 30, “claw”, 20, “defenestrate”, 1000);

    clowncar.push_back(pennywise);

    Clown jwgacy(“John Wayne Gacy”, theCounter, “creep out”, 30, “molest”, 50, “defenestrate”, 1000);

    clowncar.push_back(jwgacy);

    vectorSize = clowncar.size(); //get array size

    Clown bozo(“Bozo”, theCounter, “nose honk”, 5, “flower squirt”, 10, “defenestrate”, 1000);

    clowncar.push_back(bozo);

    Clown krusty(“Krusty”, theCounter, “tease”, 15, “step on foot”, 20, “defenestrate”, 1000);

    clowncar.push_back(krusty);

    vectorSize = clowncar.size(); //get array size

    Clown ronald(“Ronald McDonald”, theCounter, “smile”, 30, “arterie clog”, 30, “defenestrate”, 1000);

    clowncar.push_back(ronald);

    vectorSize = clowncar.size(); //get array size

    cout<<“**************”<<endl;

    cout<<“**********”<<endl;

    clowncar.shrink_to_fit();

    printVectorContents2(clowncar);

directFight(clowncar);

return 0;

}

//****************************************************************************

//Non-Member functions

void printVectorContents(vector<Clown> &car){

for(int i=0; i < car.size(); i++){

        car[i].printClown();

    }

}

void printVectorContents2(vector<Clown> &car){

for(int i=0; i < car.size(); i++){

        car[i].printClown2();

    }

}

void printVectorContents3(vector<Clown> &car){

for(int i=0; i < car.size(); i++){

        car[i].printClown3();

    }

}

void popThisClown(vector<Clown> &car, int popWho){   //how to selectively delete from a vector????

for (int j = 0; j < car.size(); j++)

    {

if(car[j].getClownId() == popWho)

        {

            car.erase (car.begin()+j);

        }

    }// end for

};

void directFight(vector<Clown> &car){      //handles the fighting

bool victor = false;

bool targetIdentified = false;

string winner;

int attackerArrayPosition;

int targetArrayPosition;

int targetID;

int attackerID;

string attackerName;

string targetName;

int attackNum;

string attackType;

int attackDamage;

while (victor == false){

for (int attackerArrayPosition=0;attackerArrayPosition<car.size();attackerArrayPosition++){                             //scrolls through attackers

if(car.size() == 1){

                victor = true;

                winner = car[0].getName();

cout<<“Winner is “<<winner<<endl;

exit(0);

            }

            attackerName = car[attackerArrayPosition].getName();

            attackerID = car[attackerArrayPosition].getClownId();

            targetArrayPosition = rand()%car.size();               // gets an array position

            targetID = car[targetArrayPosition].getClownId();      //translates array position into clown ID number

            targetName = car[targetArrayPosition].getName();

while (targetIdentified == false){

if (targetID == attackerID){

                    targetIdentified = false;

                    targetArrayPosition = rand()%car.size();

                    targetID = car[targetArrayPosition].getClownId();

                }

else if (targetID != attackerID){

                    targetIdentified = true;

for(int i=0;i<car.size();i++){

if (targetID == car[i].getClownId()){

                            targetName = car[i].getName();

                        }

                    }

break;

                }

else{

                    cout<<“this isn’t supposed to happen. AttackerID is “<<attackerArrayPosition<<” target ID is “<<targetID<<endl;

                }

            }

        attackNum = rand()%3 + 1;    //choose attack (gets a random number)

switch ( attackNum ) {

case 1 :

                    attackType = car[attackerArrayPosition].getAttack1();

break;

case 2 :

                    attackType = car[attackerArrayPosition].getAttack2();

break;

case 3 :

                    attackType = car[attackerArrayPosition].getAttack3();

break;

default :

                    cout<<“error in attackNum switch statement”<<endl;

            } //end attackNum Switch

switch ( attackNum ) {

case 1 :

                    attackDamage = car[attackerArrayPosition].getDamage1();

break;

case 2 :

                    attackDamage = car[attackerArrayPosition].getDamage2();

break;

case 3 :

                    attackDamage =  car[attackerArrayPosition].getDamage3();

break;

default :

                    cout<<“error in attackNum switch statement”<<endl;

            }

cout<<attackerName<<” attacks “<<targetName<<” with “<<attackType<<” attack for “<<attackDamage<<” damage.”<<endl;

            //report attacker, attack, target AND score damage

                        car[targetArrayPosition].setHP(attackDamage);       //call to adjust hps according to damage

if (car[targetArrayPosition].getDead() == true){    //thrown dead from the car

cout<<car[targetArrayPosition].getName()<<” is dead.”<<endl;

                            cout<<“<<<<<<<<<<<<<+++++++++>>>>>>>>>>>>>>>>>>>”<<endl;

popThisClown(car, targetID);

                            car.shrink_to_fit();

                            targetIdentified = false;   //reset for next round

break;

                        }

else{

                            cout<<“<<<<<<<<<<<<<>>>>>>>>>>>>>>>>>>>”<<endl;

                            targetIdentified = false;   //reset for next round

printVectorContents3(car);

                        }

            cout<<“<<<<<<<<<*************>>>>>>>>>>>>>”<<endl;

if(car.size() == 1){

                victor = true;

                winner = car[0].getName();

            }

    }

         printVectorContents3(car);

    }

cout<<“Winner is “<<winner<<endl;

};

output:

**************

**********

Clown idNumber = 1, name = Pennywise

Clown idNumber = 2, name = John Wayne Gacy

Clown idNumber = 3, name = Bozo

Clown idNumber = 4, name = Krusty

Clown idNumber = 5, name = Ronald McDonald

Pennywise attacks Bozo with bite attack for 30 damage.

<<<<<<<<<<<<<>>>>>>>>>>>>>>>>>>>

Clown Name = Pennywise, hp = 100

Clown Name = John Wayne Gacy, hp = 100

Clown Name = Bozo, hp = 70

Clown Name = Krusty, hp = 100

Clown Name = Ronald McDonald, hp = 100

<<<<<<<<<*************>>>>>>>>>>>>>

John Wayne Gacy attacks Krusty with defenestrate attack for 1000 damage.

Krusty is dead.

<<<<<<<<<<<<<+++++++++>>>>>>>>>>>>>>>>>>>

Clown Name = Pennywise, hp = 100

Clown Name = John Wayne Gacy, hp = 100

Clown Name = Bozo, hp = 70

Clown Name = Ronald McDonald, hp = 100

Pennywise attacks John Wayne Gacy with bite attack for 30 damage.

<<<<<<<<<<<<<>>>>>>>>>>>>>>>>>>>

Clown Name = Pennywise, hp = 100

Clown Name = John Wayne Gacy, hp = 70

Clown Name = Bozo, hp = 70

Clown Name = Ronald McDonald, hp = 100

<<<<<<<<<*************>>>>>>>>>>>>>

John Wayne Gacy attacks Pennywise with molest attack for 50 damage.

<<<<<<<<<<<<<>>>>>>>>>>>>>>>>>>>

Clown Name = Pennywise, hp = 50

Clown Name = John Wayne Gacy, hp = 70

Clown Name = Bozo, hp = 70

Clown Name = Ronald McDonald, hp = 100

<<<<<<<<<*************>>>>>>>>>>>>>

Bozo attacks Pennywise with nose honk attack for 5 damage.

<<<<<<<<<<<<<>>>>>>>>>>>>>>>>>>>

Clown Name = Pennywise, hp = 45

Clown Name = John Wayne Gacy, hp = 70

Clown Name = Bozo, hp = 70

Clown Name = Ronald McDonald, hp = 100

<<<<<<<<<*************>>>>>>>>>>>>>

Ronald McDonald attacks Bozo with defenestrate attack for 1000 damage.

Bozo is dead.

<<<<<<<<<<<<<+++++++++>>>>>>>>>>>>>>>>>>>

Clown Name = Pennywise, hp = 45

Clown Name = John Wayne Gacy, hp = 70

Clown Name = Ronald McDonald, hp = 100

Pennywise attacks John Wayne Gacy with defenestrate attack for 1000 damage.

John Wayne Gacy is dead.

<<<<<<<<<<<<<+++++++++>>>>>>>>>>>>>>>>>>>

Clown Name = Pennywise, hp = 45

Clown Name = Ronald McDonald, hp = 100

Pennywise attacks Ronald McDonald with bite attack for 30 damage.

<<<<<<<<<<<<<>>>>>>>>>>>>>>>>>>>

Clown Name = Pennywise, hp = 45

Clown Name = Ronald McDonald, hp = 70

<<<<<<<<<*************>>>>>>>>>>>>>

Ronald McDonald attacks Pennywise with smile attack for 30 damage.

<<<<<<<<<<<<<>>>>>>>>>>>>>>>>>>>

Clown Name = Pennywise, hp = 15

Clown Name = Ronald McDonald, hp = 70

<<<<<<<<<*************>>>>>>>>>>>>>

Clown Name = Pennywise, hp = 15

Clown Name = Ronald McDonald, hp = 70

Pennywise attacks Ronald McDonald with defenestrate attack for 1000 damage.

Ronald McDonald is dead.

<<<<<<<<<<<<<+++++++++>>>>>>>>>>>>>>>>>>>

Clown Name = Pennywise, hp = 15

Winner is Pennywise

Program ended with exit code: 0

 

Collaborative Coding

Bridging the chasm between sandbox problems and real collaborative project-based learning.

collabCodingPage

A debt of gratitude

Thank you very much to CTphpnwb on </ dream.in.code> for helping me to gain a better understanding of how to work with references – and why this is important.

The basic problem I was facing was that I was passing the whole factor of objects into my functions. When you do this, it actually creates a copy of the vector and manipulates that. What I wanted to have happen was to pass a reference to my vector (i.e. the vector’s address in the computer) so that no copy was made, and all changes were done to the original vector.

I’ve tried playing with shrink_to_fit, but I think I may be exploring territory that isn’t going to actually help me at this point.

the successful code:

//

//  main.cpp

//  clowncar

//

//  Created by Jack on 5/4/14.

//  Copyright (c) 2014 Jack Treml. All rights reserved.

//

 

 

 

/*

 1. empty car (0)

 2. pick up Pennywise and John Wayne Gacy (2)

 3. Pick up Bozo and Krusty (4)

 4. Pick up Ronald McDonald (5)

 5. print out list of clowns

 6. As for a name of a clown (or ID number) to kick out of the car

 7. Kick only that individual out, then re-print list

 */

 

#include <iostream>

#include <vector>

usingnamespacestd;

using std::vector;

 

class IdNumbers{     // a place to store a counter for creating idNumbers

public:

    IdNumbers(){

    }

static int getANewNumber(){

counter++;

return counter;

    }

protected:

static int counter;

};

 

class Clown{   // the clown objects

public:

    Clown(){};

    ~Clown(){};

    Clown(int clownId){

idNum = clownId;

    };

    Clown(string nameOfClown, IdNumbers theNumber){

clownName = nameOfClown;

idNum = theNumber.getANewNumber();

    };

int getClownId(void){

return idNum;

    }

void printClown(void){

cout<<“idNumber = “<<idNum<<endl;

cout<<“name = “<<clownName<<endl;

    };

void printClown2(void){

        cout<<“Clown idNumber = “<<idNum<<“, name = “<<clownName<<endl;

    };

private:

string clownName;

int idNum;

};

 

//functions

void printVectorContents(vector<Clown> &);

void printVectorContents2(vector<Clown> &);

void askWhoToPop(vector<Clown> &);

void popClown(vector<Clown> &, int);

void popThisClown(vector<Clown> &car, int popWho);

 

int IdNumbers ::counter = 0;

 

int main(int argc, const char * argv[])

{

IdNumbers theCounter;

    vector<Clown> clowncar;     //sets up a vector for fish

int vectorSize = 0;

    vectorSize = clowncar.size(); //get array size

    cout<<“**************”<<endl;

cout<<“vector is size: “<<vectorSize<<endl;

Clown pennywise(“Pennywise”, theCounter);

    clowncar.push_back(pennywise);

Clown jwgacy(“John Wayne Gacy”, theCounter);

    clowncar.push_back(jwgacy);

    vectorSize = clowncar.size(); //get array size

    cout<<“**************”<<endl;

cout<<“vector is size: “<<vectorSize<<endl;

    //printVectorContents(clowncar);

    printVectorContents2(clowncar);

Clown bozo(“Bozo”, theCounter);

    clowncar.push_back(bozo);

Clown krusty(“Krusty”, theCounter);

    clowncar.push_back(krusty);

    vectorSize = clowncar.size(); //get array size

    cout<<“**************”<<endl;

cout<<“vector is size: “<<vectorSize<<endl;

    //printVectorContents(clowncar);

    printVectorContents2(clowncar);

Clown ronald(“Ronald McDonald”, theCounter);

    clowncar.push_back(ronald);

    vectorSize = clowncar.size(); //get array size

    cout<<“**************”<<endl;

    cout<<“current capacity is: “<<clowncar.capacity()<<endl;

cout<<“vector is size: “<<vectorSize<<endl;

    //printVectorContents(clowncar);

    //list clowns with ID numbers

    printVectorContents2(clowncar);

    //ask for an ID number of a clown to evict

askWhoToPop(clowncar);

    cout<<“**********”<<endl;

    clowncar.shrink_to_fit();

    cout<<“current capacity is: “<<clowncar.capacity()<<endl;

cout<<“vector is size: “<<vectorSize<<endl;

    printVectorContents2(clowncar);

return 0;

}

 

 

//Non-Member functions

void printVectorContents(vector<Clown> &car){

for(int i=0; i < car.size(); i++){

        car[i].printClown();

    }

}

 

void printVectorContents2(vector<Clown> &car){

for(int i=0; i < car.size(); i++){

        car[i].printClown2();

    }

}

 

void askWhoToPop(vector<Clown> &car){

int popWho;

    cout<<“Please enter an ID number of a clown to kick out of the car: “;

cin>>popWho;

popThisClown(car, popWho);

cout<<endl;

}

 

void popThisClown(vector<Clown> &car, int popWho){   //how to selectively delete from a vector????

for (int j = 0; j < car.size(); j++)

    {

        cout<<“is “<<j<<” the right guy to bump?”<<endl;

if(car[j].getClownId() == popWho)

        {

            cout<<“yeah, I’m here lookin’ at erasing clown “<<j<<endl;

            //car.erase(j);   //tried this – didn’t work

            car.erase (car.begin()+j);

        }

    }// end for

};

 

output:

**************

vector is size: 0

**************

vector is size: 2

Clown idNumber = 1, name = Pennywise

Clown idNumber = 2, name = John Wayne Gacy

**************

vector is size: 4

Clown idNumber = 1, name = Pennywise

Clown idNumber = 2, name = John Wayne Gacy

Clown idNumber = 3, name = Bozo

Clown idNumber = 4, name = Krusty

**************

current capacity is: 8

vector is size: 5

Clown idNumber = 1, name = Pennywise

Clown idNumber = 2, name = John Wayne Gacy

Clown idNumber = 3, name = Bozo

Clown idNumber = 4, name = Krusty

Clown idNumber = 5, name = Ronald McDonald

Please enter an ID number of a clown to kick out of the car: 3

is 0 the right guy to bump?

is 1 the right guy to bump?

is 2 the right guy to bump?

yeah, I’m here lookin’ at erasing clown 2

is 3 the right guy to bump?

 

**********

current capacity is: 4

vector is size: 5

Clown idNumber = 1, name = Pennywise

Clown idNumber = 2, name = John Wayne Gacy

Clown idNumber = 4, name = Krusty

Clown idNumber = 5, name = Ronald McDonald

Program ended with exit code: 0

clowncar vector solution

Amazingly, this solution came fast an easily:

//

//  main.cpp

//  clowncar

//

//  Created by Jack on 5/4/14.

//

 

/*

 1. empty car (0)

 2. pick up Pennywise and John Wayne Gacy (2)

 3. Pick up Bozo and Krusty (4) 

 4. Pick up Ronald McDonald (5)

 5. Ronald McDonald gets kicked out (4)

 6. All the rest stop for a drink at the Alehouse together (0)

 */

 

#include <iostream>

#include <vector>

usingnamespacestd;

using std::vector;

 

//functions

void printVectorContents(vector<string>);

 

int main(int argc, const char * argv[])

{

    vector<string> clowncar;     //sets up a vector for fish

    int vectorSize = 0;

    vectorSize = clowncar.size(); //get array size

    cout<<“vector is size: “<<vectorSize<<endl;

    clowncar.push_back(“Pennywise”);

    clowncar.push_back(“John Wayne Gacy”);

    vectorSize = clowncar.size(); //get array size

    cout<<“vector is size: “<<vectorSize<<endl;

    printVectorContents(clowncar);

    

    clowncar.push_back(“Bozo”);

    clowncar.push_back(“Krusty”);

    vectorSize = clowncar.size(); //get array size

    cout<<“vector is size: “<<vectorSize<<endl;

    printVectorContents(clowncar);

    

    clowncar.push_back(“Ronald McDonald”);

    vectorSize = clowncar.size(); //get array size

    cout<<“vector is size: “<<vectorSize<<endl;

    printVectorContents(clowncar);

    

    clowncar.pop_back();

    vectorSize = clowncar.size(); //get array size

    cout<<“vector is size: “<<vectorSize<<endl;

    printVectorContents(clowncar);

    

    while(clowncar.size() > 0){

        clowncar.pop_back();

    }

    vectorSize = clowncar.size(); //get array size

    cout<<“vector is size: “<<vectorSize<<endl;

    printVectorContents(clowncar);

 

    return 0;

}

 

 

//functions

void printVectorContents(vector<string> car){

    for(int i=0; i < car.size(); i++){

        cout<<“clown #”<<i<<“: “<<car[i]<<endl;

    }

}

 

 

/*  output – surprisingly, this worked right first try.

    the timing of the cout statements for vector size is a bit kooky, but it’s working the way I wanted

 

 vector is size: 0

 vector is size: 2

 clown #0: Pennywise

 clown #1: John Wayne Gacy

 vector is size: 4

 clown #0: Pennywise

 clown #1: John Wayne Gacy

 clown #2: Bozo

 clown #3: Krusty

 vector is size: 5

 clown #0: Pennywise

 clown #1: John Wayne Gacy

 clown #2: Bozo

 clown #3: Krusty

 clown #4: Ronald McDonald

 vector is size: 4

 clown #0: Pennywise

 clown #1: John Wayne Gacy

 clown #2: Bozo

 clown #3: Krusty

 vector is size: 0

 Program ended with exit code: 0

 

*/

Some Concepts Trip me Up: C++ vector of objects

ImageI’m struggling with a new element of code: vectors. I’ve known about them for some time as people keep suggesting that I use them rather than arrays. One benefit is that vectors are supposed to be more flexible in their size, i.e. you can shrink or expand them as needed while the program is running.

Nevertheless, I am having a terrible time getting my head around these things.

ImageI thought this might be a good place to work out the kinks with some stepwise coding examples (as I learn them myself). As an example, I would like to figure out how to use vectors to handle two problems. The first, simpler, problem is to have a vector of people (i.e. strings) (let’s make them clowns) that we want to stuff into a car and then let them out again, each time resizing the vector and outputting the size of the vector as well as the names of the clowns in the car.

1. empty car (0)

2. pick up Pennywise and John Wayne Gacy (2)

3. Pick up Bozo and Krusty (4)

4. Pick up Ronald McDonald (5)

5. Ronald McDonald gets kicked out (4)

6. All the rest stop for a drink at the Alehouse together (0)

 

As a second example:

Same idea, but this time the vector holds objects (we’ll make them students: each has a string: name and int: grade). Everything else is the same as above

1. empty car (0)

2. pick up Pennywise,98 and John Wayne Gacy,47 (2)

3. Pick up Bozo,78 and Krusty,59 (4)

4. Pick up Ronald McDonald,17 (5)

5. Ronald McDonald gets kicked out (4)

6. All the rest stop for a drink at the Alehouse together (0)

I’m going to work this out myself now, but any input is greatly appreciated.

day 1… in like a lamb

I reserved this space in August and haven’t done anything with it because I didn’t want to dilute any readership that I had with my main blog, downhousesoftware.wordpress.com. Nevertheless, I keep thinking about launching it anyway to keep a record of the work I’ve been doing (that sounds like I’ve gotten a lot done, but it’s mostly just finding my bearings).

Right now I have a semester and change of C++ under my belt, with a lot of outside projects to boot and I’ve recently started up a coding club for the little town of Paola, where I live. Although we only have a few members, I’m happy it’s up and going and I think we can all learn a lot from it given some time and the right projects.

Given all that, let’s call today day 1.

Please let me know if you’re interested in learning some coding too and would like to join me in tackling some simple problems – I think it would be a great experience learning to share files online and see more than just what’s above the surface.