Monday, May 17, 2010

1) what include file do I need?
2) what data types are available
3) how do i declare?
4) how do i use

1)
#include // for cin and cout
#include // for file io

2)
ifstream
ofstream

these are data types, just like int, double, string

3)
ifstream jin;
ofstream jout;

alternatively:
ifstream jin("hello.txt");
ofstream jout("myoutput.txt");

4)
open a file:
jin.open("hello.txt");
jout.open("myoutput.txt");

close a file:
jin.close();
jout.close();

read from a file:
int x;
jin >> x;

write to a file:
jout << x << "hello" << endl;

Wednesday, May 12, 2010

What you should perhaps be able to do, come CS211

http://venus.cs.qc.cuny.edu/~alayev
http://venus.cs.qc.cuny.edu/~waxman/211


Lab 1:
Make teams of 3 people.
Come up with a cool name.
Register your team name together with list of members.
We will learn how to log in to the computers, how to run Visual Studio. Submit with this first project digital photos of your team members so that I can keep track of you. Submission will be by making a Google Document, and sharing it with me. If you do not finish in lab, you can finish it for homework.
http://venus.cs.qc.edu/~joshwaxman/Spring2009/cs211
Project 1:
Do things with one-dimensional arrays -- the arrays you know and love. Namely, do the following, in separate programs:
a) Set all the elements of the array to the value 5.
b) Print out all the values of the array, separated by the comma character. There should not be a trailing comma character.
c) Create a string containing all the elements of the array, separated by the comma character.
d) Find the product of all the elements in the array.
e) Find the sum of all elements in the array.
f) Find the minimum value in the array.
g) Find the maximum value in the array.
h) Find the position of the minimum element in the array.
i) Here is a Wikipedia page which has pseudocode for the merge algorithm, which will merge two sorted arrays into a third sorted array.
http://en.wikipedia.org/wiki/Merge_algorithm
Implement it in C++.
j) Fill two arrays (A and B) with items typed in from the keyboard, add up the elements in each position, and store the result in the corresponding spot in array C. Thus, C[6] would contain A[6] + B[6].
k) Read in a bunch of numbers into an array from a file, and then Bubble-sort them.
http://en.wikipedia.org/wiki/Bubble_sort
l) Now that you can find the position of the minimum element in an array (see h), implement the Selection sort:
http://en.wikipedia.org/wiki/Selection_sort
m) Write some code which will reverse an array.
o) Write some code which will read a file containing integers in the range of 0 to 100, and then output the frequency of each element in the file.
p) Write a recursive function which will print out every element in an array. It should take in the array, the position to print out, and the capacity.
(optional q) There is a programming language known as C# (pronounced see-sharp), which is quite similar to C++. Teach yourself some C#, and implement items (a) through (p) in C#.
r) Read up about the goto statement, and write a program which will print "this program is making me dizzy" forever.

Monday, May 3, 2010

Lab and hw #19

1) Implement a Bubble sort
2) Implement a Selection sort
3) Implement a non-recursive Insertion sort