EEEE2065 - Assessed Lab#1
Printing an ascii histogram.
Total marks: 100

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

❼ 0-25%: Codes undeveloped or did not compile properly.
❼ 26-50%: Codes developed and compiled, but not achieving expected result, programs are buggy or inefficient.
❼ 51-75%: Codes developed and compiled and results are correct, but modularity/clarity/commenting practices are not well followed.

❼ 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

Create a Histogram class and define appropriate variables and methods within it to be able to accomplish the following.
1.0 12.0
2.0 15.2
3.0 17.8
4.0 19.1
5.0 15.3
6.0 13.1
7.0 14.3
Figure 1: An example of an inputFile.hist that your program will read in.

Your program needs to

1. Read the name of the input file from the command line by typing a command such as:
$ 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.

4. Create a sample histogram file as shown in Figure 1 and test your readHistFile() and printHistData() functions above by calling them from your main.

2 Use the data in your class to plot a horizontal histogram.

The two numbers in the input file of Figure 1 represent a histogram where the first number is the bin-label, for example, the day of the week, and the second number is a measure ofsome quantity we are interested in. This could be any parameter, for example, the amount of pollution measured from a sensor. Create a function plotHorizontalHist() in your Histogram class that uses the data read from the input file to plot a histogram with labels. The bars of the histogram extend horizontally with the length of the bars proportionate to the number associated with each label. Such as in Figure 2.
1.0/12.00 ************************
2.0/15.20 *******************************
3.0/17.80 ************************************
4.0/19.10 ***************************************
5.0/15.30 *******************************
6.0/13.10 ***************************
7.0/14.30 *****************************
Figure 2: Printing a Horizontal Histogram

3 Modifying to plot a vertical histogram.

Histograms usually are viewed vertically rather than horizontally. Create another subfunction in your class plotVerticalHist() that allows you to plot the histogram vertically such that the output looks more like in Figure 3.
*
*
* *
* *
* * * *
* * * * *
* * * * * *
* * * * * *
* * * * * * *
* * * * * * *
* * * * * * *
* * * * * * *
* * * * * * *
* * * * * * *
* * * * * * *
* * * * * * *
* * * * * * *
* * * * * * *
* * * * * * *
* * * * * * *
1 2 3 4 5 6 7

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.

3. Plot your histogram vertically and horizontally with the data taken from the inputFile.txt. Once you have completed, write up what you have done in a report of length 7-10 pages. Explain how and why you made the design decisions that you made in constructing yourprogram and show the key results. Upload your report together with all your relevant .cpp and .h files to Moodle by end of the day on Oct 13, 2023.