Question

C++ hashing code must read in an input file "input.txt", which is formatted as such: add...

C++ hashing code must read in an input file "input.txt", which is formatted as such:

add 0x20000000

addi 0x20000000

addiu 0x24000000

addu 0x21000000

and hash from an array with the values "0x2000000, 0x20000000, 0x24000000, 0x2100000" hard coded in.

Then the output must read the value and then the item such as add, addi, addiu, addu, making it look like:

0x200000000 add

0x200000000 addi

0x240000000 addiu

0x210000000 addu

0 0
Add a comment Improve this question Transcribed image text
Answer #1

Hi please find below code .Put this code in main.cpp and put your text file in same directory of code.compile and run the .Cpp file.


#include<iostream>
#include<fstream>
#include <string>
using namespace std;
int main() {
ifstream myReadFile;
string line,key,value;

//hardcoded values
string val[]={"0x2000000", "0x20000000", "0x24000000", "0x2100000"};

//Open the file to be read
myReadFile.open("input.txt");
int count=0;

//check if file is open
if (myReadFile.is_open()) {

//Read file line by line
while (getline(myReadFile,line)) {
stringstream s(line);

//Get the item in key from stringstream
s>>key;

//Print values from hardcoded array and item from #file
cout<<val[count]<<" "<<key<<endl;
count++;

}
}

//close file stream.
myReadFile.close();
return 0;
}
Output:

0x2000000 add 0x20000000 addi 0x24000000 addiu 0x2100000 addu

Add a comment
Know the answer?
Add Answer to:
C++ hashing code must read in an input file "input.txt", which is formatted as such: add...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • The name of the C++ file must be search.cpp Write a program that will read data...

    The name of the C++ file must be search.cpp Write a program that will read data from a file. The program will allow the user to specify the filename. Use a loop that will check if the file is opened correctly, otherwise display an error message and allow the user to re-enter a filename until successful. Read the values from the file and store into an integer array. The program should then prompt the user for an integer which will...

  • Insert elements into a hash table implemented using chain hashing, as an array of linked list...

    Insert elements into a hash table implemented using chain hashing, as an array of linked list in which each entry slot is as a linked list of key/value pairings that have the same hash (outcome value computed using certain hash function). You are allowed to use “Hash Function”, h(k) = k % x where, x is the value you will need to decide to use, that you find appropriate for this implementation. The main requirements are the following: 1. Input:...

  • write a c++ code to read multiple integers from input.dat until the end of file. Edit...

    write a c++ code to read multiple integers from input.dat until the end of file. Edit input.dat and put several integers in it. Compile and execute the code then check output.dat to verify all the integers are in there. Update the code to check to see if input.dat exists before reading from it. If it doesn’t exist print an error message (and don’t read!). Compile and execute your code. Delete input.dat and output.dat and execute – did you see your...

  • I am writing a program in C++, which requires me to read an input text file...

    I am writing a program in C++, which requires me to read an input text file using command line argument. However, I am using xcode on my Macbook to write C++ program, and use terminal instead of command. How do you use int main(int argc, char** argv[]) to read an input file. My professor requires us not to hard code the text file name like .open("example.txt"); Thank you!

  • C++ code The assignment has two input files: • LSStandard.txt • LSTest.txt The LSStandard.txt file contains...

    C++ code The assignment has two input files: • LSStandard.txt • LSTest.txt The LSStandard.txt file contains integer values against which we are searching. There will be no more than 100 of these. The LSTest.txt file contains a set of numbers that we are trying to locate within the standard data set. There will be no more than 50 of these. Read both files into two separate arrays. Your program should then close both input files. All subsequent processing will be...

  • C program Read file problem: For example, I have an input.txt file like this: q 1...

    C program Read file problem: For example, I have an input.txt file like this: q 1 tq 4 p1 10 p2 5 p3 7 p4 20 p5 17 p6 9 p7 3 p8 11 p9 15 p10 1 I want the num of q is in one array, tq is in one array, the order of process(ie,p1,p2) is in one array, and process time is in one array(process time is the number after like p1,p2). There may many q,tq,p so...

  • 1. What would be the output of the following MIPS code? .globl main main addu $s7, $0, $ra add $s3, $0,$0 addi $s4, $0,...

    1. What would be the output of the following MIPS code? .globl main main addu $s7, $0, $ra add $s3, $0,$0 addi $s4, $0, 1 $s5, $0,$0 $s6, save add . data .align 2 .globl save # the next line creates an array of 10 words that can be re ferred to as "save" # the array is initialized to the 10 values after .wo rd # so the first array entry is a 0 and the last entry is...

  • Please answer question in C++, thank you. Read in name of input file. File will be...

    Please answer question in C++, thank you. Read in name of input file. File will be formatted as below: filename: triangles1.txt 3 4 5 7 7 7 For each line read in the 3 integer values as the 3 sides of a triangle and calculate the area and print on output line with two decimal points.

  • Create a complete pseudo-code program in C++ to do the following using the PseudoCode language developed...

    Create a complete pseudo-code program in C++ to do the following using the PseudoCode language developed in class using Absolute Addressing. There is 1 deliverable: 1. You should include the input cards shown below as a test. THE PROGRAM: First you will read in a value N which holds the number of values to be read in. (so if N is 20 then there will be 20 more cards to read in.) Read in N values into an array. Bubble-Sort...

  • Lab 8 Lab8-input.txt 0.076 10.886 5·648 12.023 12.224 6.882 0.226 0.039 16.193 4.916 3.978 17.877...

    Lab 8 Lab8-input.txt 0.076 10.886 5·648 12.023 12.224 6.882 0.226 0.039 16.193 4.916 3.978 17.877 -6.045 8.966 10.351 0.437 4.157 9.658 -9.480 3.049 9.223 27.855 4.669 3.873 CMPSC 201-Spring 2019 Lab 8 To be done individuallv Due by end of your recitation section on 3/29/19. Goals: Practicing 1-dimensional arrays in functions. Problem: Download the file "arrayfunctiondemo.cpp" from lecture on Wednesday 3/20 and modify the code so it will use a function to input data from a file, output data to...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT