Monday, May 17, 2010

Review sheets for final

Here:
http://docs.google.com/View?id=ajbqhgmq9qdz_93fk5f2p46

and here:
http://docs.google.com/View?id=ajbqhgmq9qdz_94j9pg3jg2
with answers to the second document here:
http://docs.google.com/View?id=ajbqhgmq9qdz_95fjsg5ccv

Wednesday, April 14, 2010

reversing a number, using recursion

#include "stdafx.h"
#include
#include
#include
using namespace std;

int rev(int n)
{
    char buf[100];
    sprintf(buf, "%d", n);
    int lastdigits = atoi(buf+1);
    int firstdigit = buf[0]-'0';
    if (n < 10) return n;
    return firstdigit + 10 * rev(lastdigits);
}

int main()
{
    cout << rev(123) << endl;
    return 0;
}

Wednesday, April 7, 2010

Alex review sheet

http://venus.cs.qc.edu/%7Elool8078/211Review.doc

Wednesday, March 24, 2010

Wednesday, March 17, 2010

lab assignment:
research (Google) printf and scanf, and how you would use & in the context of scanf. write a simple program that uses each of these, to print and read an int, a double, and a C string (array of characters)

implement conway's game of life:

start out with initial board setup
int current_generation[20][20];
int next_generation[20][20];

// set up the first configuaration (read from a file)
while(true)
{
    // apply 4 rules to fill in next_generation,
    // based on current_generation

//   1. Any live cell with fewer than two live neighbours dies, as if caused by underpopulation.
//   2. Any live cell with more than three live neighbours dies, as if by overcrowding.
//   3. Any live cell with two or three live neighbours lives on to the next generation.
//   4. Any dead cell with exactly three live neighbours becomes a live cell.

    // make current_generation the same as next_generation
    // copy the contents of next_gen into curr_gen
    for (i = 0; i < 20; i++)
        for (j = 0 ; i < 20; j++)
            A[i][j] = B[i][j];

    // print to screen or the board the contents of cur_gen

}

Monday, February 22, 2010

lab 3, together with homework at the bottom

void swap(int &a, int &b)
{
int t = a;
a = b;
b = t;
}

void bubblesort(int a[][10], int col)
{
for (int n = 0; n < 10; n++)
{
for (int i = 0; i < 9; i++)
if (a[i][col] > a[i+1][col])
swap(a[i][col], a[i+1][col]);
}
}


int a[10][10];
for (int i = 0; i < 10; i++)
for (int j = 0; j < 10; j++)
cin >> a[i][j];

for (i = 0; i < 10; i++)
bubblesort(a, i);


for (i = 0; i < 10; i++, cout << endl)
for (int j = 0; j < 10; j++)
cout << a[i][j];
cin >> num;
t = num;
char picture[9][5];
for (int i = 0; i < 9; i++)
for (int j = 0; j < 5; j++)
picture[i][j] = ' ';

for (i = 0; i < 5; i++)
{
int digit = num % 10;
num /= 10;
draw(picture, digit, 5 - i);
}


for (int i = 0; i < 9; i++, cout << endl)
for (int j = 0; j < 5; j++)
cout << picture[i][j];


HW: read up on templatized functions
write a templatized bubblesort and selection sort
http://www.cplusplus.com/doc/tutorial/templates/

Thursday, February 18, 2010

assignment:
implement 2 different DFSAs
first using gotos
then using 2d array for state transition table