Question: Classes/Streams - Marketing software ( Starter code is provided in the end) In this programming assignment, youll identify the number of potential customers for a
Classes/Streams - Marketing software ( Starter code is provided in the end)
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:
int main(int argc, char* argv[]){
vector
bool hadError = false ;
int ageLowerRange = 0 ;
int ageUpperRange = 0 ;
string gender = " " ;
int yILowerRange = 0 ;
int yIUpperRange = 0 ;
hadError = ReadPeopleFromFile ( argc, argv, people) ;
if( hadError ) {
return 1; //indicateserror
}
GetUserInput( ageLowerRange, ageUpperRange, gender, yILowerRange, yIUpperRange ) ; people = GetPeopleInAgeRange( people, ageLowerRange, ageUpperRange ) ; people = GetPeopleWithSpecificGender( people, gender ) ; people = GetPeopleInIncomeRange( people, yILowerRange, yIUpperRange ) ; cout << " Number of potential customers = " << people.size( ) << endl; return0; }
Here is an example program execution with people.txt (user input is highlighted here for clarity):
Opening file people.txt.
Age = 20, gender = male, yearly income = 25000
Age = 25, gender = male, yearly income = 45000
Age = 23, gender = male, yearly income = 30000
Age = 16, gender = male, yearly income = 7000
Age = 30, gender = male, yearly income = 55000
Age = 22, gender = female, yearly income = 27000
Age = 26, gender = female, yearly income = 44000
Age = 21, gender = female, yearly income = 37000
Age = 18, gender = female, yearly income = 17000
Age = 29, gender = female, yearly income = 62000
Finished reading file.
Enter lower range of age: 24
Enter upper range of age: 30
Enter gender (male, female, or any): any
Enter lower range of yearly income: 43000
Enter upper range of yearly income: 57000
Number of potential customers = 3
here is the starter quiz
#include
// Define a Person class, including age, gender, and yearlyIncome. class Person { public: Person(); void Print(); void SetData(int a); // FIXME Also set gender and yearly income int GetAge(); private: int age; string gender; int yearlyIncome; };
// Constructor for the Person class. Person::Person() { age = 0; gender = "default"; yearlyIncome = 0; return; }
// Print the Person class. void Person::Print() { cout << "Age = " << this->age << ", gender = " << this->gender << ", yearly income = " << this->yearlyIncome << endl; return; }
// Set the age, gender, and yearlyIncome of a Person. void Person::SetData(int a) { // FIXME Also set gender and yearly income this->age = a; return; }
// Get the age of a Person. int Person::GetAge() { return this->age; }
// Get a filename from program arguments, then make a Person for each line in the file. bool ReadPeopleFromFile(int argc, char* argv[], vector
// Ask user to enter age range. void GetUserInput(int &ageLowerRange, int&ageUpperRange) { cout<<" Enter lower range of age: "; cin >> ageLowerRange; cout << "Enter upper range of age: "; cin >> ageUpperRange; return; }
// Return people within the given age range. vector
int main(int argc, char* argv[]) { vector Here is a copy of my code. Can anyone show me how to fix it and what to do? (C++) #include // Define a Person class, including age, gender, and yearlyIncome. class Person { public: Person(); void Print(); void SetData(int a); // FIXME Also set gender and yearly income int GetAge(); void setGender(string gender); void setIncome( int income); private: int age; string gender; int yearlyIncome; }; // Constructor for the Person class. Person::Person() { age = 0; gender = "default"; yearlyIncome = 0; return; } // Print the Person class. void Person::Print() { cout << "Age = " << this->age << ", gender = " << this->gender << ", yearly income = " << this->yearlyIncome << endl; return; } // Set the age, gender, and yearlyIncome of a Person. void Person::SetData(int a) { // FIXME Also set gender and yearly income this->age = a; return; } string Person::setGender(string gen){ this->gender = gen; return; } int Person::getYearlyIncome() { this->yearlyIncome = salary; return; } void Person::setIncome(int income) { this->yearlyIncome = income; return; } // Get the age of a Person. int Person::GetAge() { return this->age; } void Person::setAge(int a) { this->age = age; return; } // Get a filename from program arguments, then make a Person for each line in the file. bool ReadPeopleFromFile(int argc, char* argv[], vector // Ask user to enter age range. void GetUserInput(int &ageLowerRange, int&ageUpperRange) { cout<<" Enter lower range of age: "; cin >> ageLowerRange; cout << "Enter upper range of age: "; cin >> ageUpperRange; return; } // Return people within the given age range. vector //Return people within the given gender. vector //Return people within the given gender. vector int main(int argc, char* argv[]) { vector
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
