Workshop

Workshop Slides

Workshop Documents

Debugging Kit       Link

Other Documents

Workshop Code

Exercise 1
int iterations = 10;
for(int i = 0, j = iterations / 2 - 1; i < iterations; i++, j--) 
{
    cout << i / j << endl;
}

main.cpp
#include <iostream>
#include "PhoneBook.h"
using namespace std;

int main()
{
	PhoneBook book1;
	book1.addPerson("Rufus", "951-777-7777");
	book1.addPerson("George", "909-333-9865");
	book1.addPerson("Bob", "760-321-1234");
	book1.findPerson("Bob");

	system("Pause");
	return 0;
}

PhoneBook.h
#pragma once
#include <iostream>
#include <string>
#include <vector>
#include <algorithm> // for using: find(vector.begin(), vector.end(), valueToFind) 
using namespace std;

struct Person
{
	string name;
	string phoneNumber;
};
class PhoneBook
{
public:
	PhoneBook();
	~PhoneBook();
	void addPerson(string name, string phoneNumber);
	void findPerson(string name);
private:
	vector<Person> book;
	void printPerson(Person p);
};

PhoneBook.cpp
#include "PhoneBook.h"


// Default Constructor
PhoneBook::PhoneBook()
{
}

// Default Destructor
PhoneBook::~PhoneBook()
{
}

// adds a person to the phone book
void PhoneBook::addPerson(string name, string phoneNumber)
{
	Person p;
	p.name = name;
	p.phoneNumber = phoneNumber;
	book.push_back(p);
}

// looks for and prints out a persons info from the book vector
void PhoneBook::findPerson(string name)
{
	for (int i = 0; i < book.size(); i++)
	{
		if (book[i].name == name)
		{
			printPerson(book[i]);
                        return;
		}
	}
        cout << name << " wasn't found in the phonebook!" << endl;
}

// prints out a single persons information
void PhoneBook::printPerson(Person p)
{
    cout << "Name: " << p.name << "\t Phone: " << p.phoneNumber << endl;
}