Question

For a linear probing hash table in C++ what foes into my HashLin.hpp, HashLin.cpp, and Main.cpp...

For a linear probing hash table in C++ what foes into my HashLin.hpp, HashLin.cpp, and Main.cpp files. I am not really sure how all the different files work together. Also, once I have to code finished and need in input data from a file how do I do that? Any help would be great!!!

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

OK FIRST we will understand how different files will compile together

with simple steps i'm going to show that

HashLin.h file is a headerfile which will contain basic definitions like definition of a function

as in our case we will use class for solving the problem so the definition of the class will be written in this headerfile

and only the signature of the headerfile will be written in the headerfile

next file is HashLin.cpp this file will contain the definition of the methods of the class defined in the file HashLin.h

so all the functions will be stored in this file

next file is Main.cpp which will contain the driver program means input and output. all the member declaration and their use will be written in the Main.cpp

I've created sample three files for you which is as

----------------------------first file --------------------------------------------------------------

--------------------------HashLin.h------------------------------------------------------------

#ifndef HashLin_H_
#define HashLin_H_

class HashLin
{
public:
   //this part will contain the members of the class
   int a; // this is just an example
   HashLin(); //this will be constructor of the class , remember we will write it's definition in the other file
   HashLin(int a);

   //all the signature of the function will be written here
};
#endif

---------------------------------second file ---------------------------------------------

----------------------------------HashLin.cpp-------------------------------------

#include "HashLin.h" //this include our headerfile
#include<iostream>
using namespace std;

HashLin:: HashLin(){
a=5;
}

HashLin:: HashLin(int a){
this->a=a;
}

------------------------------------------------third file ----------------------------------------------------

-------------------------------------------------Main.cpp---------------------------------------------------

#include<iostream>
#include<fstream>
#include "HashLin.h" //here we have included the headerfile
using namespace std;
int main()
{
ifstream f; //this is an object which will help in reading from a file
f.open("nums.txt"); //this will open a file num.txt for reading mode
while(f)
{
int b;
f>>b; //an integer will be read from the file nums.txt and you can change according to your requirement
HashLin* obj=new HashLin(b); //create an object which will be intialised with the file data
cout<<obj->a<<"\n"; //see data here
}
}

Note :- in above file i've shown you how you can read the data from a file as well

here is the file nums.txt

- Notepad nums Eile Edit Format View Help 1 2 3 4 6 7 8 9 10

Now how can you compile multiple files together

i hope you are using linux so we have to work with g++

if you are using any other IDE then you have to create a project and then build that project

also in window you can use "mingw" library and then you can use g++

here are the steps

place the HashLIn.h file in the include folder you have to find it in windows system in the mingw folder

i'm using windows system and using mingw64 so included the headerfile in the below path

D:\mingw-w64\i686-8.1.0-posix-dwarf-rt_v6-rev0\mingw32\i686-w64-mingw32\include

but in linux place this file in the same folder where other files are stored

Now place following command to compile multiple files together in both linux and window system

./g++ HashLin.cpp Main.cpp -o output

in linux you have to remove ./ from the g++ so

g++ HashLin.cpp Main.cpp -o output

here -o is used for putting the name of the output file and we have given "output" name to our output file

to execute this output file we will use

./output

in linux only use

output

here is the ss of the above process

PS D:\mingw-w64\i686-8.1.0-posix-dwarf-rt_v6-rev0\mingw32\bin> ./g++ HashLin.cpp Main.cpp -o output PS D:\mingw-w64\i686-8.1.

I hope this will help you so please give positive ratings :))))

- Notepad nums Eile Edit Format View Help 1 2 3 4 6 7 8 9 10

PS D:\mingw-w64\i686-8.1.0-posix-dwarf-rt_v6-rev0\mingw32\bin> ./g++ HashLin.cpp Main.cpp -o output PS D:\mingw-w64\i686-8.1.0-posix-dwarf-rt_v6-rev0\mingw32\bin> ./g++ HashLin.cpp Main.cpp -o output PS D:\mingw-w64\i686-8.1.0-posix-dwarf-rt_v6-rev0\mingw32\bin> ./output 10 10 PS D:\mingw-w64\i686-8.1.0-posix-dwarf-rt_v6-rev0\mingw32\bin> L22-~M5ONM9H

