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

Hi this is for C++ so Thanks in advance! Write 2 programs: One program will use

ID: 3694450 • Letter: H

Question

Hi this is for C++ so Thanks in advance!

Write 2 programs:

One program will use a 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 the East, West, North, and South divisions. The data for each quarter for each division should be written to a file.

The second program will read the data written by the first program. 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

Input Validation: Do not accept negative numbers for any sales figures.

Explanation / Answer

Hope i reached your expectations

1)

#include <iostream>
#include <cstring>
using std::cout;
using std::cin;
struct CompanyDivision
{
char name[6];
double qtr_sales[4];
double annual_sales;
double avg_qtr_sales;
public:
CompanyDivision(const char* _name)
{
strncpy(name, _name, 5);
name[5] = '';
for (short i = 0; i < 4; i++ )
{
cout << name << " Q" << (i+1) << " Sales: ";
do
{
cin >> qtr_sales[i];
}
while (qtr_sales[i] < 0);
annual_sales += qtr_sales[i];
}
avg_qtr_sales = annual_sales / 4;
}
void print()
{
cout << " Division Name: " << name << ' '
<< " First-Quarter Sales: " << qtr_sales[0] << ' '
<< " Second-Quarter Sales: " << qtr_sales[1] << ' '
<< " Third-Quarter Sales: " << qtr_sales[2] << ' '
<< " Fourth-Quarter Sales: " << qtr_sales[3] << ' '
<< " Total Annual Sales: " << annual_sales << ' '
<< "Average Quarterly Sales: " << avg_qtr_sales << ' ';
}
};
int main()
{
CompanyDivision n ( "North" );
CompanyDivision s ( "South" );
CompanyDivision e ( "East" );
CompanyDivision w ( "West" );
cout << ' ';
e.print();
cout << ' ';
w.print();
cout << ' ';
n.print();
cout << ' ';
s.print();
return 0;
}

2)


#include <iostream>
#include <string>
#include <fstream>
#include <iomanip>
using namespace std;
const int LENGTH = 4;
struct CorprateData
{
static string Division[LENGTH];
double Qtr[LENGTH];
double QtrlySales;
};
string CorpData::Division[LENGTH] = {"East", "West", "North", "South"};
int main()
{
CorpData Sales;
double TotCorpQtr[LENGTH] = {0,0,0,0};
double TotYrDiv,                       
TotYrCorp,                       
Highest,
Lowest;
TotYrCorp = TotYrDiv = 0;
fstream File("salefigures.txt", ios::in | ios::binary);
if (!File)
{
cout << "Error opening file. ";
return 0;
}
cout << fixed << showpoint << setprecision(2);
cout << " Corporate Sales Data Report "<< "--------------------------- ";
cout << " Total sales by division: ";
for (int d = 0; d < LENGTH; d++)
{
File.read(reinterpret_cast<char *>(&Sales), sizeof(Sales));
cout << Sales.Division[d] << ": ";
cout << " Total yearly Sales: $";
for (int q = 0; q < LENGTH; q++)
{
TotYrDiv += Sales.Qtr[q];
TotCorpQtr[q] += Sales.Qtr[q];
}
cout << TotYrDiv << endl;
cout << " Average quarterly sales: $" << TotYrDiv/4 << endl;
TotYrCorp += TotYrDiv;
}
cout << " Total corporate sales for each quarter: ";
for (int i = 0; i < LENGTH; i++)
{
cout << "Quarter " << (i + 1) << ": $" << TotCorpQtr[i] << endl;
}
cout << " Total yearly corporate sales: $" << TotYrCorp << endl;
Highest = Lowest = TotCorpQtr[0];
for (int i = 1; i < LENGTH; i++)
{
if (TotCorpQtr[i] > Highest)
Highest = TotCorpQtr[i];
if (TotCorpQtr[i] < Lowest)
Lowest = TotCorpQtr[i];
}
cout << "The highest quarter for the corporation: " << Highest << endl;
cout << "The lowest quarter for the corporation: " << Lowest << endl;
File.close();
return 0;
}

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