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

7. Corporate Sales A corporation has six divisions, each responsible for sales t

ID: 3702428 • Letter: 7

Question

7. Corporate Sales A corporation has six divisions, each responsible for sales to different geographic loca- tions. Design a Divsales class that keeps sales data for a division, with the following members An array with four elements for holding four quarters of sales figures for the division A private static variable for holding the total corporate sales for all divisions for the entire year. A member function that takes four arguments, each assumed to be the sales for a quarter. The value of the arguments should be copied into the array that holds the sales data. The total of the four arguments should be added to the static variable that holds the total yearly corporate sales. A function that takes an integer argument within the range of 0 to 3. The argument is to be used as a subscript into the division quarterly sales array. The function should return the value of the array element with that subscript. Write a program that creates an array of six Divsales objects. The program should ask the user to enter the sales for four quarters for each division. After the data is entered, the program should display a table showing the division sales for each quarter. The program should then display the total corporate sales for the year. Input Validation: Only accept positive values for quarterly sales figures

Explanation / Answer

#include <iostream>
using namespace std;

class DivSales
{
private:
int sales[4];


public:
static int totalSales; //static variable
void setQuarterSales(int q1,int q2,int q3,int q4)
{
  sales[0] = q1;
  sales[1] = q2;
  sales[2] = q3;
  sales[3] = q4;
  
  totalSales = totalSales + q1+q2+q3+q4;
}
int getQuarterSales(int quarter)
{
  return sales[quarter];
}
static int getTotalSales()
{
  return totalSales;
}


};
int DivSales::totalSales = 0; // initialize static member
int main() {

DivSales ds[6];
int q1,q2,q3,q4;
cout<<"Enter the sales for four quarters for each six division : ";

for(int i = 0;i<6;i++)
{
cin>>q1>>q2>>q3>>q4;
if(q1>0 && q2>>0 && q3>0 && q4>0)
ds[i].setQuarterSales(q1,q2,q3,q4);
else
cout<<" Quarter sales should be positive ";// sales validation
}

for(int i = 0;i<6;i++)
{
  cout<<" Division "<<(i+1)<<" sales for each quarter : "<<endl;
  for(int j=0;j<4;j++)
  cout<<ds[i].getQuarterSales(j)<<endl;
  
}
cout<<"Total corporate sales for all divisions for the entire year : "<<DivSales::getTotalSales();
return 0;
}

Output:

Enter the sales for four quarters for each six division :

345 678 231 654
445 653 766 788
234 566 321 435
678 911 224 546
544 684 656 353
556 575 687 375
Division 1 sales for each quarter :
345
678
231
654

Division 2 sales for each quarter :
445
653
766
788

Division 3 sales for each quarter :
234
566
321
435

Division 4 sales for each quarter :
678
911
224
546

Division 5 sales for each quarter :
544
684
656
353

Division 6 sales for each quarter :
556
575
687
375
Total corporate sales for all divisions for the entire year : 12905

Do ask if any doubt. Please upvote.

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