Homework 2, Count von Count's Clever Counting Challenge and Coding Conundrum.

Short Description:

Write a program to demonstrate your ability to count using a programming language.

Goals

When you finish this homework, you should have:

Formal Description

(With admiration, credit, and apologies to CTW).

Picture of the Count from Sesame Street (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:

  1. Ask the user for a file name
    1. Please use the prompt on a single line, with no newline.
      • What file do you wish to open => 
      • Note this does not have a new line at the end.
      • And has space after the >
    2. read in the user response and print a newline.
      • This will look like two blank lines, but in the output file it will be only one.
    3. If your program is able to open the named file move to the next step.
    4. If you are unable to open the file, print the error message below and ask again until you are able to open a file.
      • Error: unable to open filename.
      • This should start with a tab.
      • This should end with a newline
      • filename should be replaced with the name of the file.
      • This should have a blank line printed after it.
      • For example:
        
        What file do you wish to open => bob
        
            Error: unable to open bob.
        
        What file do you wish to open => 
  2. The file contains zero or more problems, each problem is represented by:
  3. For each problem in the file
  4. The final output for the given test file should be as follows. (user responses in bold).
    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

Testing

  1. input.txt
  2. output.txt
  3. test.data
Your program should follow the input/output specifications exactly. This includes spaces and newlines. To assist you in testing this, I have provided an input, interaction, and output file. You can test your program with these files on the linux server. Assuming your program in called sevenCs and you have downloaded input.txt , output.txt and test.data into your working directory, issue the following command:
$ 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

Notes:

  1. The skip factor must be an integer greater than 0. If the skip factor is not report the following error:
  2. The file is in unix format, meaning that lines end with a newline, but not a carriage return.
  3. The program should end by printing a single blank line.
  4. All numbers input will be integers.
  5. Downloading the test cases can be tricky.
  6. For the purposes of testing, you should not have a file named bob in your folder.
  7. Your code must compile, without warnings or errors, with the following compiler flags:

Required Files

A single c++ source code file.

Submission

Submit the assignment to the D2L folder Homework 2 by the due date.