Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

1. The first step would be to do this coding assignment and send the answer back

ID: 3920068 • Letter: 1

Question

1. The first step would be to do this coding assignment and send the answer back for review.

2. Feel free to code in any language you prefer.

3. Please include a quick summary of your thought process of your code and the efficiency of your solution.

Suppose you're building a Yelp competitor, and now want to implement your version of Review Highlights.

"The Review Highlights feature was built to help consumers quickly discover the core elements, attractions, menu items, or other popular offerings that a business may be known for. The highlights reflect overall trends we see in the words or phrases that Yelpers use in their reviews of the business, which reduces the consumer's task of reading dozens (or even hundreds) of reviews."

Write a function with this signature:

def review_highlights(reviews, max)

# Arguments:

# * reviews is an array of strings

# * max is the maximum number of review highlights to return

#

# Returns an array of 0 to max review highlights

For example, given the following reviews:

? "I Love their falafel sandwiches, go early there is always line at lunchtime during the week, but it goes pretty quick.",

? "I've also had the gyros sandwich, which I honestly have only had once. Like I said previously, the falafel sandwich is just too good. What's different about Falafel Drive-In's gyros is that the meat is cubed--not sliced. I also like the seasoning used for the gyros meat.",

? "Falafel's Drive-In is one popular place--its menu is a cross between Middle East-inspired street food and American classics (hot dogs and the like).",

? "The food itself was fine. We ordered one of the specials, a large falafel sandwich and banana shake, a large side of fries, and then a falafel salad. The falafel itself really is great and with the red sauce on the side, it is awesome. However, the salad was just really plain and bland."

Some possible review highlights might be:

? "falafel sandwich"

? "I Love their falafel sandwiches, go early there is always line at lunchtime during the week, but it goes pretty quick."

These are just examples. There are no right or wrong review highlights! We've purposely left this more open to see how you think.

The solution can be in any language. Send your source files, and provide instructions to build an executable named rh (if you've used a compiled language), or provide a script named rh (if it's an interpreted language).

rh should expect two arguments:

? the first argument is the path to a file containing one review per line (i.e., each review is " " delimited)

? the second argument is the maximum number of review highlights to return rh should print one review highlight per line (" " delimited"). For example:

$ cat ~/reviews.txt

I Love their falafel sandwiches, go early there is always line at lunchtime during the week, but it goes pretty quick.,

I've also had the gyros sandwich, which I honestly have only had once. Like I said previously, the falafel sandwich is just too good. What's different about Falafel

Drive-In's gyros is that the meat is cubed--not sliced. I also like the seasoning used for the gyros meat.,

Falafel's Drive-In is one popular place--its menu is a cross between Middle East-inspired street food and American classics (hot dogs and the like).,

The food itself was fine. We ordered one of the specials, a large falafel sandwich and banana shake, a large side of fries, and then a falafel salad. The falafel itself really is great and with the red sauce on the side, it is awesome. However, the salad was just really plain and bland.

$ ./rh ~/reviews.txt 2

falafel sandwich

I Love their falafel sandwiches, go early there is always line at lunchtime during the week, but it goes pretty quick.

Explanation / Answer

// Using c++

#include <iostream>

#include <string>

#include <fstream>

#include <stdlib.h>

#define MAX 50

using namespace std;

// Function to read file contents and stores it in parameter string array and returns number of reviews

int readFile(string review[])

{

// ifstream object declared

ifstream fRead;

// For index position

int index = 0;

// Opens the file for reading

fRead.open("reviews.txt");

// Checks if the file unable to open for reading display's error message with file name

if(!fRead)

{

cout<<" ERROR: Unable to open the file ";

exit(0);

}// End of if condition

// Loops till end of the file

while(!fRead.eof())

{

// Reads one string at a time from the file and stores it in index position of review

getline(fRead, review[index]);

// Increase the index by one

index++;

}// End of while loop

// Returns the number of reviews

return index;

}// End of function

// Function to return number of reviews passed as max parameter

string *review_highlights(string reviews[], int max)

{

// To store the max reviews passed as parameter

// Dynamically allocates memory of size max

string *result = new string [max];

// Loops till max

for(int c = 0; c < max; c++)

// Stores the current index position of the review in result current index position

result[c] = reviews[c];

// Returns the review

return reviews;

}// End of function

// main function definition

int main()

{

// To store number of reviews to see

int no;

// To store reviews read from file

string review[MAX];

// Calls the function to read file and stores it in review

// and stores number of reviews in count

int count = readFile(review);

// Accepts number of reviews to see from the user

printf(" Enter how many reviews you want to see (maximum %d)? ", count);

cin>>no;

// Calls the function to return number of reviews entered by the user

// and stores it in result

string *result = review_highlights(review, no);

cout<<" Reviews for falafel sandwich: ";

// Loops till number of reviews entered by the user

for(int c = 0; c < no; c++)

// Display each review

cout<<result[c]<<endl<<endl;

}// End of main function

Sample Output;

Enter how many reviews you want to see (maximum 7)? 3

Reviews for falafel sandwich:
I Love their falafel sandwiches, go early there is always line at lunchtime during the week, but it goes pretty quick.

I've also had the gyros sandwich, which I honestly have only had once. Like I said previously, the falafel sandwich is just too good. What's different about Falafel Drive-In's gyros is that the meat is cubed--not sliced. I also like the seasoning used for the gyros meat.

Falafel's Drive-In is one popular place--its menu is a cross between Middle East-inspired street food and American classics (hot dogs and the like).

reviews.txt file contents

I Love their falafel sandwiches, go early there is always line at lunchtime during the week, but it goes pretty quick.
I've also had the gyros sandwich, which I honestly have only had once. Like I said previously, the falafel sandwich is just too good. What's

different about Falafel Drive-In's gyros is that the meat is cubed--not sliced. I also like the seasoning used for the gyros meat.
Falafel's Drive-In is one popular place--its menu is a cross between Middle East-inspired street food and American classics (hot dogs and the like).
The food itself was fine. We ordered one of the specials, a large falafel sandwich and banana shake, a large side of fries, and then a falafel salad. The falafel itself really is great and with the red sauce on the side, it is awesome. However, the salad was just really plain and bland..

I like it but it is not better than Indian chiken butter masala.

Falafel sandwiches is good for lunch for not suitable for dinner.
If you want biriyani then Falafel sandwiches is good.