Help Tank identify the amount of viruses in code!

Your tasks are:

1.to write the MyUnorderedMap functions

2.to write a function, get_virus_frequency(), that accepts an arbitrary number of lines from standard input and builds a MyUnorderedMap containing the number of occurances for every word containing the word "Virus" in it, i.e., if the word CryptoLockerVirus appears 15 times in the input code, then map[CryptoLockerVirus] should return 15.

An example of the behavior of this function is at the end of pa06.cpp, which expects < sample_input.txt

// Some actual C++ source code (your sample_input.cpp)

cout <// your actual get_virus_frequency code:

myhashdictionary["reallyBig_badvirus37"] = 1;

myhashdictionary["reallyBig_badvirus37"]++;
# This is how you'd run

g++ pa08.cpp

./a.out

Hint: you cant just define word boundaries by spaces, because this is code.

You will need to define word boundaries by special characters too.

Assignment Notes

You will implement a dictionary (abstract data type) using a hash table data structure that will have similar functionality to std::unordered_map.

https://en.cppreference.com/w/cpp/container/unordered_map

Deliverable: You must submit a file, MyUnorderedMap.hpp, that contains the implementations of

1.all of your MyUnorderedMap functions and
2.get_virus_frequency()
3.your name function

Dictionary.h

#ifndef DICTIONARY_H
#define DICTIONARY_H

#include "MyPair.h"


template
class Dictionary
{
public:
// Should only update, but not insert
// Should throw std::out_of_range exception
virtual V & at(const K &key) = 0;

// Updates or inserts
virtual V & operator[](const K &key) = 0;

virtual bool empty() const = 0;

virtual int size() const = 0;

virtual void clear() = 0;

virtual void insert(const MyPair &init_pair) = 0;

// The version that removes by key
virtual void erase(const K &key) = 0;

// Not exactly like the std:: version, but similar.
virtual MyPair< K, V> * find(const K &key) const = 0;

// Not actually std:: (see h file)
virtual void print() const = 0;

virtual int count(const K &key) const = 0;
};

#endif

MyPair.h

#ifndef MYPAIR_H
#define MYPAIR_H

template < typename K, typename V>
struct MyPair
{
K first;
V second;

MyPair(){}
MyPair(const K &key): first(key) {}
MyPair(const K &key, const V &value): first(key), second(value) {}
};

#endif

MyUnorderedMap.h

#ifndef MYUNORDEREDMAP_H
#define MYUNORDEREDMAP_H

#include < iostream>
#include < stdexcept>
#include < string>
#include "Dictionary.h"

using std::cout;
using std::endl;


void get_identity(std::string &my_id);


template < typename K, typename V>
class MyUnorderedMap: public Dictionary< K, V>
{
private:
MyPair< K, V> *m_data = nullptr;

int data_size = 0;
int reserved_size = 0;

// To make it easier on you (rather than use void pointers or crazy new C++ templating)
// we'll only test with std::string keys (remember values can be any type)
int hash(const K &key) const;

public:
// Should start data_size and reserved_size at 0, m_data to nullptr
MyUnorderedMap();

~MyUnorderedMap();

MyUnorderedMap(const MyUnorderedMap< K, V> &source);

MyUnorderedMap< K, V> & operator=(const MyUnorderedMap< K, V> &source);

V & at(const K &key);

V & operator[](const K &key);

bool empty() const;

int size() const;

// data_size and reserved_size should be 0 after this,
// and m_data should be nullptr.
void clear();

void insert(const MyPair< K, V> &init_pair);

void erase(const K &key);

// Should return nullptr for key not in HT
MyPair< K, V> * find(const K &key) const;

// Not actually std::
// Backwards in order traversal print (for BST)
// For Hash table, just print all elements in any order,
// so that it looks like this when you print(unordereded_map_obj):
// ([K0]=V0,
// [K1]=V1,
// [K2]=V2)
// With a newline at the end
// Like in sample_output.txt
// Do not modify the table.
// Only print valid current data elements.
void print() const;

int count(const K &key) const;

// This one was not in the BST, but is in the HT
// Grows or shrinks reserved_size and size of dynamic array to be new_cap large,
// and nothing else.
// Other functions, like insert, erase, or [], should decide how large to make the new cap
// and call reserve themselves with that size.
// Those other functions should choose to double the reserved size when the HT becomes 60% full,
// and to shrink the HT when it becomes 10% full, to a resulting 30%.
// Remember to re-hash!
void reserve(int new_cap);

};

// Should accept a source code file (.cpp for example) via std in
// Should build a dictionary of the counts of the words in the code file
// Only count the words that contain the word "virus" (not case sensitive) as a substring
// so that a list of the amount of viruses in the code can be tracked
// Do not add newlines (n) to the dictionary (they'll mess up print)
// Most symbols should be excluded to isolate the actual keywords and
// variable names in the code
// ./a.out < sample_code.cpp should be the form of input
void get_virus_frequency(MyUnorderedMap< std::string, int> &in_tree);


#include "MyUnorderedMap.hpp"

#endif
Academic Honesty!
It is not our intention to break the school's academic policy. Posted solutions are meant to be used as a reference and should not be submitted as is. We are not held liable for any misuse of the solutions. Please see the frequently asked questions page for further questions and inquiries.
Kindly complete the form. Please provide a valid email address and we will get back to you within 24 hours. Payment is through PayPal, Buy me a Coffee or Cryptocurrency. We are a nonprofit organization however we need funds to keep this organization operating and to be able to complete our research and development projects.