// 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:
//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...
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; //============================================================================ // 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 *...
This is C++ code for parking fee management program #include <iostream> #include <iomanip> using namespace std; void input(char& car, int& ihour,int& imin, int& ohour, int& omin); void time(char car, int ihour, int imin, int ohour, int omin, int& phour, int& pmin, int& round, double& total); void parkingCharge (char car, int round, double& total); void print(char car, int ihour, int imin, int ohour, int omin, int phour, int pmin, int round, double total); int main() { char car; int ihour; int...
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 { 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(); 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 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 <<...
#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...
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 {...
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 <<...