Reposting this question! All info that I got are included in the screenshots. Th
ID: 3921669 • Letter: R
Question
Reposting this question! All info that I got are included in the screenshots. This assignment must be done using command line arguments in C programming language. Will be run and tested using a Linux terminal but that shouldn't affect the code. Need help ASAP please! 1 Introduction This assignment is designed to use a hash table to count the number of unique addresses accessed by a program. You need to implement a program called count. The input of the count program is a trace consisting of 64-bit addresses and you are required to print out the number of unique address in the trace. 2 Problem speci cation: Use a hash table to count the number of unique addresses 2.1 Hash table with chaining In this assignment, you will implement a hash table with chaining. An important part of a hash table is collision resolution. In this assignment, we want you to use chaining, which is di erent from Assignment 1. Figure 1 shows an example of using separate chaining in hash table. More information about chaining with linked list can be found at Wikipedia, http:/len.wikipedia. org/wiki/Hashtable#Separate chaining-with-linked-lists. 0 k 1,data k2,datak4,data m-1 k3,data Figure 1: Example of a hash table with separate chaining. Use a linked list to store collisions.Explanation / Answer
void uniqueword (ifstream&, ofstream&, char);
void uniqueword (ifstream &inputFile, ofstream &outputFile, char words[100][16])
{
int count[55]; // Holds the associated counts.
char *tok=0; //storing tokens
int uniqueCount = 0; // Counts the total number of unique words
// Read every unique word in the file.
while(!inputFile.eof())
{
inputFile >> words[99];
// If there is a match, increment the associated count.
if(strcmp(words[99], tok) == 0)
{
counter[99]++;
}
}
// Display each unique word and its associated count.
for(int i = 0; i < 100; i++)
{
cout << words[i] << ":" << counter[i] << endl;
}
}
int main(int argc, char *argv[])
{
ifstream inputFile;
ofstream outputFile;
char words[100][16];
char inFile[12] = "input.txt";
char outFile[16] = "unique word.txt";
// Get the name of the file from the user.
cout << "Enter the name of the file: ";
cin >> inFile;
// Open the input file.
inputFile.open(inFile);
// Open the output file.
outputFile.open(outFile);
if(inputFile)
{
while(!inputFile.eof())
{
uniqueword (inputFile, outputFile, words);//call the function
}
// Close the input file.
inputFile.close();
// Close the output file.
outputFile.close();
return 0;
}
else
{
// Display the error message.
cout << "Input File not found. ";
}
}
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.