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

Can someone help me with the C++ code for this program? Description: This progra

ID: 3758697 • Letter: C

Question

Can someone help me with the C++ code for this program?

Description: This program will read a data file that contains book store sales for 12 months. Each month record will contain 6 category book sales (Math, CS, Physics, Chemistry, Biology, Geography). The file will be processed by the program and will produce a report.

The report contains the following parts:
1) The total, highest and lowest sales for each month among 6 category book sales 2) The total, highest and lowest sales for each category book among 12 month.
3) Sorting 12 months in descendent order of the total sale
4) Sorting 6 book categories in descendent order of the total sale
5) Search the sale by user inputting the month and book category
6) The total number of books sold by the book store

(See the attached sample input and output for example.)

Specifications:

1. All input data will be in an input file. The name of the data file that will be used for your program MUST BE sale.dat.

2. You need to use two dimensional array to store the book store sales

3. You need to write several functions in your program: For example: for finding highest, lowest, and total, sorting, and searching etc.

4. You need to do input validation for valid month and book category for searching

Sample Run

Sample Input File sale.dat contains:

Sample Output:
The book store sold a total of 4015 books.

Please Input Month and book category you want to search ( -1 for exit)

Month: Feb
Category: CS
The total sale is 121

Please Input Month and book category you want to search ( -1 for exit)

Month: Nov
Category: Geo
The total sale is 48

Please Input test score you want to search -1
Bye!
Press any key to continue

Explanation / Answer

#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <string>
using namespace std;

int main()
{
int arr[12][6], i, j;
int total_monthly[12], high_monthly[12], low_monthly[12];
int total_subject[6], high_subject[6], low_subject[6];
string Month[12] = {"Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec"};
string subject[6] = {"Math", "CS", "Phy", "Chem", "Bio", "Geo"};

FILE *ip = freopen("sale.dat", "r", stdin);

for(i=0; i<12; i++)
{
sum = 0;
high = 0;
low = 0;
for(j=0; j<6; j++)
{
   cin >> arr[i][j];
   sum += arr[i][j];
   if(arr[i][j] > high) high = arr[i][j];
   if(arr[i][j] < low) low = arr[i][j];
}
total_monthly[i] = sum;
high_monthly[i] = high;
low_monthly[i] = low;
}

//Computing Total High Low for each subject
for(j=0; j<6; j++)
{
sum = 0;
high = 0;
low = 0;
for(i=0; i<12; i++)
{
   sum += arr[j][i];
   if(arr[j][i] > high) high = arr[j][i];
   if(arr[j][i] > low) low = arr[j][i];
}
total_subject[j] = sum;
high_subject[j] = high;
low_subject[j] = low;
}

//Outputting everything

cout << " Month ";
for(j=0; j<6; j++) cout<< subject[j] << " ";
cout << " Total High Low ";

for(i=0; i<12; i++)
{
cout << Month[i] << " ";
for(j=0; j<6; j++) cout << arr[i][j] << " ";
cout << total_monthly[i] << " " << high_monthly[i] << " " << low_monthly[i] << " ";
}

cout << " ";
cout << "Total ";
for(j=0; j<6; j++) cout << total_subject[j] << " ";
cout << " ";
cout << "High ";
for(j=0; j<6; j++) cout << high_subject[j] << " ";
cout << " ";
cout << "Low ";
for(j=0; j<6; j++) cout << low_subject[j] << " ";
cout << " ";


string month, category;
cout << " Please Input Month and book category you want to search ( -1 for exit)";
cout << " Month: "; cin>> month;
if(month == "-1") return;
cout << " Category: "; cin>> category;
cout << " The total sale is " << totSale(month, category);

return 0;
}