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 placeHint: 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!
Sample Run Input File Rendered Output (or view table.html) What is the input file: table.txt What is the output file: table.html 5 by 4 Singles Doubles Triples HRs Ames 6 2 0 1 Jones 4 1 1 0 Morris 3 0 0 4 Smith 6 4 0 0 Zoolander 0 0 0 0
Ames Jones Morris Smith Zoolander Singles 6 4 3 6 0 Doubles 2 1 0 4 0 Triples 0 1 0 0 0 HRs 1 0 4 0 0
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!). Import the original file
and the "averaged" file into Excel to see how the plots
compare. (Hint: use the Line
chart type.)