Question #50415

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. Save the file as Sales.cpp.

Expert's answer

Here is the restored and formatted document:

Program

sales.cpp


#include <iostream>
#include <conio.h>
#include <string>
using namespace std;
class Salesperson;
class Sale
{
private:
    int dayOfMonth;//day of the month
    int amountSale;//amount of the sale
    int ID;//the salesperson's ID number
public:
    Sale(int date, int amount, int id);
    friend void display(Salesperson saler, Sale sale);
};
Sale::Sale(int date, int amount, int id)
{
    if((date>0)&&(date<32))
        dayOfMonth=date;
    else
        dayOfMonth=1;
    amountSale=amount>0?amount:0;
    ID=id;
}
class Salesperson
{
private:
    string name;//amount of the sale
    int ID;//the salesperson's ID number
public:
    Salesperson(string Name, int id);
    friend void display(Salesperson saler, Sale sale);
};
Salesperson::Salesperson(string Name, int id)
{
    name=Name;
    ID=id;
}
void display(Salesperson saler, Sale sale)
{
    cout<<"Date of sale: "<<sale.dayOfMonth<<endl;
    cout<<"Amount: "<<sale.amountSale<<endl;
    cout<<"Saler: "<<saler.name<<"(ID: "<<saler.ID<<")"<<endl;
}
int main()
{
    Sale a(5,3,1);
    Salesperson saler("John",1);
    display(saler,a);
    getch();
    return 1;
}


Example of execute program:


Date of sale: 5
Amount: 3
Saler: John(ID: 1)


http://www.AssignmentExpert.com/

LATEST TUTORIALS
APPROVED BY CLIENTS