Add a comment
Know the answer?
Add Answer to:
For a linear probing hash table in C++ what foes into my HashLin.hpp, HashLin.cpp, and Main.cpp...
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
  • C++ assignment - Hash table with linear probing --- implement in single file - main.cpp You...

    C++ assignment - Hash table with linear probing --- implement in single file - main.cpp You are asked to implement a very specific hash table. The keys are lower-case English words (e.g., apple, pear). The length of a key is at most 10. The hash function is “simply using the last character”. That is, the hash value of apple should be e, and the hash value of pear should be r. Your hash table contains exactly 26 slots (hash value...

  • Implement an eager delete() method for linear probing hash table. The eager delete will delete the...

    Implement an eager delete() method for linear probing hash table. The eager delete will delete the pair from the hash table, not just set the value to null. *Algorithhms* In Java Language Please I want to add the delete method to this hash table code. public class Linear ProbingHashST<Key, Value> private int M = 30001; private Value [] vals = (Value[]) new Object[M]: private Key [] keys = (Key []) new Object[M]: array doubling and halving code omitted private int...

  • The task of this project is to implement in Java Hash Table structure using Linear Probing...

    The task of this project is to implement in Java Hash Table structure using Linear Probing Collision Strategy.   You can assume that no duplicates or allowed and perform lazy deletion (similar to BST). Specification Create a generic class called HashTableLinearProbe <K,V>, where K is the key and V is the value. It should contain a private static class, HashEntry<K,V>. Use this class to create array to represent Hashtable:             HashEntry<K,V> hashtable[]; Implement all methods listed below and test each method...

  • please use Java!! We are storing the inventory for our fruit stand in a hash table....

    please use Java!! We are storing the inventory for our fruit stand in a hash table. The attached file shows all the possible key/fruit combinations that can be inserted into your hash table. These are the real price lookup values for the corresponding fruit. Problem Description In this programming assignment, you will implement a hash table class fruitHash. Your hash table must include the following methods: 1) hashFunction(key) This method takes a key as an argument and returns the address...

  • Task: Comparing the performance between Linear Probing and Double Hashing. Requirements: Please make sure your program...

    Task: Comparing the performance between Linear Probing and Double Hashing. Requirements: Please make sure your program compiles, otherwise your submission will not be graded and you will receive zero. Point deduction rule: Compile warning: 3 points each. Minor error: such as not meeting the assignment input/output requirement, 5 points each. Major error: examples include, infinite loop, runtime errors, any runtime exception, 15 points each. Any code not compliant to the assignment requirement (e.g., not using List interface and AbstractMap and...

  • Linear Hash Table 2. In this first question you will apply the specified operations to instances...

    Linear Hash Table 2. In this first question you will apply the specified operations to instances of LinearHashTable (i.e., hash tables that use the "linear probing" approach as it was discussed in class). When such a hash table is first created, it has dimension 1 and an initial length of 2, and subsequent operations might require that the underlying array be resized, so for each of the questions below, start with the hash table specified and demonstrate (by drawing the...

  • I really need assistance with creating a C++ hash table program for generating a hash from a string. Create a hash funct...

    I really need assistance with creating a C++ hash table program for generating a hash from a string. Create a hash function then test and evaluate the results. The set of strings are from a "words.txt" file (there are 45,402 words in the file, no repeating words. Map the words to 45,402 buckets using a hash function). Requirements: Create an array of 45,402 integers and initialize each to zero. These will be used to store how many times each index...

  • I really need assistance with creating a C++ hash table program for generating a hash from a string. Create a hash funct...

    I really need assistance with creating a C++ hash table program for generating a hash from a string. Create a hash function then test and evaluate the results. The set of strings are from a "words.txt" file (there are 45,402 words in the file, no repeating words. Map the words to 45,402 buckets using a hash function). Requirements: Create an array of 45,402 integers and initialize each to zero. These will be used to store how many times each index...

  • This should be in Java Create a simple hash table You should use an array for...

    This should be in Java Create a simple hash table You should use an array for the hash table, start with a size of 5 and when you get to 80% capacity double the size of your array each time. You should create a class to hold the data, which will be a key, value pair You should use an integer for you key, and a String for your value. For this lab assignment, we will keep it simple Use...

  • Following class is only part of my program that uses a hash table to simulate a...

    Following class is only part of my program that uses a hash table to simulate a market's client database, client class is my main class which asks user to input client names and then creates a hash table which then users can look up client names. wasn't able to upload everything as it is too much code, but what I need is to modify my client class instead of me inputting data line by line, the program should read from...

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