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

Create a class for a salesman that has a data member of an array of double data

ID: 3536987 • Letter: C

Question

Create a class for a salesman that has a data member of an array of double data type as the sales of some number of quarters, a data member average as the average of the sales of all quarters, another data member as max as the maximum of the sales of all quarters, and one data member min as the minimum of sales of all quarters.

After that write a default constructor and a user-defined constructor. Default constructor should ask user the number of quarters and enter the sales, calculate average, maximum, and minimum of all sales. User-defined constructor should pass an array of double as the sales and the number of quarters by constant reference and calculate average, maximum, and minimum. Write a member function that displays all of the information about this salesman. Write a main to test it.

note: i need this program in three files sales.h, salesman.cpp, main cpp where i call functions.

Explanation / Answer

//sales.h


#ifndef SALES_H

#define SALES_H


class Salesman

{

double* sales;

double average;

int quarters;

double max;

double min;


public:

Salesman();

Salesman(double s[],const int quarters);

void display();

};


#endif


// salesman.cpp


#include<iostream>

#include "sales.h"


using namespace std;


Salesman::Salesman()

{

cout<<"Enter the total no of quarters: ";

cin>>quarters;



sales=new double[quarters];

cout<<"Enter sales of each quarter: ";


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

cin>>sales[i];


max=sales[0];;

min=sales[0];


average=0.0;


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

{

if(max<sales[i])

max=sales[i];

if(min>sales[i])

min=sales[i];


average+=sales[i];


}


average/=quarters;

}


Salesman::Salesman(double s[],const int q)

{

quarters=q;

sales=new double[quarters];

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

sales[i]=s[i];


max=sales[0];;

min=sales[0];


average=0.0;


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

{

if(max<sales[i])

max=sales[i];

if(min>sales[i])

min=sales[i];


average+=sales[i];


}


average/=quarters;

}


void Salesman::display()

{

// tesing parametrized constructor

cout<<"sales of each quarter: "<<endl;

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

cout<<sales[i]<<endl;


cout<<" average: "<<average;


cout<<" maximum sales: "<<max;


cout<<" minimum sales: "<<min;



}



//main.cpp


#include<iostream>

#include"sales.h"

using namespace std;


int main()

{

// tesing parametrized constructor

cout<<"testing parameterized constructor: ";


double sales[]={2000.00,5000.00,2250.70,1000.11,9999.99,1123.25};

Salesman s(sales,6);

s.display();


cout<<" Testing default constructor: ";


Salesman obj;

obj.display();

return 0;

}

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