Question: In this programming assignment, youll identify the number of potential customers for a business. The starter program outputs the number of potential customers in a

In this programming assignment, youll identify the number of potential customers for a business. The starter program outputs the number of potential customers in a userentered age range given a file with peoples data. 1. Move the class Person to the separate files: person.h and person.cpp. Make sure you can still compile with separate files. 2. During file reading, the program isnt storing the gender or yearly income of the people. Instead, the default values are being printed. Fix the program to correctly set the data read from file. The regions of the code that need to be fixed are marked with: FIXME Also set gender and yearly income 3. Allow the user to select the potential customers gender: male, female, or any. The program should now output only potential customers with the userspecified gender and age. Update the GetUserInput function to prompt the user and store the users gender selection. Also, create a function GetPeopleWithSpecificGender that returns only people with the userspecified gender. Debugging suggestion: Use a function to print mains vector of Persons so that you can see who is in the vector after each function call. This technique may help debug the newly created function GetPeopleWithSpecificGender. 4. In addition to age and gender, allow the user to select the lower and upper range of a customers yearly income. Update the GetUserInput function to prompt the user and store the users specified range. Also, create a function GetPeopleInIncomeRange that returns only people with the userspecified yearly income. The main should now look like the following code: intmain(intargc,char*argv[]){ vectorpeople; boolhadError=false; intageLowerRange=0; intageUpperRange=0; stringgender=""; intyILowerRange=0; intyIUpperRange=0; hadError=ReadPeopleFromFile(argc,argv,people); if(hadError){ return1;//indicateserror } GetUserInput(ageLowerRange,ageUpperRange,gender,yILowerRange, yIUpperRange); people=GetPeopleInAgeRange(people,ageLowerRange,ageUpperRange); people=GetPeopleWithSpecificGender(people,gender); people=GetPeopleInIncomeRange(people,yILowerRange,yIUpperRange); cout<<" Numberofpotentialcustomers="< return0; } Here is an example program execution with people.txt (user input is highlighted here for clarity): Openingfilepeople.txt. Age=20,gender=male,yearlyincome=25000 Age=25,gender=male,yearlyincome=45000 Age=23,gender=male,yearlyincome=30000 Age=16,gender=male,yearlyincome=7000 Age=30,gender=male,yearlyincome=55000 Age=22,gender=female,yearlyincome=27000 Age=26,gender=female,yearlyincome=44000 Age=21,gender=female,yearlyincome=37000 Age=18,gender=female,yearlyincome=17000 Age=29,gender=female,yearlyincome=62000 Finishedreadingfile. Enterlowerrangeofage:24 Enterupperrangeofage:30 Entergender(male,female,orany):any Enterlowerrangeofyearlyincome:43000 Enterupperrangeofyearlyincome:57000 Numberofpotentialcustomers=3

Heres the code that needs to be modified

#include #include #include #include using namespace std;

class Item { public: void SetName(string nm) { name = nm; }; void SetQuantity(int qnty) { quantity = qnty; }; virtual void Print() { cout << name << " " << quantity << endl; }; virtual ~Item() { return; }; protected: string name; int quantity; };

class Produce : public Item { // Derived from Item class public: void SetExpiration(string expir) { expiration = expir; }; void Print() { cout << name << " x" << quantity << " (Expires: " << expiration << ")" << endl; }; private: string expiration; };

// Print all items in the inventory void PrintInventory(vector inventory);

// Dialogue to create a new item, then add that item to the inventory vector AddItemToInventory(vector inventory);

// Dialogue to update the quantity of an item, then update that item in the inventory vector UpdateItemQtyInInventory(vector inventory);

// Dialogue to remove a specific item, then remove that specific item from the inventory vector RemoveItemFromInventory(vector inventory);

int main() { vector inventory; string usrInptOptn = "default"; while (true) { // Get user choice cout << " Enter (p)rint, (a)dd, (u)pdate, (r)emove, or (q)uit: "; getline(cin, usrInptOptn);

// Process user choice if (usrInptOptn.size() == 0) { continue; } else if (usrInptOptn.at(0) == 'p') { PrintInventory(inventory); } else if (usrInptOptn.at(0) == 'a') { inventory = AddItemToInventory(inventory); } else if (usrInptOptn.at(0) == 'u') { inventory = UpdateItemQtyInInventory(inventory); } else if (usrInptOptn.at(0) == 'r') { inventory = RemoveItemFromInventory(inventory); } else if (usrInptOptn.at(0) == 'q') { cout << " Good bye." << endl; break; } }

return 0; }

void PrintInventory(vector inventory) { unsigned int i = 0; if (inventory.size() == 0) { cout << "No items to print." << endl; } else { for (i=0; iPrint(); } } return; }

vector AddItemToInventory(vector inventory) { Produce* prdc; string usrInptName = ""; string usrInptQntyStr = ""; istringstream inSS; int usrInptQnty = 0; string usrInptExpr = ""; cout << "Enter name of new produce: "; getline(cin, usrInptName); cout << "Enter quantity: "; getline(cin, usrInptQntyStr); inSS.str(usrInptQntyStr); inSS >> usrInptQnty; inSS.clear(); cout << "Enter expiration date: "; getline(cin, usrInptExpr); prdc = new Produce; prdc->SetName(usrInptName); prdc->SetQuantity(usrInptQnty); prdc->SetExpiration(usrInptExpr); inventory.push_back(prdc); return inventory; }

vector UpdateItemQtyInInventory(vector inventory) { string usrIndexChoiceStr = ""; unsigned int usrIndexChoice = 0; istringstream inSS; string usrInptQntyStr = ""; int usrInptQnty = 0; if (inventory.size() == 0) { cout << "No items to update." << endl; } else { PrintInventory(inventory); do { cout << "Update which item #: "; getline(cin, usrIndexChoiceStr); inSS.str(usrIndexChoiceStr); inSS >> usrIndexChoice; inSS.clear(); } while ( !(usrIndexChoice < inventory.size()) ); cout << "Enter new quantity: "; getline(cin, usrInptQntyStr); inSS.str(usrInptQntyStr); inSS >> usrInptQnty; inSS.clear(); inventory.at(usrIndexChoice)->SetQuantity(usrInptQnty); } return inventory; }

vector RemoveItemFromInventory(vector inventory) { istringstream inSS; string usrIndexChoiceStr = ""; unsigned int usrIndexChoice = 0; string usrInptQntyStr = ""; if (inventory.size() == 0) { cout << "No items to remove." << endl; } else { PrintInventory(inventory); do { cout << "Remove which item #: "; getline(cin, usrIndexChoiceStr); inSS.str(usrIndexChoiceStr); inSS >> usrIndexChoice; inSS.clear(); } while ( !(usrIndexChoice < inventory.size()) ); inventory.erase( inventory.begin() + usrIndexChoice ); } return inventory; }

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!