Homework Help Question & Answers

//Need help ASAP in c++ please. Appreciate it! Thank you!! //This is the current code I have. #include <iostream> #include <sstream> #include <iomanip> using namespace std; cl...

//Need help ASAP in c++ please. Appreciate it! Thank you!!

//This is the current code I have.

#include <iostream>

#include <sstream>

#include <iomanip>

using namespace std;

class googlePlayApp {

private:

string name;

double rating;

int numInstalls;

int numReviews;

double price;

  

public:

googlePlayApp(string, double, int, int, double);

~ googlePlayApp();

googlePlayApp();

  

string getName();

double getRating();

int getNumInstalls();

int getNumReviews();

string getPrice();

  

void setName(string);

void setRating(double);

void setNumInstalls(int);

void setNumReviews(int);

void setPrice(double);

};

googlePlayApp::googlePlayApp(string n, double r, int ni, int nr, double pr) {

name = n;

rating = r;

numInstalls = ni;

numReviews = nr;

price = pr;

//cout << "In the constructor with arguments" << endl;

}

googlePlayApp::googlePlayApp() {

name = "No Name App";

rating = 0;

numInstalls = 0;

numReviews = 0;

price = 0;

//cout << "In the default constructor" << endl;

}

googlePlayApp::~googlePlayApp() {

}

string googlePlayApp::getName() {

return name;

}

double googlePlayApp::getRating() {

return rating;

}

int googlePlayApp::getNumInstalls() {

return numInstalls;

}

int googlePlayApp::getNumReviews(){

return numReviews;

}

string googlePlayApp::getPrice() {

if(price == 0.0)

return "Free";

  

else {

double p = price;

stringstream st;

st << fixed << setprecision(2) << p;

string s = st.str();

return ("$" + s);

}

}

void googlePlayApp::setName(string n) {

name = n;

}

void googlePlayApp::setRating(double r) {

rating = r;

}

void googlePlayApp::setNumInstalls(int ni) {

numInstalls = ni;

}

void googlePlayApp::setNumReviews(int re) {

numReviews = re;

}

void googlePlayApp::setPrice(double p) {

price = p;

}

int main() {

googlePlayApp App1("Whatsapp", 4.5,100000000, 49897441,0.0);

cout << "Name: " << App1.getName() << endl;

if(App1.getNumInstalls() > 1000000) {

cout << "Number of installs:1M+ " << endl;

}

else

cout << "Number of installs: " << App1.getNumInstalls() << endl;

cout << "Rating : " << App1.getRating() << endl;

cout << "Price : " << App1.getPrice() << endl;

cout << "Number of reviews: " << App1.getNumReviews() << endl;

googlePlayApp App2("PicsArt", 4.7, 1009800000, 4997441, 4.99);

cout << "Name: " << App2.getName() << endl;

if(App2.getNumInstalls() > 1000000) {

cout<<"Number of installs:1M+ "<<endl;

}

else

cout << "Number of installs: " << App2.getNumInstalls() << endl;

cout << "Rating : " << App2.getRating() << endl;

cout << "Price : " << App2.getPrice() << endl;

cout << "Number of reviews: " << App2.getNumReviews() << endl;

googlePlayApp App3("Oxford Dictionary", 4.8, 100000, 50000, 6.99);

cout << "Name: " << App3.getName() << endl;

if(App3.getNumInstalls() > 1000000) {

cout << "Number of installs:1M+ " << endl;

}

else

cout << "Number of installs: " << App3.getNumInstalls() << endl;

cout << "Rating : " << App3.getRating() << endl;

cout << "Price : " << App3.getPrice() << endl;

cout << "Number of reviews: " << App3.getNumReviews() << endl;

}

/And these following needs to be incorporated into it. Any help would be appreciated. In C++.Thank you

Your class implementation from Lab #10 should have at least these fields, with setters and getters for all:

name
rating
numInstalls
numReviews
price
Assignment:

The supplied file - apps.csvPreview the document - has a list of 25 actual Google Play apps in a common file format called CSV (Comma-Separated Values). This is a text file that has a series of lines representing rows and columns. Each line is a row with a series of column values, separated by a comma (,). The order of the fields in the file is as follows:

name, category, rating, numInstalls, numReviews, price

All of these fields should be in your googlePlayApp class already, except for category, which should be a string. Add that field to the class and the constructor with arguments, including setters/getters.

We will review an example way of processing a CSV file in class.

Read the supplied CSV file as input with one app. per line, and store each entry in a dynamic structure (a dynamic array -- not a fixed-size array -- or a vector). Each class should be allocated based on a single line in the file.

After the file has been read, go into an "app directory" loop and prompt the user for an application name. If there is a match for that name in the list, print out that the information for that app.

