Tuesday, December 1, 2009

Lab #20

1) Make a Context free grammar, based on this web page. Use the string methods to run this CFG randomly on a start string of S.

2) Tokenize a string, and put each element into the next place in an array.

3) Count how many times a substring occurs in a larger string.

Tuesday, November 24, 2009

Lab 19

1. Make an array of strings for firstname. Make an array of strings for lastname. Read them from a file. Create a third array of strings for fullname, which is firstname followed by a space followed by a last name.

2. Do the same for C-strings.

3. Again with an array of strings, sort them in ascending order and then print them out. Then sort them in descending order and print them out.

4. The same as above, but sort them based on * string length*.

5. Bubble sort a bunch of numbers.

6. Trace through the recursively insertion sort. In the middle of lab, I will demonstrate the three types of sorts, using iteration rather than recursion. This you don't have to hand it, but it would be a good idea to try it, to make sure you really understand it.

Thursday, November 19, 2009

Lab 18

1. write a function that takes in an array and returns the avg of elements in the array.
2. Write a function that takes in an array and a number n and returns true if n occurs in the array, and false otherwise.
3. Write a function which takes in an array and prints the array in reverse order.
4. Write a function which takes in an array and a number n, and performs swaps of random elements in the array, n times.
5. Write a loop which finds the maximum element of an array.
6. Write a loop which finds the *position* of the maximum element of an array.
7. Go to Wikipedia and look up Selection sort, Insertion Sort, and Bubble. If you can, try to implement these. If not, don't sweat it.

Tuesday, November 17, 2009

Lab 17

1) modify the quiz example to get the values for the arrays from a text file.

2) Work on the array problems which Dr. Ryba gave.
http://venus.cs.qc.edu/~ryba/cs111/Array.pdf

you only need submit your answer to question 1.

Thursday, November 12, 2009

Lab 16

1. Fill a 2d array with 7s
2. Print out that 2d array, with each row on a line, elements separated by ,
3. Given matrices A and B, find C = A + B
4. Given matrices A and B, find C = A - B
5. Calculate the dot product of two 1d arrays.
6. Multiply a 2D array by a scalar
7. Perform Matrix multiplication on 2 matrices.

Tuesday, November 10, 2009

Lab assignment submission

lab 15

1) sum up an array
2) find the product of all elements in an array
3) add one vector to another, to produce a third vector
4) print out a vector
5) fill a vector with elements from the keyboard
6) calculate the standard deviation of a bunch of nums, and print out those scores which are within one standard deviation of the mean.
7) using an array, print out a number in reverse order.

Tuesday, November 3, 2009

Lab 14

1. write a recursive function that asks for numbers (ending when the user types in a -1), and will print it in reverse order.

2. Use the STL stack data type, and use it to reverse a bunch of numbers, just as above.

3. Find the sum of the numbers 1 through 10, using recursion.

4. Write exp(x, n), and returns x ^ n;

Thursday, October 29, 2009

Lab 13

1. make a recursive Fib function.
2. trace through the six recursive functions from 10/28/09

Thursday, October 22, 2009

Lab 12

trace of factors program on web site
factors program which really prints out all the factors
REPT function
trace of functions to draw diamond pattern

Tuesday, October 20, 2009

Lab 11

what operation do you want to do?
Q
+
-
*
/
loop around, and use a switch statement

Thursday, October 15, 2009

Lab 10

1) write a function which prints out all the FACTORS of a number

2) write a function which will return the SUM of its arguments

3) write a function which will return whether a number ISEVEN

4) write a function which will return whether a given year is a LEAPYEAR

5) write a function which will take in a fahrenheit number and return the celsius

6) According to Plato, the ideal age of a wife is half the age of the husband plus 7 years. write a function which will calculate this "ideal" age for the wife, given the husband's age.

Thursday, October 8, 2009

Lab 9

HW and Lab
1) Write a program which plays higher / lower with you, where you are the guesser. Use random numbers for this.
2) Write a program which plays higher / lower with you, where the computer is the guesser. Use random numbers for this.
3) Write a multi-player game of Trouble. Here is the board. Here are the rules.

include "windows.h"
SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE), 10);

Tuesday, October 6, 2009

Thursday, October 1, 2009

hw

do a trace in excel of triangle and triangle down.

Thursday, September 24, 2009

Lab 7

1) take in a number, and count how many times the number 3 occurs as a digit.

2) take in a number and reverse it, except where the digit is 3, replace it instead with the digit 5.

3) take in a number and print out all the factors of that number.

4) read in two numbers, x and y. If both x and y are odd, print "both odd." if they are both even, print "both even". if one is even and one is odd, print that.

5) read in a number and tell me whether it is in the range of 5 to 10.

Tuesday, September 22, 2009

Lab 6

1) Write a program that prompts
for firstname and lastname. The
combined name should not be longer
than 20 characters long. If it
is longer, give them a second chance.

2) Modify the above to give, instead, as many times as necessary
to fix the input. This should be a
separate program.

3) Modify the above to give three
attempts.

4) Print the first 10 numbers, together with their squares (rather than square roots).

5) Print the first 10 numbers, together with their cubes (rather than square roots).

Thursday, September 17, 2009

Quiz 1

Lab 5

If statements

1) calculate a grade. usually is average of midterm and final, but if the bribe is greater than $50, then the student gets 100.

2) make a program which asks for a password, and if the password (which is "swordfish") is correct, tell them the secret. otherwise, insult them and exit the program.

3) modify your temperature conversion program from last lab. This time, at the start, after taking in the degrees in Kelvin, ask them in what temperature they would like the result. Then, tell them what the result is in that temp scale.

4) Read through the web page here on modulo arithmetic. Write a program which will solve all the problems on that page.

Tuesday, September 15, 2009

Lab 4

1) Take in a number such as 3.14, and print out only the portion after the decimal point, e.g. 0.14.

2) Here from Wikipedia, are conversions from to various temperature scales from Kelvin. Write a program which takes in a temperature in Kelvin and converts it into each of these other temperature scales.


from Kelvin
Celsius [°C] = [K] − 273.15
Fahrenheit [°F] = [K] × 95 − 459.67
Rankine [R] = [K] × 95
Delisle [°De] = (373.15 − [K]) × 32
Newton [°N] = ([K] − 273.15) × 33100
Réaumur [°Ré] = ([K] − 273.15) × 45
Rømer [°Rø] = ([K] − 273.15) × 2140 + 7.5

Then, submit the resulting program on the form below.

Thursday, September 10, 2009

Lab 3

Three things to work on:

1) A program which gets in the speed (in mph) and time elapsed (in hours), and calculates and prints out the distance traveled.

2) A program which gets in the cost of an item as well as the percentage sales tax, and calculates and prints out the total cost of the item.

3) A program which will take in an initial deposit to a bank plus the annual effective interest rate per year, compounds that four three years, and calculates and prints out the future value of that deposit.


Tuesday, September 1, 2009

hw 1

download c++ express edition at home

take team photo, make team name
send an email with subject including
CS111 hw1
includes picture
a program which will print out Hi Josh from Team [TeamName]