{[ promptMessage ]}

Bookmark it

{[ promptMessage ]}

LabExam1Soln

# LabExam1Soln - A histogram is a graphical display of...

This preview shows pages 1–3. Sign up to view the full content.

A histogram is a graphical display of tabulated frequencies, shown as bars. An example of a histogram You should complete a program that asks the user for limits of 5 bins, reads data from a file and prints the histogram. Example of the run: Enter 4 limits of bins 0 1 2 3 Enter the name of the data file : data.txt -INF- 0 :*** 0- 1 :******* 1- 2 :*** 2- 3 :*** 3- +INF :** data.txt -1 -1 1.2 1.2 1.4 0.1 0.2 -.1 0.1 0.2 0.3 0.1 0.4 2.2 2.2 2.3 5 6 The incomplete program looks as follows: #include <iostream> #include <iomanip> #include <fstream> using namespace std;

This preview has intentionally blurred sections. Sign up to view the full version.

View Full Document
const int TOTAL_BINS=5; void add_point( double x, int bins[], double limits[]); void print_hist( int bins[], double limits[]); bool read_data( char name[], int bins[], double limits[]); int main() { double limits[TOTAL_BINS-1]; int bins[TOTAL_BINS]; cout<< "Enter " <<TOTAL_BINS-1<< " limits of bins" <<endl; for ( int i=0;i<TOTAL_BINS-1;i++) { cin>>limits[i]; } char file[80]; do { // try to read data from file // until user enters valid file name cout<< "Enter the name of the data file : " ; cin>>file; } while (!read_data(file,bins,limits)); print_hist(bins,limits); return 0; } void add_point( double x, int bins[], double limits[])
This is the end of the preview. Sign up to access the rest of the document.

{[ snackBarMessage ]}