Requirements:

1) The CSV file must be read as input and any app. should be queryable. No hard-coded arrays of strings, etc. will be accepted.

2) Allocate each googlePlayApp dynamically based on each entry in the file.

3) Use any search algorithm to find the name. Linear search (walking through the array, checking for a match, until the end or a match is found) is OK.

4) Print all of the info about the app (the above fields, including category, and the special formatting of 'price') using the 'getter' methods.

5) If the user enters a name that is not found, output 'Name not found' or similar. Continue in the loop until some sentinel value is read (such as a blank line, or an 'X', etc.), then exit.

//apps.csv:

Photo Editor Selfie Camera Filter & Mirror

Image,PHOTOGRAPHY,4.3,922444,527247,0.0

Little Fire Station,FAMILY,4.2,8293,3762,0.0

Mercari: The Selling App,SHOPPING,4.4,203841,101883,1.99

My Android Device S/W & H/W,FAMILY,4.5,889,681,1.99

Sleep as Android Gear Addon,HEALTH_AND_FITNESS,2.8,4299,961,4.99

Girls hairstyles 2018,BEAUTY,4.2,423,62,0.0

Calendar Widget Month + Agenda,PRODUCTIVITY,4.2,72042,60840,4.99

EZ App Installer,TOOLS,4.1,4924,533,4.99

Bleacher Report Live,SPORTS,4.0,3322,232,2.99

Access Point Names,COMMUNICATION,4.0,993,138,0.99

Helix Jump,GAME,4.2,2498552,1498648,0.99

Mail1Click - Secure Mail,COMMUNICATION,4.1,432,255,4.99

Fidget Spinner,GAME,4.2,429394,307398,0.0

Listen and learn English in seven days,EDUCATION,4.3,9342,1516,1.99

Insightly CRM,BUSINESS,3.8,2035,1383,0.99

Questland: Turn Based RPG,FAMILY,4.6,55225,31134,0.99

AV High School District,FAMILY,3.5,224,91,9.99

TFO BZ Lessons,FAMILY,4.4,596,75,0.99

X Launcher: With OS11 Style Theme & Control

Center,ART_AND_DESIGN,4.7,75662,5754,0.99

HD Video Player,VIDEO_PLAYERS,4.3,7234,1551,0.99

Hangouts,COMMUNICATION,4.0,4419350,3419249,0.00

HTC Sense Input-CA,TOOLS,3.1,441,124,0.00

Moto Z Market,TOOLS,2.2,702,605,0.99

Greater London A-Z 2016,TRAVEL_AND_LOCAL,3.7,800,40,0.00

AP Government Review,FAMILY,4.7,44,3,0.00

Example output:

Read 25 apps.
Please enter an application name (X to quit): Little Fire Station

Name: Little Fire Station
Category: FAMILY
Rating: 4.2
Number of installs: 8293
Number of reviews: 3762
Price: Free

Please enter an application name (X to quit): Moto Z Market

Name: Moto Z Market
Category: TOOLS
Rating: 2.2
Number of installs: 702
Number of reviews: 605
Price: 0.99

Please enter an application name (X to quit): Nonexistent app
Application not found.
Please enter an application name (X to quit): X
0 0
Next > < Previous
ReportAnswer #1

// C++ program to create a class googlePlayApp

#include <iostream>

#include <sstream>

#include <iomanip>

#include <fstream>

using namespace std;

class googlePlayApp {

private:

               string name;

               string category;

               double rating;

               int numInstalls;

               int numReviews;

               double price;

public:

               googlePlayApp(string,string, double, int, int, double);

               ~ googlePlayApp();

               googlePlayApp();

               string getName();

               string getCategory();

               double getRating();

               int getNumInstalls();

               int getNumReviews();

               string getPrice();

               void setName(string);

               void setRating(double);

               void setNumInstalls(int);

               void setNumReviews(int);

               void setPrice(double);

               void setCategory(string);

};

googlePlayApp::googlePlayApp(string n,string c, double r, int ni, int nr, double pr) {

               name = n;

               category = c;

               rating = r;

               numInstalls = ni;

               numReviews = nr;

               price = pr;

}

googlePlayApp::googlePlayApp() {

               name = "No Name App";

               category = "No category";

               rating = 0;

               numInstalls = 0;

               numReviews = 0;

               price = 0;

}

googlePlayApp::~googlePlayApp() {

}

string googlePlayApp::getName() {

               return name;

}

string googlePlayApp::getCategory()

{

               return category;

}

double googlePlayApp::getRating() {

               return rating;

}

int googlePlayApp::getNumInstalls() {

               return numInstalls;

}

int googlePlayApp::getNumReviews(){

               return numReviews;

}

