Homework 3: Count the Digits

Please review the rules on collaboration for homework for this course, as well as the guidelines for turning in work.

This assignment is designed to give you practice with reading input from the keyboard and using arrays. This program will calculate the frequency of each digit between 0 and 9 that is found in a message read from the keyboard, display the frequency for each digit and note which digit appeared most often.

Your program should read in a string of characters (consisting of both letters and digits) from the keyboard. You may assume that the input will consist of at least one character but be no longer than 100 characters. So, assuming x is the number of characters in the message, you can assume that 1 <= x <= 100. Assume that there will not be any spaces or control characters in the message.

Your program should examine each character in the message, and if it is a digit, it should increase the frequency of that digit by one.

See the "Grading" section below for specific criteria for this assignment. As with all homework, the style guidelines apply to this assignment, and points may be deducted for poor style, readability, and testing.

Learning outcomes

Upon completion of this assignment, students will demonstrate understanding of the following learning outcomes:

1. In the context of low-level, systems programming: 2. Architect and analyze stateful programs: 3.Productively develop software within a Unix-style command-line interface (CLI): 8. Author small, memory-safe programs that interact with the world:

The Task

Your program should follow these requirements:

  1. Read in the message from the keyboard. It will be at least one character and less than 100. You should read until a newline is encountered.
  2. Once a newline ('\n') is encountered, your program should print the frequency of each digit between 0 and 9.
  3. Your program should then indicate which digit appeared most frequently. If there is a tie, the program should print out all digits that occured the same, maximum number of times.
  4. Your program should ignore letters.
  5. Use an array of integers to track the frequency of each digit in the message

For example:

If I enter the message "a12sd34fg5f4", the program should print out a string of numbers, separated by a space, that indicate the frequency of each digit between 0 and 9 such as:

0 1 1 1 2 1 0 0 0 0

and print a statement such as:

4 appeared most frequently in the input message.

Hints

Grading

Your testing should cover an appropriate range of "input" value combinations and your program's output should make it easy to assess correctness. I highly recommend for this (and all coding projects) that you make a testing plan before you start to write code. You do not need to plan to test all possible inputs to the program, but you should have a plan that will test major sections of your code and demonstrate your problem solving skills. Include this plan when you submit your code and testing transcript.

Upload your .c file, your testing plan (in PDF form please), and testing transcript to Gradescope. Your .c file should compile on mathlan without error using clang. You should not use any header files beyond those discussed on this page.

This homework is worth 25 points, based on the following criteria: