Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

C++ program) Design a class for a sales person that has the following members va

ID: 3725876 • Letter: C

Question

C++ program)

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.

--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

  

Demonstrate the class in a program that creates a sales person object, and then calls each of the functions in the class.

--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.

Show your output and comments!

TotalAnnualSales Commission Percentage Under $10,000 No commission $10,000-$20,000 2% of TotalAnnualSales Greater than $20,000 4% of TotalAnnualSales

  

Explanation / Answer

#include <iostream>

#include <string>

using namespace std;

class SalesPerson

{

public:

SalesPerson(int eid, string fname, string lname, double sales)

{

EID = eid;

Firstname = fname;

Lastname = lname;

TotalAnnualSales = sales;

}

void setEID(int eid)

{

EID = eid;

}

void setFirstname(string fname)

{

Firstname = fname;

}

void setLastname(string lname)

{

Lastname = lname;

}

void setTotalAnnualSales(double sales)

{

TotalAnnualSales = sales;

}

int getEID()

{

return EID;

}

string getFirstname()

{

return Firstname;

}

string getLastname()

{

return Lastname;

}

double getTotalAnnualSales()

{

return TotalAnnualSales;

}

double calculateCommission()

{

if (TotalAnnualSales < 10000)

return 0;

else if (TotalAnnualSales < 20000)

return TotalAnnualSales * 0.02;

else

return TotalAnnualSales * 0.04;

}

void display()

{

cout << "EID: " << EID << ", Name: " << Firstname << " " << Lastname << ", TotalAnnualSales: " << TotalAnnualSales << ", Commssion: " << calculateCommission() << endl;

}

private:

int EID;

string Firstname;

string Lastname;

string Date;

double TotalAnnualSales;

};

void sort(SalesPerson *p[], int n)

{

for (int i = 0; i < n; i++)

{

for (int j = 0; j < n - i; j++)

{

if (p[i]->getFirstname() < p[j]->getFirstname())

{

SalesPerson *temp = p[i];

p[i] = p[j];

p[j] = temp;

}

}

}

}

int search(SalesPerson *p[], int l, int r, string fname)

{

while (l <= r)

{

int m = l + (r - l) / 2;

if (p[m]->getFirstname() == fname)

return m;

else if (p[m]->getFirstname() < fname)

l = m + 1;

else

r = m - 1;

}

return -1;

}

int main()

{

SalesPerson *persons[10];

int eid, n = 3;

string fname, lname;

double totalASales;

for (int i = 0; i < n; i++)

{

cout << "Employee ID: ";

cin >> eid;

cout << "Firstname: ";

cin >> fname;

cout << "Lastname: ";

cin >> lname;

cout << "Total Annual Sales: ";

cin >> totalASales;

persons[i] = new SalesPerson(eid, fname, lname, totalASales);

}

for (int i = 0; i < n; i++)

{

persons[i]->display();

}

sort(persons, n);

cout << " After sorting SalesPerson objects: " << endl;

for (int i = 0; i < n; i++)

{

persons[i]->display();

}

cout << "Enter firstname to search: ";

cin >> fname;

int ind = search(persons, 0, n - 1, fname);

if (ind == -1)

cout << fname << " not found";

else

persons[ind]->display();

}

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote