bigrams.c file and tests.txt to Gradescope under the corresponding assignment.
You may submit as many times as you like up until the deadline.
This assignment is designed to give you practice with reading input from the keyboard and using arrays. You will write a program that reads input from the user until they type a newline character (i.e. they press enter). Your program will finish by displaying the number of times it saw each bigram in the user input, as well as the most common bigram.
A bigram is a sequence of two adjacent characters from in the user input.
The input "abc" has two bigrams: "ab" and "bc".
Bigrams include any adjacent characters – including spaces – so inputs like "test message" would include the bigrams "t " and " m".
Note that this assignment does not specify an upper limit on the length of user input; you should not set an upper limit in your implementation. Instead, design your solution so you do not need to store the entire input at any one time. All you need to keep track of is the count for each bigram you have observed. An array (perhaps even a 2D array) would be a good way to organize your count of bigrams.
To get started, download bigrams.tar.gz and run the following commands to extract and open the starter code on MathLAN:
$ cd ~/csc161/homework
$ tar xvzf ~/Downloads/bigrams.tar.gz
$ cd bigrams
As you complete your implementation, make sure your program meets the following requirements:
"AB", "Ab", "aB", and "ab" all have distinct counts.Your program can display bigrams in any order that is convenient for you.
The following examples show the expected output for some test cases. The input provided to the program is displayed just below the program’s invocation.
$ ./bigrams
abc
"ab": 1
"bc": 1
Most common bigram: "ab"
$ ./bigrams
antidisestablishmentarianism
"ab": 1
"an": 2
"ar": 1
"bl": 1
"di": 1
"en": 1
"es": 1
"hm": 1
"ia": 1
"id": 1
"is": 3
"li": 1
"me": 1
"ni": 1
"nt": 2
"ri": 1
"se": 1
"sh": 1
"sm": 1
"st": 1
"ta": 2
"ti": 1
Most common bigram: "is"
$ ./bigrams
161 is (sometimes) fun
" (": 1
" f": 1
" i": 1
"(s": 1
") ": 1
"1 ": 1
"16": 1
"61": 1
"es": 1
"et": 1
"fu": 1
"im": 1
"is": 1
"me": 2
"om": 1
"s ": 1
"s)": 1
"so": 1
"ti": 1
"un": 1
Most common bigram: "me"
$ ./bigrams
Sally sells seashells by the seashore.
" b": 1
" s": 3
" t": 1
"Sa": 1
"al": 1
"as": 2
"by": 1
"e ": 1
"e.": 1
"ea": 2
"el": 2
"he": 2
"ho": 1
"ll": 3
"ls": 2
"ly": 1
"or": 1
"re": 1
"s ": 2
"se": 3
"sh": 2
"th": 1
"y ": 2
Most common bigram: " s"
$ ./bigrams
a
The input did not contain any bigrams.
getchar() function is probably the easiest way to do this.Your assignment will be graded on a scale of 0–100 points based on the following criteria:
You no longer need to submit test transcripts with assignments for this class.
Instead, you will fill in a file tests.txt (provided in your starter code) with a plan for how you will test your implementation.
Your tests should cover edge cases, different types of input, and inputs that check the correctness of your most frequent bigram computation.
Note that your implementation does not have to pass all of your tests for you to receive full credit on the testing portion of the assignment. Designing a good set of tests is a good way to plan your implementation, so you may even choose to write tests first.
There will be potential deductions for any code quality violations. For now, there are six requirements for quality code:
if–else block that explains what the purpose of that code is. The comment should not simply restate the code; it should add information for a human who reads the code and is confused.