(C++ Program) Corporate Sales A corporation has six divisions, each responsible
ID: 3700990 • Letter: #
Question
(C++ Program) Corporate Sales
A corporation has six divisions, each responsible for sales to different geographic locations. 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.
show your Output and comments!!
Explanation / Answer
/******************************************************************************
Online C++ Compiler.
Code, Compile, Run and Debug C++ program online.
Write your code in this editor and press "Run" button to compile and execute it.
*******************************************************************************/
#include <iostream>
using namespace std;
class DivSales
{
// private section
private:
int qatrSales[4];
int totSales;
// public section
public:
// storSales stores the quarter sales
void storSales(int val1,int val2,int val3,int val4)
{
qatrSales[0] = val1;
qatrSales[1] = val2;
qatrSales[2] = val3;
qatrSales[3] = val4;
totSales = totSales + val1 + val2 + val3 + val4;
}
// indSales returns the quarter sales
int indSales(int val)
{
return qatrSales[val];
}
// retTotSales returns the total sales
int retTotSales(void)
{
return totSales;
}
};
int main()
{
DivSales loc[6]; // six divisions
int loop1,loop2,arr[4],val;
for(loop1=1; loop1<=6; loop1++)
{
cout<<"Enter Sales for Division "<<loop1<<": -"<<endl;
for(loop2=1;loop2<=4;loop2++)
{
val = loop2 - 1;
cout<<"Quarter "<<loop2<<": ";
cin>>arr[val]; // quarter sales are input here
}
// store the sales
loc[loop1].storSales(arr[0],arr[1],arr[2],arr[3]);
cout<<endl<<endl;
}
// formatted output
cout<<endl<<"Division wise sales: -"<<endl;
cout<<" "<<"Quarter 1 "<<"Quarter 2 "<<"Quarter 3 "<<"Quarter 4 "<<endl;
for(loop1=1; loop1<=6; loop1++)
{
cout<<"Division "<<loop1;
for(loop2=1;loop2<=4;loop2++)
{
val = loop2 - 1;
cout<<" "<<loc[loop1].indSales(val);
}
cout<<endl;
}
// calculate the total sales
val=0;
for(loop1=1; loop1<=6; loop1++)
{
val = val + loc[loop1].retTotSales();
}
cout<<endl<<"Total Sales: "<<val;
return 0;
}
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.