(Wikimedia commons)
Greetings, I am The Count and I need your assistance. I have been helping children learn to count for many years and I have decided to branch out into computer based counting. I need your help to write one, that's one, computer program.
I have noticed that children are getting very good at counting from one, by one, but I would like to help them get better at counting from any number to any other number, even skipping a few when required. Here is where you come in, I want you to write a program to help them check to see if they are correct when answering a counting problem, mwah ha ha haaaa!.
Your program should work as follows:
What file do you wish to open =>
Error: unable to open filename.
What file do you wish to open => bob Error: unable to open bob. What file do you wish to open =>
Easy, what everyone knows how to do! 1,5,1 Can you count down? 5,1,1 Can you skip by 2? 1,6,2 Can you skip by 2 counting down? 7,3,2 Can you count a single thing? 1,1,100000
Easy, what everyone knows how to do! 1,5,1Should produce:
Easy, what everyone knows how to do! 1, 2, 3, 4, 5
Can you count down? 5,1,1Should produce:
Can you count down? 5, 4, 3, 2, 1
Can you skip by 2? 1,6,2Should produce:
Can you skip by 2? 1, 3, 5
Can you skip by 2 counting down? 7,3,2Should produce:
Can you skip by 2 counting down? 7, 5, 3
Can you count a single thing? 1,1,100000Should produce:
Can you count a single thing? 1
What file do you wish to open => bob Error: unable to open bob. What file do you wish to open => test.data Easy, what everyone knows how to do! 1, 2, 3, 4, 5 Can you count down? 5, 4, 3, 2, 1 Can you skip by 2? 1, 3, 5 Can you skip by 2 counting down? 7, 5, 3 Can you count a single thing? 1
$ sevenCs < input.txt | diff output.txt -If there is no output, your program works correctly. If there is output, it will indicate how your program produces different output than expected.
An easier to understand version of diff employs the -y
flag.
$ sevenCs < input.txt | diff -y output.txt -In this case, the two files will be displayed side by side with the differences indicated by special symbols. An example is below
senvnCs > myOutput.txt
the output from your program will be written to myOutput.txt. Be cautioned however, you will not see ANY of the prompts, so you will need to know what to type.
a.dat | b.dat |
a b c 1 2 3 | a c 1 2 3 4 |
Each character is immediately followed by a new line | b is missing, 2 has a space after it, 3 has spaces before it. 4 is extra |
diff a.dat b.dat
produces the following output:
a a b < c c 1 1 2 | 2 3 | 3 > 4
Error: Incorrect skip factor.
wget
wget https://mirkwood.cs.edinboro.edu/~bennett/class/cmsc1240/spring2025/homework/one/test.data
.
-g -O2 -Wall -Wextra -Wpedantic -Werror -Wold-style-cast -Wunused-parameter -Wuninitialized -Wshadow -Wdangling-else