The Dayton Fire & Brimstone company has asked you to write a program which will
ID: 3920496 • Letter: T
Question
The Dayton Fire & Brimstone company has asked you to write a program which will produce a report, in chart form, showing how their four divisions are doing this year in generating sales. Each division has five sales territories.
The four divisions are East Coast, Mid-West, Far-West, and West Coast.
In main:
-have the user enter a file name for a text file which will hold the sales for all divisions and their territories; define a vector to hold the division names and an array of doubles to hold each of the four division's sales total.
-call a function which repeatedly has the user enter a division name and place it in the vector, and then enters the division’s five sales amounts and places each of them into the text file, using the division name as a prompt. Validate that each sales amount is zero or greater.
-call a second function which processes the file by summing the sales of each division and placing the total into the array of divisional sales totals.
-in main: process the divisional totals array by producing the following sales chart:
-display a Sales Chart title line
-display a single line for each division, showing:
>the division’s name
>the division’s total sales amount
>an asterisk (*) for each $1,000 in sales, e.g., $3, 500 in sales would show: * * *
-also determine the division with the most sales
After the sales chart is displayed, display the division name and sales amount of the division with the most sales.
Note: arrays and files must be processed with loops, and any vector statements or functions must be from Chapter 7 of our textbook.
Use this data for the screen print:
East Coast: $800, $1,200, $2,000, $500, $2,500
Mid-West: $1,000, $3,000, $2,500, $5,000, $1,500
Far-West: $50, $150, $400, $200, $199
West Coast: $200, $0, $500, $100, $201
_________________________
I would also like it to be formatted similarlly to this:
#include <iostream>
#include <string>
using namespace std;
const int DAYS = 4;
void Get_Data(char weath[][DAYS], const int MN, string mn[]);
int main ()
{
const int MONTHS = 3, TYPE = 3;
char weather[MONTHS][DAYS];
string month[MONTHS] = {"June", "July", "August"};
string type[TYPE] = { "rainy", "cloudy", "sunny" };
int stats[MONTHS][TYPE] = { { 0, 0, 0 }, { 0, 0, 0 }, { 0, 0, 0 } };
int statsTotals [TYPE] = { 0, 0, 0 };
int rainy = 0, cloudy = 1, sunny = 2;
Get_Data(weather, MONTHS, month);
for (int m = 0; m < MONTHS; m++)
{
for (int d = 0; d < DAYS; ++d)
{
if (weather[m][d] == 'R')
{
stats[m][rainy]++;
}
else if (weather[m][d] == 'C')
{
stats[m][cloudy]++;
}
else
{
stats[m][sunny]++;
}
}
}
cout << " *** Summer Weather Report ***";
for (int m = 0; m < MONTHS; m++)
{
for (int t = 0; t < TYPE; t++)
{
cout << " For " << month[m] << ": " << stats[m][t] << " days were " << type [t];
statsTotals[t] += stats[m][t];
}
cout << endl;
}
cout << endl << endl;
for (int t = 0; t < TYPE; t++)
{
cout << " Total " << type[t] << " days were : " << statsTotals[t];
}
cout << endl << endl;
system("pause");
return (0);
}
void Get_Data(char weath[][DAYS], const int MN, string mn [])
{
int day;
for (int m = 0; m < MN; m++)
{
day = 0;
for (int d = 0; d < DAYS; d++)
{
if (d == 0)
{
day = 1;
}
else
{
day += 8;
}
cout << " Enter the code (R, C or S) for " << mn[m] << ", day " << day << ">";
cin >> weath[m][d];
}
}
}
Explanation / Answer
//main.cpp
#include <iostream>
#include <fstream>
#include <string>
#include <vector>
using namespace std;
const size_t TOTAL_DIV = 4;
const size_t NO_OF_TERRITORIES = 5;
// Using this struct to read data from the file easily
struct FileRecord {
string divName;
double sale1;
double sale2;
double sale3;
double sale4;
double sale5;
friend istream& operator >> (istream& is, FileRecord& fileRecord)
{
is >> fileRecord.divName >> fileRecord.sale1 >> fileRecord.sale2 >> fileRecord.sale3 >> fileRecord.sale4 >> fileRecord.sale5;
return is;
}
};
// This method repeatedly asks the user to enter division name
// and sales amounts for it's territories
void GetData(vector<string>& divNames, const string& fileName)
{
ofstream outFile(fileName);
string divName;
double saleAmount;
string command = "Y";
do
{
cout << "Enter division name: ";
cin >> divName;
outFile << divName << "> ";
divNames.emplace_back(divName);
for (size_t i = 1; i <= NO_OF_TERRITORIES; ++i)
{
cout << "Sale amount " << i << ": ";
cin >> saleAmount;
if (!saleAmount > 0)
throw runtime_error("Invalid sales amount.");
outFile << " " << saleAmount;
}
cout << "Do you want to enter more division? (Y for yes, anything else to stop): ";
cin >> command;
if ((command == "Y" || command == "y"))
outFile << " ";
} while (command == "Y" || command == "y");
}
// This methods reads data from the given files names
// and processes the sales amount for each division
void ProcessFile(vector<string>& divNames, string& fileName, double* divisionalSalesTotal)
{
ifstream inFile(fileName);
string line;
FileRecord record;
for (size_t i = 0; i < divNames.size(); ++i)
{
inFile >> record;
divisionalSalesTotal[i] = record.sale1 + record.sale2 + record.sale3 + record.sale4 + record.sale5;
}
}
int main()
{
vector<string> divNames;
string fileName;
cout << "Enter filename to save data to: ";
cin >> fileName;
GetData(divNames, fileName);
double* divisionalSalesTotal = new double[divNames.size()];
ProcessFile(divNames, fileName, divisionalSalesTotal);
double maxSales = divisionalSalesTotal[0];
string maxSaleDivision = divNames[0];
for (size_t i = 0; i < divNames.size(); ++i)
{
if (divisionalSalesTotal[i] > maxSales)
{
maxSales = divisionalSalesTotal[i];
maxSaleDivision = divNames[i];
}
cout << endl << "******* Sales Chart ******" << endl;
cout << "Division name: " << divNames[i] << " Total Sales: $" << divisionalSalesTotal[i];
int times = divisionalSalesTotal[i] / 1000;
for (size_t j = 0; j < times; ++j)
{
cout << "*";
}
cout << endl;
}
delete[] divisionalSalesTotal;
cout << endl << "Division with maximum sales: " << maxSaleDivision << " Sales amount: " << maxSales;
system("pause");
}
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.