This is my first time posting here and I am doing so because I need a little help with an assignment I have for school..I am not asking for the answer but I would greatly appreciate a few hints to get me going in the right direction because after a while my brain just got overloaded and I got VERY confused....
I have done the first part of the question but I am having trouble with number 2..
This is the assignment:
1. Design a class for a sales person that has the following members variable:
EID: To holds the sales person’s employment ID
Firstname: To holds the sales person’s first name.
Lastname: To holds the sales person’s last name.
Date: To holds the sales person’s birth date
TotalAnnualSales: To holds the sales person’s total sales in a year.
In addition, the class should have the following member functions.
Constructor: The constructor should accept the sales person’s data as arguments and assign these values to the object’s member variables. (4 points)
Mutators: Appropriate mutator functions should be created to allow values to be set for each object’s data members.
Accessors: Appropriate accessor functions should be created to allow values to be retrieved from an object’s data members.
calculateCommission: This function should calculate and display the commission amount for a sales person based on his totalAnnualSales. See below.
TotalAnnualSales Commission percentage
Under $10,000 No commission
$10,000-$20,000 2% of TotalAnnualSales
Greater than $20,000 4% of TotalAnnualSales
Demonstrate the class in a program that creates a sales person object, and then calls each of the functions in the class.
2. With the sales person class design in question #1 above in hand, write a program
To have an array of sales person objects. The program should read and store information for each sales person in each of the object. It should then call a class function, once for each object, to display the sales person’s ToalAnnualSales amount and commission amount.
This program should use bubble sort to sort the array of sales person objects. It places sales person objects in ascending order by their first name.
Demonstrate the binary search method in this program to search by first name..
I am done with the first part of the question but I am having trouble making an array of objects....(How do i make my code look cool like it does in my compiler?)
//Class declaration
class SalesPerson
{
//private data members of class
private:
string EID;
string FirstName;
string LastName;
string Date;
double TotalAnnualSales;
//function to calculate comission
double calculateCommission();
void bubbleSort(string FirstName[], const int SIZE);
int binarySearch(const string FirstName[], int size, string nameSearch);
};//end of class declaration
//main start
int main ()
{
//declare variables
string EID;
string FirstName;
string LastName;
string Date;
string nameSearch;
int foundLocation;
double TotalAnnualSales;
double commission;
const int size=5;
//create an array for the objects
SalesPerson employees[size];
ofstream outputFile;
outputFile.open("work.txt");
for ( int i=0; i < size; i++)
{
//prompt user for salesperson information
cout<< "Enter sales person ID: "<<endl;
outputFile<< "Enter sales person ID: "<<endl;
cin>>EID;
cout<< "Enter first name: "<<endl;
outputFile<< "Enter first name: "<<endl;
cin>>FirstName;
cout<< "Enter last name: "<<endl;
outputFile << "Enter last name: "<<endl;
cin>>LastName;
cout<< "Enter date: "<<endl;
outputFile<< "Enter date: "<<endl;
cin>>Date;
cout << "Enter total annual sales: "<<endl;
cin >> TotalAnnualSales;
//create object of sales person class
SalesPerson person(EID, FirstName, LastName, Date, TotalAnnualSales);
//call function to calculate commission
commission = person.calculateCommission();
cout<<" Commission earned for "<<employees[i].getLastName()<<" "<<employees[i].getFirstName()<< " is "<<commission<<endl;
}
//ask user for information
cout<< " Please enter the person's name that you wish to find in my name data base "<<endl;
outputFile<<" Please enter the person's name that you wish to find in my name data base "<<endl;
// cin>>nameSearch;
getline(cin,nameSearch);
//this function preforms the binary search
int SalesPerson::binarySearch(const string employees[], int size, string nameSearch)
{
int first = 0,
last = size - 1,
middle,
position = -1;
bool found = false;
while (!found && first <= last)
{
middle = (first + last) / 2;
if (FirstName[middle] == nameSearch)
{
found = true;
position = middle;
}
else if (FirstName[middle] > nameSearch)
last = middle - 1;
else
first = middle + 1;
}
return position;
} ]