c++ Design a class for a sales person that has the following members variable: E
ID: 3731418 • Letter: C
Question
c++
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. ( 8 points)
Accessors: Appropriate accessor functions should be created to allow values to be retrieved from an object’s data members. (8 points)
calculateCommission: This function should calculate and display the commission amount for a sales person based on his totalAnnualSales. See below. (5 points)
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.
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. (8 points)
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. (6 points)
Demonstrate the binary search method in this program to search by first name. (6 points)
TotalAnnualSales
Commission percentage
Under $10,000
No commission
$10,000-$20,000
2% of TotalAnnualSales
Greater than $20,000
4% of TotalAnnualSales
Explanation / Answer
/******************************************************************************
Online C++ Compiler.
Code, Compile, Run and Debug C++ program online.
Write your code in this editor and press "Run" button to compile and execute it.
*******************************************************************************/
#include <iostream>
#include <string.h>
#include <ctime>
#include<conio.h>
using namespace std;
class SalesPerson
{
private:
int m_eID;
string m_firstName, m_lastName;
time_t m_dateOfBirth;
float m_totalAnnualSales;
public:
// Constructor
SalesPerson()
{
}
SalesPerson(int eID, string firstName, string lastName, time_t dateOfBirth, float totalAnnualSales)
{
this->m_eID = eID;
this->m_firstName = firstName;
this->m_lastName = lastName;
this->m_dateOfBirth = dateOfBirth;
this->m_totalAnnualSales = totalAnnualSales;
}
// Mutators
void SetEID(int eID)
{
m_eID = eID;
}
void SetFirstName(string firstName)
{
m_firstName = firstName;
}
void SetLastName(string lastName)
{
m_lastName = lastName;
}
void SetDateOfBirth(time_t dateOfBirth)
{
m_dateOfBirth = dateOfBirth;
}
void SetTotalAnnualSales(float totalAnnualSales)
{
m_totalAnnualSales = totalAnnualSales;
}
//Accessors
int GetEID() const
{
return m_eID;
}
string GetFirstName() const
{
return m_firstName;
}
string GetLastName() const
{
return m_lastName;
}
time_t GetDateOfBirth() const
{
return m_dateOfBirth;
}
float GetTotalAnnualSales() const
{
return m_totalAnnualSales;
}
float CalculateCommission()
{
float commission = 0;
if(m_totalAnnualSales>= 10000 && m_totalAnnualSales <= 20000)
{
commission = m_totalAnnualSales*2/100;
}
else if(m_totalAnnualSales > 20000)
{
commission = m_totalAnnualSales*4/100;
}
return commission;
}
};
int main()
{
// 1st task
time_t rawtime;
struct tm * dateOfBirthInfo;
time ( &rawtime );
dateOfBirthInfo = localtime ( &rawtime );
dateOfBirthInfo->tm_year = 1992-1900;
dateOfBirthInfo->tm_mon = 2-1;
dateOfBirthInfo->tm_mday = 13;
//making the object
SalesPerson salesPerson(1, "Tom", "Cruise", mktime ( dateOfBirthInfo ),12000);
// calling each functions
salesPerson.SetEID(2);
salesPerson.SetFirstName("Mark");
salesPerson.SetLastName("Taylor");
salesPerson.SetDateOfBirth(mktime ( dateOfBirthInfo ));
salesPerson.SetTotalAnnualSales(14000);
cout<<"EID = "<<salesPerson.GetEID()<<endl;
cout<<"First Name = "<<salesPerson.GetFirstName()<<endl;
cout<<"Last Name = "<<salesPerson.GetLastName()<<endl;
time_t n = salesPerson.GetDateOfBirth();
cout<<"Date of birth = "<<ctime(&n)<<endl;
cout<<"Total annual sales = "<<salesPerson.GetTotalAnnualSales()<<endl;
cout<<"Commission = "<<salesPerson.CalculateCommission()<<endl;
//2 task
cout<<"2 nd task"<<endl;
int c;
cout<<"Press number of SalesPerson to add"<<endl;
cin>>c;
SalesPerson* s = new SalesPerson[c];
int counter = 0;
while(counter<c)
{
int eID;
cout<<"Enter the sales person ID"<<endl;
cin>> eID;
string fName;
cout<<"Enter the sales person First Name"<<endl;
cin>> fName;
string lName;
cout<<"Enter the sales person Last Name"<<endl;
cin>> lName;
int yyyy;
cout<<"Enter the Date of birth.....Year (Format YYYY)"<<endl;
cin>> yyyy;
int mm;
cout<<"Enter the Date of birth.......Month (Format MM)"<<endl;
cin>> mm;
int dd;
cout<<"Enter the Date of birth......Date (Format DD)"<<endl;
cin>> dd;
time_t rt;
struct tm * dOBInfo;
time ( &rt );
dOBInfo = localtime ( &rt );
dOBInfo->tm_year = yyyy-1900;
dOBInfo->tm_mon = mm-1;
dOBInfo->tm_mday = dd;
float totalSal;
cout<<"Enter the sales person Total annual sales"<<endl;
cin>> totalSal;
SalesPerson salesPerson(eID, fName, lName, mktime ( dOBInfo ),totalSal);
s[counter] = salesPerson;
counter++;
}
for(int i = 0 ; i< c; i++)
{
cout<<"Total annual sales"<< s[i].GetTotalAnnualSales()<< endl;
cout<<"Commission"<< s[i].CalculateCommission()<< endl;
}
// 3 rd task
SalesPerson tmp;
int flag = 1; // set flag to 1 to start first pass
int numLength = c-1;
for(int i = 1; (i <= numLength) && flag; i++)
{
flag = 0;
for (int j=0; j < i; j++)
{
if(s[j+1].GetFirstName() < s[j].GetFirstName()) //compare first two address objects found
//if the string comparison evaluates to true do this!
{
cout<<"in swap";
tmp = s[j]; // swap elements
s[j] = s[j+1];
s[j+1] = tmp;
flag = 1; // indicates that a swap occurred.
}
}
}
for(int i = 0 ; i< c; i++)
{
cout<<"Sorted name"<< s[i].GetFirstName()<< endl;
}
delete[] s;
return 0;
}
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.