Question

Language: C++

Create a class named 'Salesman' that shall inherit from a class called 'Person' and will add various functionality. We will store the following private variables specific to Warehouse:

. a std::vector of float values which indicate the monetary values of each sale made by this salesman . a std::string which s

Hint: to print the characters you should do the following: std::cout << HelloWorld\ << std::endl;

0 0
Add a comment Improve this question Transcribed image text
Answer #1
 #include <iostream> #include<vector> #include<numeric> using namespace std; class Person{//Base Class public: string name; int age; int height; protected: Person(){ } }; class Salesman:public Person{ private: vector<float> a; string title; float commission=0.2; float bsalary=45000; public: Salesman(){ } Salesman(string name1,int age1,int height1,string title1,float commission1){ name=name1; age=age1; height=height1; title=title1; commission=commission1; } ~Salesman(){}//default destructor Salesman(const Salesman &s1) {a=s1.a;title=s1.title;commission=s1.commission;bsalary=s1.bsalary;} //copy constructor Salesman(const Salesman* s1) {a=s1->a;title=s1->title;commission=s1->commission;bsalary=s1->bsalary;} //copy constructor void setPosition(string title1){ title=title1; } string getPosition(){ return title; } void setSalary(float bsalary1){ bsalary=bsalary1; } float getSalary(){ return bsalary; } void setCommission(float commission1){ commission=commission1; } float getcommision(){ return commission; } void addSale(float a1){ a.push_back(a1); } float getTotalSalary(){ int tsales=accumulate(a.begin(),a.end(),0); return(bsalary+(commission*tsales)); } void printDetails(){ cout<<"Name:"<<name<<","<<"Age:"<<age<<","<<"Height:"<<height<<endl; cout<<name<<" made a total of "<<a.size()<<" sales this year and gets"<<endl; cout<<commission<<"% as commission."<<endl; cout<<"Therefore,"<<name<<"\'s total income is their salary ("<<bsalary<<") + their commission ("<<commission*accumulate(a.begin(),a.end(),0)<<") ="<<bsalary+commission*accumulate(a.begin(),a.end(),0)<<" as the "<<title<<"."<<endl; } }; int main() { Salesman s("Sam",32,175,"Sales Executive",4.5); s.addSale(5); s.addSale(7); s.printDetails();        return 0; } 
Add a comment
Know the answer?
Add Answer to:
Language: C++ Create a class named 'Salesman' that shall inherit from a class called 'Person' and...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • Language: C++ Create an abstract base class person. The person class must be an abstract base...

    Language: C++ Create an abstract base class person. The person class must be an abstract base class where the following functions are abstracted (to be implemented in Salesman and Warehouse): • set Position • get Position • get TotalSalary .printDetails The person class shall store the following data as either private or protected (i.e., not public; need to be accessible to the derived classes): . a person's name: std::string . a person's age: int . a person's height: float The...

  • c++ program Implement a class called Person with the following members: 1a. ????, a private variable...

    c++ program Implement a class called Person with the following members: 1a. ????, a private variable of type ?????? 1b. ???, a private variable of type ??? 1c. Default constructor to set name to "" and age to 0 1d. Non-default constructor which accepts two parameters for name and age 1e. A copy constructor 1f. The post-increment operator 1g. The pre-decrement operator 1h. The insertion and extraction stream operators >>and <<

  • Using your Dog class from earlier this week, complete the following: Create a new class called...

    Using your Dog class from earlier this week, complete the following: Create a new class called DogKennel with the following: Instance field(s) - array of Dogs + any others you may want Contructor - default (no parameters) - will make a DogKennel with no dogs in it Methods: public void addDog(Dog d) - which adds a dog to the array public int currentNumDogs() - returns number of dogs currently in kennel public double averageAge() - which returns the average age...

  • 2- Write a program that has a Person class, a Student class, that is derived from...

    2- Write a program that has a Person class, a Student class, that is derived from Person, and a Faculty class, derived from Person as well, with the following specifications: The Person class has the following members: a. An integer private member variable named SSN. b. Two string protected member variables named firstName and lastName. C. An integer protected member variable named age. d. A constructor that takes SSN, first name, last name, and age as parameters. e. A constructor...

  • Java Problem 2: Employee (10 points) (Software Design) Create an abstract class that represents an Employee and contains abstract method payment. Create concrete classes: SalaryEmployee, CommissionEm...

    Java Problem 2: Employee (10 points) (Software Design) Create an abstract class that represents an Employee and contains abstract method payment. Create concrete classes: SalaryEmployee, CommissionEmployee, HourlyEmployee which extend the Employee class and implements that abstract method. A Salary Employee has a salary, a Commision Employee has a commission rate and total sales, and Hourly Employee as an hourly rate and hours worked Software Architecture: The Employee class is the abstract super class and must be instantiated by one of...

  • Create this c++ program. Create to classes and name their type Account and Money. Follow the...

    Create this c++ program. Create to classes and name their type Account and Money. Follow the instruction listed below. Please read and implement instructions very carefully Money Class Requirements - Negative amounts of Money shall be stored by making both the dollars and cents negative The Money class shall have 4 constructors * A default constructor that initializes your Money object to $0.00 A constructor that takes two integers, the first for the dollars and the second for the cents...

  • In a project named 'DogApplication', create a class called 'Dog' 1. declare two instance variables in...

    In a project named 'DogApplication', create a class called 'Dog' 1. declare two instance variables in 'Dog' : name (String type) age (int type) 2. declare the constructor for the 'Dog' class that takes two input parameters and uses these input parameters to initialize the instance variables 3. create another class called 'Driver' and inside the main method, declare two variables of type 'Dog' and call them 'myDog' and 'yourDog', then assign two variables to two instance of 'Dog' with...

  • Create a class called Student. This class will hold the first name, last name, and test...

    Create a class called Student. This class will hold the first name, last name, and test grades for a student. Use separate files to create the class (.h and .cpp) Private Variables Two strings for the first and last name A float pointer to hold the starting address for an array of grades An integer for the number of grades Constructor This is to be a default constructor It takes as input the first and last name, and the number...

  • c++ please need help with this question Consider a class Employee with data members: age(an integer),...

    c++ please need help with this question Consider a class Employee with data members: age(an integer), id (an integer) and salary (a float), and their corresponding member functions as follows: class Employee {        private:             int age;             int id;             float salary;        public:             Employee( ); // default constructor: age=0, id=0, and salary=0             Employee(Employee &x);   // copy constructor           Employee& operator = (Employee &x); // equal sign operator             void setAge(int x);    // let age = x...

  • Part (A) Note: This class must be created in a separate cpp file Create a class...

    Part (A) Note: This class must be created in a separate cpp file Create a class Employee with the following attributes and operations: Attributes (Data members): i. An array to store the employee name. The length of this array is 256 bytes. ii. An array to store the company name. The length of this array is 256 bytes. iii. An array to store the department name. The length of this array is 256 bytes. iv. An unsigned integer to store...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT