Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

C++ PROGRAM I just need some additional code on my program, i need to show the bytes on each number. NOTE: NUMBER OF BYTES MUST

C++ PROGRAM

I just need some additional code on my program, i need to show the bytes on each number.

NOTE: NUMBER OF BYTES MUST SHOW AFTER THE * (asterisk) ON EACH NUMBER

Code:

#include #include #include #include using namespace std; // Ask user for filename and open it for reading in binary mode void inputFileDetails(ifstream &ifs) { string fn; cout<<"Enter the exact location of the file & put filename extension (ex. .txt at the end): "; cin >> fn; ifs.open (fn, ios::in | ios::out | ios::binary); if (!ifs.is_open()) { cout << "File could not be opened!"; exit(1); } } // Read each character from file and increment count for that character by 1 void countTotalBytes(ifstream &ifs,int counters[],int& totalbytes) { char c; while (ifs.read(&c, 1)) { counters[(unsigned char) c]++; totalbytes++; } ifs.close(); } // Find the maximum value of all the character counters so that we can scale the distribution plot void findMax(int counters[],int &max) { for (int i = 0; i < 256; i++) if (counters[i] > max) max = counters[i]; } void displayDistribution(int counters[],int max) { // Plot the distribution after applying scaling for (int i = 0; i < 256; i++) { int stars = round (counters[i] * 100.0 / max); cout << setw(3) << i << " "; for (int i = 0; i < stars; i++) cout << "*"; cout << endl; } } void displayStatistics(int max,int totalbytes) { cout << " Max count: " << max; cout << " Legend: * = " << round(max / 100.0) << " bytes "; cout << " Total: " << totalbytes << endl;

} int main() { string fn; int counters[256], max = 0, totalbytes = 0; // keep track of how many of each char (0 to 255) in counters for (int i = 0; i < 256; i++) counters[i] = 0; ifstream ifs;

//call functions inputFileDetails(ifs); countTotalBytes(ifs,counters,totalbytes); findMax(counters,max); displayDistribution(counters,max); displayStatistics(max,totalbytes); return 0; }

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Database Marketing The New Profit Frontier

Authors: Ed Burnett

1st Edition

0964535629, 978-0964535626

More Books

Students also viewed these Databases questions

Question

Differentiate 3sin(9x+2x)

Answered: 1 week ago

Question

Compute the derivative f(x)=(x-a)(x-b)

Answered: 1 week ago