please help me with C++ the part of the code and file are given below

I’m studying for my Computer Science class and need an explanation.

If you’ve used an Android phone, you know that the Google Play Store is the central location for locating applications (Apple fans will recognize this as the App Store). For each “app” in the store there is a record that contains information such as the name, category, rating, etc. — allowing you to view an information page and decide if you want to install that app on your device.

In this assignment you you will experiment with hash functions (or invent your own!) to implement a directory of information about mobile apps.

Input

The supplied input file in this module — googleplay.csv — contains entries for approximately 6000 applications. This is another CSV file similar to what we used in Lab #7. Each line contains information about a single app. There are 4 comma-separated fields, in this order: name, category, rating and reviews. You can assume the name field of each entry is unique to the file (this will be important for your hash function), but this is not true of any of the other three fields. The name field is a string of readable characters that can include spaces and punctuation.

Assignment

Write a program that implements a hash table using any of the methods described in Chapter 18 or in class. You are free to use any hash function of your creation and any method you choose to handle hash collisions. A good place to start for a hash key is to use something about the name — the first letter? the last letter? the first three letters? (these will all work, but none are a very good choice). To handle collisions, you could chain them with a linked list on each “bucket”, or use open addressing with linear probing, for example.

A starter file — main_googleplay_starter.cpp — is provided. This file implements the framework for the hash table and reading of the file. Some functions are marked for your implementation (i.e. appFind() and appInsert()).

Requirements

  • The program should ask for input of an app name (which may include spaces and punctuation) and output the details of the app, if it is found in the hash. Loop until an exit is requested (blank name, -1, etc.).
  • Your program only needs to implement the “add” and “lookup” functions, not deletes or rehashing/resizing of the table.
  • If the app is not found, output “Not found in the table” or similar.
  • This time, do not use any STL or any third-party libraries (for example, a Map) to implement the hash — it must be a hash of your own creation.
  • Do not use any hard-coded values, i.e. fixed strings that return responses to fixed questions. The program must be able to retrieve any of the keys available in the file.
  • Each entry should be hashed (some key generated, based in something about the record) i.e. do not just read the data into an array or some other fixed structure.
  • Output the average number of comparisons required to add all the entries from the file, and the number of comparisons for each successful or failed lookup.

See if you can bring down the number of comparisons from your first attempt. A little Google searching will yield some string-optimized hash functions. There is no “right” answer, but hash functions that perform very poorly (close to a linear search) will lose points.

Example Output

Read 6239 apps.
Average comparisons required: 1.78
Enter an app name (<return> to quit): Mandala Coloring Book

Found, comparisons required: 8
Name: Mandala Coloring Book
Category: ART_AND_DESIGN
Rating: 4.6
Number of reviews: 4326

Enter an app name (<return> to quit): Monster Ride Pro

Found, comparisons required: 2
Name: Monster Ride Pro
Category: GAME
Rating: 5.0
Number of reviews: 1

Enter an app name (<return> to quit): SuperVPN Free VPN Client

Found, comparisons required: 1
Name: SuperVPN Free VPN Client
Category: TOOLS
Rating: 4.3
Number of reviews: 576454

Enter an app name (<return> to quit): Calculus with Bobby Flay

Not found in the table.
Comparisons required: 6

Enter an app name (<return> to quit): _x000D_ _x000D_

main_googleplay_starter.cpp:

_x000D_ #include <iostream>

#include <sstream>

#include <fstream>

#include <cstdlib>

using namespace std;

#define FILENAME “googleplay.csv”

// A single app in the Google Play Store. If you are using

// chaining, you may need to add an additional structure here (or a

// ‘next’ pointer within this structure) to maintain the chains in

// each bucket.

typedef struct {

string name;

string category;

double rating;

int reviews;

} googlePlayApp;

// Starting size. Don’t adjust this unless absolutely necessary.

const int HASH_SIZE = 10007;

// Hash table for all of the apps — static so it’s zeroed. This

// is an array of pointers (change as needed).

static googlePlayApp *appHash[HASH_SIZE];

// Reads a single app, filling in the

// fields (name, etc.) passed by the caller. The caller

// is expected to pass a single line (row) from the csv file.

void readSingleApp(const string &str,

googlePlayApp &newApp) {

istringstream istr(str);

string fields[5];

string tmp;

int i = 0;

// Read in each csv column

while (getline(istr, tmp, ‘,’)) {

fields[i++] = tmp;

}

// Populate the new item with the column info

newApp.name = fields[0];

newApp.category = fields[1];

newApp.rating = atof(fields[2].c_str());

newApp.reviews = atoi(fields[3].c_str());

}

// Insert a new app into the hash table. You may want to add a

// reference variable here to track number of comparisons.

void appInsert(googlePlayApp &newApp) {

// Implement this function

}

// Find an app in the hash table

// Returns ‘true’ if the app was found, filling in the

// fields of ‘foundApp’, else false. You may want to add a reference

// variable here to track number of comparisons.

bool appFind(const string &name, googlePlayApp &foundApp) {

// Implement this function

}

int main() {

ifstream inFile(FILENAME);

string inputLine, inputStr;

int linesRead = 0;

// Read in each app entry

while (getline(inFile, inputLine)) {

googlePlayApp newApp;

readSingleApp(inputLine, newApp);

appInsert(newApp);

linesRead++;

// For extra debugging output

//if (linesRead % 1000 == 0)

// cout << “Inserted ” << linesRead << ” entries”

// << endl;

}

if (linesRead == 0) {

cerr << “Reading failed.” << endl;

return (-1);

} else {

cout << “Read ” << linesRead << ” apps.” << endl;

}

for (;;) {

string tmp;

googlePlayApp foundApp;

cout << “Enter an app name (<return> to quit): “;

getline(cin, tmp);

if (tmp == “”) {

break;

}

if (appFind(tmp, foundApp) == false) {

cout << “Not found in the database.” << endl;

continue;

}

// Output the app info here

cout << “Name: ” << foundApp.name << endl;

// …

}

return (0);

}