EEEE2065 - Assessed Lab#1
Overview
In this coursework assessment you are to create a single program histogram.cpp that contains appropriate class(es) at the top and a main() function that is able to accomplish the tasks described below. This coursework assessment is made available to the students on Fri day Oct 6th 2023 and is due back uploaded on Moodle by 5pm, Friday Oct 13th 2023. Please be sure to submit your programs on Moodle by the due date. A penalty of 5% per day will be imposed on late submissions. This assessed lab is worth 10% of your final grade. You are to use C++ version of commands to accomplish your tasks where possible. In particular you are to use classes to implement the tasks described.
Marking Rubric
❼ 76-100%: Codes developed and compiled with correct results and with clear, well commented code and modularity rules being demonstrated/followed.
Plagiarism statement: The codes you submit are to be developed by the student alone. Any codes which are significantly similar to each other, or to code found on the internet will be penalized as plagiarism and points will be deducted accordingly.
1 Read histogram data from a file into your class
Your program needs to
$ histogram inputFile.hist
A sample inputFile.hist is shown in Figure 1 consisting of two columns of numbers.
The first column is the histogram bin-label while the second column is the histogram bin frequency of occurence. This should be achieved using the argc and argv parameters.
2. Create a function in your Histogram class: readHistFile() that opens the input file (checking for its existence, and exiting gracefully if it doesn’t exist) and reads the file’s contents into your class.
3. Although you may have correctly read the data from the file into your class, at this point you are currently not able to verify or see that data. Write a function printHistData() that prints out the contents of your histogram data so you can validate that it has been properly read into your Histogram class.
2 Use the data in your class to plot a horizontal histogram.
3 Modifying to plot a vertical histogram.
Figure 3: Printing a Vertical Histogram
4 Reading text from an ascii file, plotting histogram on word lengths.
In the last part of this assessment, you are to modify the input data source of the histogram. Instead of coming from a .hist file as in Figure 1, you are compute the histogram based on a .txt file that contains some human-readable text file, such as shown in Figure 4.
Our aim in writing the original edition of Numerical Recipes was to provide a book that combined general discussion, analytical mathematics, algorithmics, and actual working programs. The success of the first edition puts us now in a difficult, though hardly unenviable, position. We wanted, then and now, to write a book that is informal, fearlessly editorial, unesoteric, and above all useful. There is a danger that, if we are not careful, we might produce a second edition that is weighty, balanced, scholarly, and boring. Also used were a variety of C compilers, too numerous (and sometimes too buggy) for individual acknowledg ment. It is a sobering fact that our standard test suite (exercising all the routines in this book) has uncovered compiler bugs in many of the compilers tried. When possible, we work with developers to see that such bugs get fixed; we encourage interested compiler developers to contact us about such arrangements.
Figure 4: An example of an inputFile.txt that your program will read in.
1. Create a new subfunction in your Histogram class readTextFile() that is able to open and read a given .txt file, for every word read from the file, it measures the length of that word, and adds +1 to the frequency bin of that word length in the histogram. You can therefore populate the fields of your histogram from a .txt file or from a .histfile.
2. Rewrite your main function so that it now calls readTextFile() on the input taken from the command line, and plots the histogram of the word lengths in that file with a command such as:
$ histogram inputFile.txt
Be sure to zero out your histogram before populating it with data from inputFile.txt.
2023-10-13