Question
C++ PROGRAM Process command line arguments just add additional code to my program with the ff: * write a code to accept filenames on the
C++ PROGRAM
Process command line arguments
just add additional code to my program with the ff:
* write a code to accept filenames on the command line
* allow drag and drop (the user could simply drag the file to the reader)
**YOU CAN REFER TO THIS VIDEO
https://drive.google.com/file/d/1etOxzjPrRZ1rrIF-wWXnutUWuUXN5SeX/view?usp=sharing
SOURCE CODE:
#include
using namespace std;
void inputFileDetails(ifstream& ifs) {
string fn; cout << "Enter the exact location of the file & put filename extension (ex. .txt at the end): "; cin >> fn; cout << " Counting number of bytes.. "; ifs.open(fn, ios::in | ios::out | ios::binary); if (!ifs.is_open()) { cout << "File could not be opened!"; exit(1); } }
void countTotalBytes(ifstream& ifs, int counters[], int& totalbytes) { char c; while (ifs.read(&c, 1)) { counters[(unsigned char)c]++; totalbytes++; } ifs.close(); }
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) {
for (int i = 0; i < 256; i++) { int stars = round(counters[i] * 100.0 / max); cout << setw(2) << setfill('0') << hex << i << "(" << setfill(' ') << setw(3) << dec << i << ")" << ": "; for (int i = 0; i < stars; i++) cout << "*"; for (int u = 100; u > stars; u--) cout << "."; cout << " " << stars; if (isprint(char(i))) cout << "\t" << "(" << char (i) << ")"; 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;
for (int i = 0; i < 256; i++) counters[i] = 0; ifstream ifs;
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
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started