Can you provide a step by step solution to chapter 12, PC 12, Corporate Sales Da
ID: 3889536 • Letter: C
Question
Can you provide a step by step solution to chapter 12, PC 12, Corporate Sales Data Input. I'm are using Dev C++ Bloodshed. The solution must come from the material we have covered in edition 8 up to chapter 13. this is the question:
Chapter 12 Program Challenge 12 is built from Program Challenge 11 above it.
11. Corporate Sales Data Output
Write a program that uses a debt or structure to store the following data on a company division.
Division name (such as East, West, North, or South)
Quarter (1, 2, 3, or 4)
Quarterly sales
The user should be asked for the four quarters sales figures for East, West, North, and South divisions. The data for each quarter for each division should be written to a file.
Input validation: do not accept negative numbers for any sales figures.
12. Corporate Sales Data Input
Write a program that reads the data created by the program in the programming challenge 11. 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 each division
The highest and lowest quarter for the corporation
Thank You
Explanation / Answer
#include <fstream>
#include <iostream>
using namespace std;
int main () {
string data;
int divison[4];
int val,i,j,k,p=0,total[16]={0},min=0,max=0,tc=0;
// open a file in write mode.
ofstream outfile;
outfile.open("afile.dat");
for(i=0;i<4;i++)
{
if(i==0)
{
data="East";
}
else if(i==1)
{
data="West";
}
else if(i==2)
{
data="North";
}
else
{
data="South";
}
cout << " Divison name : " << data<<endl;
for(j=1;j<=4;j++)
{
cout << "Enter Quarter Sale: "<<j<<" ";
cin >> val;
if(val>=0)
{
// write inputted data into the file.
outfile << data <<" ";
outfile << j <<" ";
outfile << val <<" ";
total[p]=val;
p++;
}
}
cin.ignore();
}
// close the opened file.
outfile.close();
for(k=0;k<16;k++)
{
if(min>total[k])
min=total[k];
if(max<total[k])
max=total[k];
tc=tc+total[k];
}
cout<<"Total yearly corporate sales" <<tc<<endl;
cout<<"Total corporate sales for quarter1 " <<total[0]+total[4]+total[8]+total[12]<<endl;
cout<<"Total corporate sales for quarter2 " <<total[1]+total[5]+total[9]+total[13]<<endl;
cout<<"Total corporate sales for quarter3 " <<total[2]+total[6]+total[10]+total[14]<<endl;
cout<<"Total corporate sales for quarter4 " <<total[3]+total[7]+total[11]+total[15]<<endl;
cout<<"Total yearly sales for each division-East " <<total[0]+total[1]+total[2]+total[3]<<endl;
cout<<"Total yearly sales for each division-West " <<total[4]+total[5]+total[6]+total[7]<<endl;
cout<<"Total yearly sales for each division-North " <<total[8]+total[9]+total[10]+total[11]<<endl;
cout<<"Total yearly sales for each division-South " <<total[12]+total[13]+total[14]+total[15]<<endl;
cout<<"Average quarterly sales for each division-East " <<(total[0]+total[1]+total[2]+total[3])/4<<endl;
cout<<"Average quarterly sales for each division-West " <<(total[4]+total[5]+total[6]+total[7])/4<<endl;
cout<<"Average quarterly sales for each division-North " <<(total[8]+total[9]+total[10]+total[11])/4<<endl;
cout<<"Average quarterly sales for each division-South " <<(total[12]+total[13]+total[14]+total[15])/4<<endl;
cout<<"The highest and lowest quarter for the corporation are " <<max<<","<<min<<endl;
return 0;
}
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.