Part 1: last k

Keeping track of the last k numbers entered. Sometimes computers are allowed to forget things. For example, when I access my checking account online, only the last 10 cleared checks get displayed. We'll do something along the same lines here. Write a program that gets a number k from the user, and then simply reads strings from the user. When the user types the string end, the program prints out the last k strings entered by the user (not counting end) and then exits. A run of this program might look like:
Memory size? 3
Enter strings: the world is a very big place end
Last 3 words were: very big place
Hint: Work out on paper what you'd like your array to look like at each step using the above input. Then try to write code to make it happen. Also, keep in mind that you need to know how big to make the array when you allocate space for it. You'll know how much "memory" you'll need, but no idea how many words the user will enter. Don't try to simply make a huge array - a sufficiently patient user would still type in enough words to overflow it!

Part 2: smoothing

Smoothing. Sometimes experimental data is noisey, so that you have a hard time seeing any trends. For example, plot the data in data.txt, and you'll see what I mean. In a situation like this, we might try to "average out" this noise. Instead of plotting each consecutive data value, we plot the average of each k consecutive data values. So, if our original data was:
-2  2  1  5  2  5 
... and k was 2, we'd have the "averaged" data points
0  1.5  3  3.5  3.5

Plotting these two shows what a difference the averaging makes! Write a program that reads in a number k from the user and then writes out the file that results from doing averaging on the data in data.txt using averages of k consecutive values (Think about your part 1 solution!). Assuming you saved the smoothed data in a file "smooth.txt", you can plot data.txt and smooth.txt with gnuplot. To plot the original:
gnuplot -p -e 'plot "data.txt" with lines'
To plot smooth.txt:
gnuplot -p -e 'plot "smooth.txt" with lines'

Part 3: subset sums

The program binctr.cpp reads a number n, and prints out all possible combinations of n-bits. For example:
~/$ ./binctr
Add onto binctr.cpp so that it reads in n positive numbers from the user, and prints out the sums of all possible subsets of the numbers entered by the user. For example:
~/$ ./part3
3 4 9
000 : 0 + 0 + 0 = 0
100 : 3 + 0 + 0 = 3
010 : 0 + 4 + 0 = 4
110 : 3 + 4 + 0 = 7
001 : 0 + 0 + 9 = 9
101 : 3 + 0 + 9 = 12
011 : 0 + 4 + 9 = 13
111 : 3 + 4 + 9 = 16
Hint: treat the array of booleans created by binctr.cpp as a "mask", i.e. as describing which of the user-inputted numbers are in the current subset, and which are out.

Part 4: Going further - Cars

Write a program that reads in data like this, cars.txt, and then answers user queries like this:
~/$ ./cars

: color = white

mdx	focus	prius	911	
acura	ford	toyota	porsche	
white	white	white	white	
suv	sedan	sedan	sporty	
40000	19000	22000	65000	

: price < 25000

focus	focus	focus	prius	
ford	ford	ford	toyota	
blue	white	red	white	
sedan	sedan	sedan	sedan	
18000	19000	17500	22000	

: type = sporty

mini	mini	corvette	911	
bmw	mbw	chevy	porsche	
black	blue	red	white	
sporty	sporty	sporty	sporty	
25000	26000	46000	65000	

: quit
Note: your solution should work even if more cars, and more makes, models, colors, types and prices are added to the file cars.txt.