Notes
The programs will be compiled and tested on the machine which runs the
Linux operating system. V3.4 of the GNU C/C++ compiler (gcc ,g++) must be used.
A significant amount coding is needed for this assignment.
1.Counting Words in C++
Problem: Write an elegant C++ program to count the number of times each word occurs
in a file. A word is defined as a sequence of characters surrounded by whitespace. Case is
not important, so the word “Run” should be treated the same as “run” or “RUN”.
Input: A text file. Assume the number of words in the input is usually less than 150,000.
The maximum size of a single word is 255 characters.
Output: A printout of all words in the input (one word per line), and their corresponding
reference count. Word ordering is unimportant.
Example: Given the following input text:
See the dog. See the dog run. Run dog, run. That dog can really run.
Your program will produce output resembling the following:
can 1
dog 2
dog, 1
dog. 1
really 1
Run 1
run. 3
See 2
That 1
the 2
Notes:
The program must be written in C++ and will be compiled with g++.
Your code must compile cleanly, must not produce any warnings when –Wall is
specified, and must run without any changes.
Make sure your solution is constructed clearly and idiomatically, so that it adheres
to the commonly accepted definition of good style as discussed in class.
Be sure to properly comment your program; explain how the solution works and
why you selected particular algorithm(s) and data structure(s).
Provide citations to references you may have used in constructing your solution.
Input to the program will come from standard input. Output must be to standard
output. Do not prompt for input, nor produce spurious output.
Your program will be testing in a manner similar to the following (the file names
“input.txt” and “output.txt” are only examples):
2. Counting Words in C
Problem: Redo the previous problem, but instead of an elegant C++ program,
produce an elegant and efficient C program. Since the program is in C, you cannot use
any C++ mechanisms, such as the Standard Template Library (STL) or stream I/O.
Notes:
The program must be written in C and will be compiled with gcc.
The code must compile cleanly, must not produce any warnings when –Wall is
specified, and must run without any changes.
Make sure your solution is constructed clearly and idiomatically, so that it adheres
to the commonly accepted definition of good style as discussed in class.
Be sure to properly comment your program; explain how the solution works and
why you selected particular algorithm(s) and data structure(s).
Provide citations to references you may have used in constructing your solution.
Input to the program will come from standard input. Output must be to standard
output. Do not prompt for input, nor produce spurious output.
Your program will be testing in a manner similar to the following (the file names
“input.txt” and “output.txt” are only examples)
The programs will be compiled and tested on the machine which runs the
Linux operating system. V3.4 of the GNU C/C++ compiler (gcc ,g++) must be used.
A significant amount coding is needed for this assignment.
1.Counting Words in C++
Problem: Write an elegant C++ program to count the number of times each word occurs
in a file. A word is defined as a sequence of characters surrounded by whitespace. Case is
not important, so the word “Run” should be treated the same as “run” or “RUN”.
Input: A text file. Assume the number of words in the input is usually less than 150,000.
The maximum size of a single word is 255 characters.
Output: A printout of all words in the input (one word per line), and their corresponding
reference count. Word ordering is unimportant.
Example: Given the following input text:
See the dog. See the dog run. Run dog, run. That dog can really run.
Your program will produce output resembling the following:
can 1
dog 2
dog, 1
dog. 1
really 1
Run 1
run. 3
See 2
That 1
the 2
Notes:
The program must be written in C++ and will be compiled with g++.
Your code must compile cleanly, must not produce any warnings when –Wall is
specified, and must run without any changes.
Make sure your solution is constructed clearly and idiomatically, so that it adheres
to the commonly accepted definition of good style as discussed in class.
Be sure to properly comment your program; explain how the solution works and
why you selected particular algorithm(s) and data structure(s).
Provide citations to references you may have used in constructing your solution.
Input to the program will come from standard input. Output must be to standard
output. Do not prompt for input, nor produce spurious output.
Your program will be testing in a manner similar to the following (the file names
“input.txt” and “output.txt” are only examples):
2. Counting Words in C
Problem: Redo the previous problem, but instead of an elegant C++ program,
produce an elegant and efficient C program. Since the program is in C, you cannot use
any C++ mechanisms, such as the Standard Template Library (STL) or stream I/O.
Notes:
The program must be written in C and will be compiled with gcc.
The code must compile cleanly, must not produce any warnings when –Wall is
specified, and must run without any changes.
Make sure your solution is constructed clearly and idiomatically, so that it adheres
to the commonly accepted definition of good style as discussed in class.
Be sure to properly comment your program; explain how the solution works and
why you selected particular algorithm(s) and data structure(s).
Provide citations to references you may have used in constructing your solution.
Input to the program will come from standard input. Output must be to standard
output. Do not prompt for input, nor produce spurious output.
Your program will be testing in a manner similar to the following (the file names
“input.txt” and “output.txt” are only examples)
Comment