Question

//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
Add a comment Improve this question Transcribed image text
Answer #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 a comment
Know the answer?
Add Answer to:
//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:

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
  • CODES: main.cpp #include <iostream> #include <string> #include "ShoppingCart.h" using namespace std; char PrintMenu() { char answer;...

    CODES: main.cpp #include <iostream> #include <string> #include "ShoppingCart.h" using namespace std; char PrintMenu() { char answer; cout << "MENU" << endl; cout << "a - Add item to cart" << endl; cout << "d - Remove item from cart" << endl; cout << "c - Change item quantity" << endl; cout << "i - Output items' descriptions" << endl; cout << "o - Output shopping cart" << endl; cout << "q - Quit" << endl << endl; while (true) {...

  • PLEASE HELP WITH THE FIX ME'S #include #include #include #include "CSVparser.hpp" using namespace std; //==...

    PLEASE HELP WITH THE FIX ME'S #include #include #include #include "CSVparser.hpp" using namespace std; //============================================================================ // Global definitions visible to all methods and classes //============================================================================ // forward declarations double strToDouble(string str, char ch); // define a structure to hold bid information struct Bid { string bidId; // unique identifier string title; string fund; double amount; Bid() { amount = 0.0; } }; //============================================================================ // Linked-List class definition //============================================================================ /** * Define a class containing data members and methods to *...

  • Need to implement Account.cpp and AccountManager.cpp code //Account.hpp #ifndef _ACCOUNT_HPP_ #define _ACCOUNT_HPP_ #include <string> using std::string;...

    Need to implement Account.cpp and AccountManager.cpp code //Account.hpp #ifndef _ACCOUNT_HPP_ #define _ACCOUNT_HPP_ #include <string> using std::string; class Account { public: Account(); Account(string, double); void deposit(double); bool withdraw(double); string getName() const; double getBalance() const; private: string name; double balance; }; #endif ////////////////////////////////////////////// //AccountManager.hpp #ifndef _ACCOUNT_MANAGER_HPP_ #define _ACCOUNT_MANAGER_HPP_ #include "Account.hpp" #include <string> using std::string; class AccountManager { public: AccountManager(); AccountManager(const AccountManager&); //copy constructor void open(string); void close(string); void depositByName(string,double); bool withdrawByName(string,double); double getBalanceByName(string); Account getAccountByName(string); void openSuperVipAccount(Account&); void closeSuperVipAccount(); bool getBalanceOfSuperVipAccount(double&) const;...

  • #include<iostream> #include<string> #include<iomanip> using namespace std; /* ********* Class Car ************* ********************************* */ class Car {...

    #include<iostream> #include<string> #include<iomanip> using namespace std; /* ********* Class Car ************* ********************************* */ class Car { private: string reportingMark; int carNumber; string kind; bool loaded; string choice; string destination; public: Car() { reportingMark = ""; carNumber = 0; kind = "Others"; loaded = 0; destination = "NONE"; } ~Car() { } void setUpCar(string &reportingMark, int &carNumber, string &kind, bool &loaded, string &destination); }; void input(string &reportingMark, int &carNumber, string &kind, bool &loaded,string choice, string &destination); void output(string &reportingMark, int &carNumber,...

  • please help me fix the error in here #include<iostream> #include <string> using namespace std; string getStudentName();...

    please help me fix the error in here #include<iostream> #include <string> using namespace std; string getStudentName(); double getNumberExams(); double getScoresAndCalculateTotal(double E); double calculateAverage(double n, double t); char determineLetterGrade(); void displayAverageGrade(); int main() { string StudentName; double NumberExam, Average, ScoresAndCalculateTotal; char LetterGrade; StudentName = getStudentName(); NumberExam = getNumberExams(); ScoresAndCalculateTotal= getScoresAndCalculateTotal(NumberExam); Average = calculateAverage(NumberExam, ScoresAndCalculateTotal); return 0; } string getStudentName() { string StudentName; cout << "\n\nEnter Student Name:"; getline(cin, StudentName); return StudentName; } double getNumberExams() { double NumberExam; cout << "\n\n Enter...

  • I need help with this code: #include <iostream> #include <cstdlib> #include <string> using namespace std; void...

    I need help with this code: #include <iostream> #include <cstdlib> #include <string> using namespace std; void dump(int ar[], int size) { cout << "\nDUMP [ "; for (int i=0; i<=size; i++) { cout << ar[i] << " "; } cout << "]\n\n"; } void quicksort(int ar[], int start, int end) { cout << "TOP OF SORT ===========================" << endl; dump(ar, start, end); int pivot = ar[end]; int left = start; int right = end - 1; int tmp; cout <<...

  • USING THIS CODE: #include <iostream> #include <string> using namespace std; class Contact { //this class cannot...

    USING THIS CODE: #include <iostream> #include <string> using namespace std; class Contact { //this class cannot be viewed from outside of the private class. //only the class functions within the class can access private members. private: string name; string email; string phone; //the public class is accessible from anywhere outside of the class //however can only be within the program. public: string getName() const { return name; } void setName(string name) { this->name = name; } string getEmail() const {...

  • #include <iostream> #include <string> #include <fstream> #include <sstream> using namespace std; struct transition{ // transition structure...

    #include <iostream> #include <string> #include <fstream> #include <sstream> using namespace std; struct transition{ // transition structure char start_state, to_state; char symbol_read; }; void read_DFA(struct transition *t, char *f, int &final_states, int &transitions){ int i, j, count = 0; ifstream dfa_file; string line; stringstream ss; dfa_file.open("dfa.txt"); getline(dfa_file, line); // reading final states for(i = 0; i < line.length(); i++){ if(line[i] >= '0' && line[i] <= '9') f[count++] = line[i]; } final_states = count; // total number of final states // reading...

  • I need a detailed pseudocode for this code in C ++. Thank you #include <iostream> #include...

    I need a detailed pseudocode for this code in C ++. Thank you #include <iostream> #include <string> #include <iomanip> using namespace std; struct Drink {    string name;    double cost;    int noOfDrinks; }; void displayMenu(Drink drinks[], int n); int main() {    const int size = 5;       Drink drinks[size] = { {"Cola", 0.65, 2},    {"Root Beer", 0.70, 1},    {"Grape Soda", 0.75, 5},    {"Lemon-Lime", 0.85, 20},    {"Water", 0.90, 20} };    cout <<...

  • C++ Language I have a class named movie which allows a movie object to take the...

    C++ Language I have a class named movie which allows a movie object to take the name, movie and rating of a movie that the user inputs. Everything works fine but when the user enters a space in the movie's name, the next function that is called loops infinetly. I can't find the source of the problem. Down below are my .cpp and .h file for the program. #include <iostream> #include "movie.h" using namespace std; movie::movie() { movieName = "Not...

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