string googlePlayApp::getPrice() {

               if(price == 0.0)

                              return "Free";

               else {

                              double p = price;

                              stringstream st;

                              st << fixed << setprecision(2) << p;

                              string s = st.str();

                              return ("$" + s);

               }

}

void googlePlayApp::setName(string n) {

               name = n;

}

void googlePlayApp::setRating(double r) {

               rating = r;

}

void googlePlayApp::setNumInstalls(int ni) {

               numInstalls = ni;

}

void googlePlayApp::setNumReviews(int re) {

               numReviews = re;

}

void googlePlayApp::setPrice(double p) {

               price = p;

}

void googlePlayApp::setCategory(string c)

{

               category = c;

}

int main() {

               ifstream fin("apps.csv"); // provide full path to file

               googlePlayApp **apps; // create a dynamic array of googlePlayApp objects

               int n;

               string line;

               string name;

               string category;

               double rating;

               int numInstalls;

               int numReviews;

               double price;

               bool found;

               // if file can be openend

               if(fin.is_open())

               {

                              n=0;

                              // read till end of file, counting the number of records in file

                              while(!fin.eof())

                              {

                                             getline(fin,line);

                                             n++;

                              }

                              fin.close(); //close the file

                              apps = new googlePlayApp*[n]; // allocate array for googlePlayApp pointer objects

                              fin.open("apps.csv"); //re-open the file

                              int i=0;

                              int index;

                              // read the records in the array reading the file till the end

                              while(!fin.eof())

                              {

                                             getline(fin,line);

                                             line = line.substr(0,line.length()-1);

                                             index = 0;

                                             name = line.substr(index,line.find(','));

                                             index = line.find(',',index+1);

                                             category = line.substr(index+1,line.find(',',index+1)-(index+1));

                                             index = line.find(',',index+1);

                                             stringstream ratingStr(line.substr(index+1,line.find(',',index+1)-(index+1)));

                                             ratingStr>>rating;

                                             index = line.find(',',index+1);

                                             stringstream installsStr(line.substr(index+1,line.find(',',index+1)-(index+1)));

                                             installsStr>>numInstalls;

                                             index = line.find(',',index+1);

                                             stringstream reviewsStr(line.substr(index+1,line.find(',',index+1)-(index+1)));

                                             reviewsStr>>numReviews;

                                             index = line.find(',',index+1);

                                             stringstream priceStr(line.substr(index+1));

                                             priceStr>>price;

                                             apps[i] = new googlePlayApp(name,category,rating,numInstalls ,numReviews ,price);

                                             i++;

                              }

                              fin.close();

                              // output the number of apps read

                              cout<<"Read "<<n<<" apps"<<endl;

                              // loop that continue till the user wants

                              do

                              {

                                             found = false;

                                             // input the application name

                                             cout<<"\nPlease enter an application name (X to quit): ";

                                             getline(cin,line);

                                             line = line.substr(0,line.length()-1);

                                             // check if user wants to quit

                                             if((line.compare("x") == 0) || (line.compare("X") == 0))

                                                            break;

                                             // loop to find the application in the array, if found print the details

                                             for(i=0;i<n;i++)

                                             {

                                                            if(line.compare(apps[i]->getName()) == 0)

                                                            {

                                                                           found = true;

                                                                           cout<<"Name : "<<apps[i]->getName()<<endl;

                                                                           cout<<"Category : "<<apps[i]->getCategory()<<endl;

                                                                           cout<<"Rating: "<<apps[i]->getRating()<<endl;

                                                                           cout<<"Number of installs: "<<apps[i]->getNumInstalls()<<endl;

                                                                           cout<<"Number of reviews: "<<apps[i]->getNumReviews()<<endl;

                                                                           cout<<"Price: "<<apps[i]->getPrice()<<endl;

                                                            }

                                             }

                                             if(!found)

                                                            cout<<"Application not found."<<endl;

                              }while((line.compare("X") != 0) && (line.compare("x") != 0));

                              // release the memory allocated for the objects

                              for(int i=0;i<n;i++)

                                             delete(apps[i]);

                              delete []apps;

               }

               return 0;

}

//end of program

Output:

Input file:

Output:

Read 25 apps Please enter an application name (X to quit): Little Fire Station NameLittle Fire Station Category FAMILY Rating

Add Homework Help Answer
Add Answer of:
//Need help ASAP in c++ please. Appreciate it! Thank you!! //This is the current code I have. #include <iostream> #include <sstream> #include <iomanip> using namespace std; cl...
Your Answer: Your Name: What's your source?
Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
More Homework Help Questions Additional questions in this topic.
Need Online Homework Help?
Ask a Question
Get FREE Expert Answers
WITHIN MINUTES
Related Questions