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

Can someone solve this problem? It is located in Chapter 13 of \"Starting out wi

ID: 3692533 • Letter: C

Question

Can someone solve this problem? It is located in Chapter 13 of "Starting out with C++ Early Objects 8th Edition by Tony Gaddis", Programming challenge 14.

Corporate Sales Data Input

Write a program that reads the information in the file created by the program in Programming Challenge 13. The program should calculate and display the following figures:

* Total corporate sales for each quarter

* Total yearly sales for each division

* Total yearly corporate sales

* Average quarterly sales for the divisions

* The highest and lowest quarters for the corporation

Thank you :)

Explanation / Answer

Write a program that uses a structure to store the following data on a company
division:
Division Name (such as East, West, North, or South)
First-Quarter Sales
Second-Quarter Sales
Third-Quarter Sales
Fourth-Quarter Sales
Total Annual Sales
Average Quarterly Sales
The program should use four variables of this structure. Each variable should rep-
resent one of the following corporate divisions: East, West, North, and 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. These figures should then be displayed on the
screen.

This is the problem which i found in chapter 11 but i can't find the input file for data inputs. So i am using some random data.

#include <iostream>
#include <fstream>
using namespace std;

struct division
{
int first;
int second;
int third;
int fourth;
int total;
int average;
};


int main()
{
division east,west,north,south;
int a, b ,c ,d, i=0;
ifstream infile("data.txt");
while (infile >> a >> b >> c >> d)
{
    if(i==0){
        east.first = a;
        east.second = b;
        east.third = c;
        east.fourth = d;
        east.total = a+b+c+d;
        east.average = (a+b+c+d)/4;
        i++;
   } else if(i==1){
        west.first = a;
        west.second = b;
        west.third = c;
        west.fourth = d;
        west.total = a+b+c+d;
        west.average = (a+b+c+d)/4;
        i++;
   } else if(i==2){
        north.first = a;
        north.second = b;
        north.third = c;
        north.fourth = d;
        north.total = a+b+c+d;
        north.average = (a+b+c+d)/4;
        i++;
   } else if(i==3){
        south.first = a;
        south.second = b;
        south.third = c;
        south.fourth = d;
        south.total = a+b+c+d;
        south.average = (a+b+c+d)/4;
        i++;
   }
}
/*
* Total corporate sales for each quarter

* Total yearly sales for each division

* Total yearly corporate sales

* Average quarterly sales for the divisions

* The highest and lowest quarters for the corporation
*/

int totalCorporateSalesFirstQuarter,totalCorporateSalesSecondQuarter,totalCorporateSalesThirdQuarter,totalCorporateSalesFourthQuarter;
int totalYearlySalesEast,totalYearlySalesWest,totalYearlySalesNorth,totalYearlySalesSouth;
int totalYearlySales;
int avgQSEast,avgQSWest,avgQSNorth,avgQSSouth;
int highest ,lowest;

totalCorporateSalesFirstQuarter = east.first + west.first+ north.first+south.first;
totalCorporateSalesSecondQuarter = east.second + west.second+ north.second+south.second;
totalCorporateSalesThirdQuarter = east.third + west.third+ north.third+south.third;
totalCorporateSalesFourthQuarter = east.fourth + west.fourth+ north.fourth+south.fourth;

totalYearlySalesEast = east.first+east.second+east.third+east.fourth;
totalYearlySalesWest = west.first+west.second+west.third+west.fourth;
totalYearlySalesNorth = north.first+north.second+north.third+north.fourth;
totalYearlySalesSouth = south.first+south.second+south.third+south.fourth;

totalYearlySales = totalYearlySalesEast + totalYearlySalesWest + totalYearlySalesNorth + totalYearlySalesSouth;

avgQSEast = totalYearlySalesEast/4;
avgQSWest = totalYearlySalesWest/4;
avgQSNorth = totalYearlySalesNorth/4;
avgQSSouth = totalYearlySalesSouth/4;

highest = totalCorporateSalesFirstQuarter;
lowest =totalCorporateSalesFirstQuarter;

if(highest<totalCorporateSalesSecondQuarter){
   highest = totalCorporateSalesSecondQuarter;
}
if (highest<totalCorporateSalesThirdQuarter){
   highest = totalCorporateSalesThirdQuarter;
}
if (highest<totalCorporateSalesFourthQuarter){
   highest = totalCorporateSalesFourthQuarter;
}

if(lowest>totalCorporateSalesSecondQuarter){
   lowest = totalCorporateSalesSecondQuarter;
}
if (lowest>totalCorporateSalesThirdQuarter){
   lowest = totalCorporateSalesThirdQuarter;
}
if (lowest>totalCorporateSalesFourthQuarter){
   lowest = totalCorporateSalesFourthQuarter;
}

cout<<"Total corporate sales for first quarter: "<<totalCorporateSalesFirstQuarter<<" ";
cout<<"Total corporate sales for second quarter: "<<totalCorporateSalesSecondQuarter<<" ";
cout<<"Total corporate sales for third quarter: "<<totalCorporateSalesThirdQuarter<<" ";
cout<<"Total corporate sales for fourth quarter: "<<totalCorporateSalesFourthQuarter<<" ";

cout<<"Total yearly sales for east division: "<<totalYearlySalesEast<<" ";
cout<<"Total yearly sales for west division: "<<totalYearlySalesWest<<" ";
cout<<"Total yearly sales for north division: "<<totalYearlySalesNorth<<" ";
cout<<"Total yearly sales for south division: "<<totalYearlySalesSouth<<" ";

cout<<"Total yearly corporate sales :" <<totalYearlySales<<" ";


cout<<"Average quarterly sales for east division: "<<avgQSEast<<" ";
cout<<"Average quarterly sales for west division: "<<avgQSWest<<" ";
cout<<"Average quarterly sales for north division: "<<avgQSNorth<<" ";
cout<<"Average quarterly sales for south division: "<<avgQSSouth<<" ";

cout<<"The highest quarters for the corporation: "<<highest<<" ";
cout<<"The lowest quarters for the corporation: "<<lowest<<" ";
return 0;
}

Create a file named "data.txt". And enter this data.

1 2 3 4
5 6 7 8
9 10 11 12
13 14 15 16