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

C++ Corporate Sales Data. This program will have a structure that holds data abo

ID: 667482 • Letter: C

Question

C++

Corporate Sales Data. This program will have a structure that holds data about each division of a corporation. This structure will have a string object that holds the division’s name, 4 doubles that hold the sales totals for each quarter. The structure will also have two other doubles, one for the annual sales and the other will hold the average of the quarter sales. The program should use four variables (instances) of this structure. Each variable should represent one of the following corporate divisions: East, West, North, South. The user should be asked for the four quarters’ sales figures for each division. Each division’s total and average sales should be calculated and stored in the appropriate member of each structure variable. The output of the program will be all the figures in the structures. Validation: Do not accept negative numbers for any sales figures.

Program must have the following functions

void DisplayCorpInformation(const Division& east, const Division& west, const Division& north, const Division& south);

void FindTotalAndAverageSales(Division& div);

void GetDivisionSales(Division& div);

The input should look like this screen shot.

The output should look like this screen shot.

Explanation / Answer

Here is the code :

Another Approach :

#include <iostream>
#include <iomanip>

using namespace std;

//structure function
struct CorpData
{
string name; //stores division name
double firstQ, secondQ, thirdQ, fourthQ, totalA, average; //stores the data of each division
} north, south, west, east;

int main()
{
double northTotal, southTotal, eastTotal, westTotal,
   aveNorth, aveSouth, aveEast, aveWest;

//North Division
cout << " North Division";
cout << " Enter first quarter sale : ";
cin >> north.firstQ;
cout << "Enter second quarter sale : ";
cin >> north.secondQ;
cout << "Enter third quarter sale : ";
cin >> north.thirdQ;
cout << "Enter fourth quarter sale : ";
cin >> north.fourthQ;

//South Division
cout << " South Division";
cout << " Enter first quarter sale : ";
cin >> south.firstQ;
cout << "Enter second quarter sale : ";
cin >> south.secondQ;
cout << "Enter third quarter sale : ";
cin >> south.thirdQ;
cout << "Enter fourth quarter sale : ";
cin >> south.fourthQ;

//East Division
cout << " East Division";
cout << " Enter first quarter sale : ";
cin >> east.firstQ;
cout << "Enter second quarter sale : ";
cin >> east.secondQ;
cout << "Enter third quarter sale : ";
cin >> east.thirdQ;
cout << "Enter fourth quarter sale : ";
cin >> east.fourthQ;

//West Division
cout << " West Division";
cout << " Enter first quarter sale : ";
cin >> west.firstQ;
cout << "Enter second quarter sale : ";
cin >> west.secondQ;
cout << "Enter third quarter sale : ";
cin >> west.thirdQ;
cout << "Enter fourth quarter sale : ";
cin >> west.fourthQ;


cout << " ";
//////////////////////////////////////////////////////////////////////////
//                  //
//   Calculate the annual total each division     //
//                  //
//////////////////////////////////////////////////////////////////////////
northTotal = (north.firstQ + north.secondQ + north.thirdQ + north.fourthQ);
southTotal = (south.firstQ + north.secondQ + north.thirdQ + north.fourthQ);
eastTotal = (east.firstQ + east.secondQ + east.thirdQ + east.fourthQ);
westTotal = (west.firstQ + west.secondQ + west.thirdQ + west.fourthQ);

//////////////////////////////////////////////////////////////////////////
//                  //
//   Calculate the annual average each division     //
//                  //
//////////////////////////////////////////////////////////////////////////
aveNorth = northTotal / 4;
aveSouth = southTotal / 4;
aveEast = eastTotal / 4;
aveWest = westTotal / 4;

//////////////////////////////////////////////////////////////////////////
//                  //
//   Display the annual total and average of each division    //
//                  //
//////////////////////////////////////////////////////////////////////////
cout << setw(10) << "Division" << setw(14) << " Annual Total" << setw(18) << " Annual Average ";
cout << setw(10) << " North " << setw(14) << northTotal << " " << setw(18) << aveNorth << endl;
cout << setw(10) << " South " << setw(14) << southTotal << " " << setw(18) << aveSouth << endl;
cout << setw(10) << " East " << setw(14) << eastTotal << " " << setw(18) << aveEast << endl;
cout << setw(10) << " West " << setw(14) << westTotal << " " << setw(18) << aveWest << endl ;


cout << endl;
system("pause");
return 0;

}

#include <iostream>
#include <string>

using namespace std;

struct CorpData
{
   
double Quarter[4], total, average;
    string Division;
   
CorpData(string st)
{
        Division = st;
    }
   
int setQ(int qtr, double f)
{
            if (f > 0)
   {
                Quarter[qtr] = f;
                return 1;
            }
        return 0;
    }

[b]void getQ(int qtr)
{
  double total=0.0;

  for(int m = 0; m < 4; m++)
  {
   total = total + Quarter[m];
   average = total / 4;
  }
  cout << "Annual Total : " << total << endl;
  cout << "Annual Average : " << average << endl;
        }
        [/b]
};

int main (int argc, char * const argv[])
{
    CorpData **Datapoint;
    Datapoint = new CorpData *[4];
    double num;
   
string Division_name[4] = {"North","South","East","West"};

    for (int i = 0; i < 4; i++)
{
        cout << endl;
      
  Datapoint[i] = new CorpData(Division_name[i]);
       
  for (int q = 0; q < 4; q++)
  {
            do
   {
                cout << "Division: "<< Datapoint[i]->Division << endl << "Enter sales for quarter: "<< q+1 << ": ";
                cin >> num;
            } while (!Datapoint[i]->setQ(q,num));
        }
    }cout << endl;

[b]for (int j = 0; j < 4; j++)
{
  cout << Datapoint[j]->Division << endl;
  Datapoint[j]->getQ(j);
}[/b]


cout << endl;
system("pause");
    return 0;
}