Ask Question

Create two classes. The first, named Sale, holds data for a sales transaction. Its private data members include the day of the month, amount of the sale, and the salesperson's ID number. The second class, named Salesperson, holds data for a salesperson, and its private data members include each salesperson's ID number and last name. Each class includes a constructor to which you can pass the field values. Create a friend function named display () that is a friend of both classes and displays the date of sale, the amount, and the salesperson ID and name. Write a short main () demonstration program to test your classes and friend function. Sample Run

Sale #103 on 12/25/2016 for $559.95 sold by #103 Woods

Sale #106 on 11/15/2016 for $359.95 sold by #106 Hansen

+3
Answers (1)
  1. 9 January, 08:35
    0
    A C+ + program was used in creating two classes. the code is stated below.

    Explanation:

    Solution

    The C+ + program is executed below:

    #include

    using namespace std;

    //declare class (will be define later)

    class Salesperson;

    //class Sale

    class Sale

    {

    //private members of class

    private:

    string day;

    double amtOfSale;

    int salesPersonId;

    //public methods

    public:

    //constructor that takes day, amount of sale and salesPersonId as parameters

    Sale (string date, double sale, int id)

    {

    //set the private members to the initial values passed

    day=date;

    amtOfSale=sale;

    salesPersonId=id;

    }

    //declare a friend function that takes objects of the two classes as parameters

    friend void display (Sale, Salesperson);

    };

    //define class Salesperson

    class Salesperson

    {

    //private members of the class

    private:

    int salesPersonId;

    string lastName;

    //public methods

    public:

    //constructor that takes name and id as parameters

    Salesperson (int id, string name)

    {

    //set the members of the class with the parameters passed

    salesPersonId=id;

    lastName=name;

    }

    //declare a friend function that takes objects of the two classes as parameters

    friend void display (Sale, Salesperson);

    };

    //define the friend funtion

    void display (Sale saleObj, Salesperson personObj)

    {

    //display the sales info using the objects of the two classes

    cout<<"/nSale #"<
    }

    int main ()

    {

    //create object for Sale class and pass default values

    Sale sObj1 ("12/25/2016",559.95,103);

    //create object for Salesperson class and pass default values

    Salesperson pObj1 (103,"Woods");

    //create another object for Sale class and pass default values

    Sale sObj2 ("11/15/2016",359.95,106);

    //create another object for Salesperson class and pass default values

    Salesperson pObj2 (106,"Hansen");

    //using the friend function dislay the sales info

    display (sObj1, pObj1);

    display (sObj2, pObj2);

    return 0;

    }
Know the Answer?
Not Sure About the Answer?
Find an answer to your question 👍 “Create two classes. The first, named Sale, holds data for a sales transaction. Its private data members include the day of the month, ...” in 📗 Computers & Technology if the answers seem to be not correct or there’s no answer. Try a smart search to find answers to similar questions.
Search for Other Answers