Here's my full assignment below, and then the code I have so far to follow. I'm up to Step 4 of the assignment... need some insight to kickstart my flow. Much appreciated.
The ABC Corporation wishes to review a group of its products based on their performance in the prior fiscal year. The company has the sales data for these products for each quarter in the year. Having heard of your programming experience, the company has hired you to write a complete C program, including comments to do the following:
1. Read in a parameter value n which will indicate how many items should be analyzed. This will be followed by n groups of data each containing information about 1 product. Each group of information will contain the name of the item and then 4 numbers indicating the profit (or loss) made on that item during the 4 quarterly reporting periods. For example, one group of data could be:
Diskettes 32 63 -12 84 or Printers -23 564 45 752. Print the data as it is read in, in the form of a table with one row for each item and one column for each reporting period.
3. Determine the total profit for each item throughout the year. Also determine the total profit for the company and the average profit for each item (total profit/4). Print these values with appropriate messages.
4. For each of the 4 quarters determine which item had the greatest profit for that quarter. Print out the quarter number, item with the most profit and the amount of profit for that item.
5. For each quarter determine how many items had a profit in that quarter and how many items had a loss in that quarter and print those results as well. For each quarter the sum of these two numbers should equal the number of items processed.
6. For each item determine if the profit for that item steadily increased, steadily decreased, or went up and down during the course of the year. Print these results as well.
Data: For this assignment you may use interactive data entry or an external file (easier). Make up your own data and use approximately 10 to 15 items some always profitable some partially and some that lost money. Please cover all possibilities.
Style: Each part of the program should be written using one or more functions. You should decide what parameters to send to these functions.
#include <iostream>
#include <iomanip> //Formatting
#include <fstream> //File operations
using namespace std;
class products {
public:
string item;
int sales[4];
double total;
double avg;
};
void print (products instance);
int main()
{
int n;
int abctotal = 0;
ifstream datafile;
datafile.open("AnnualReport.txt"); //Open input file
datafile >> n;
products records[n];
for (int i=0; i<n; i++){
datafile >> records[i].item; //Read in product name
datafile >> records[i].sales[0]; //Read in said product sales for each quarter...
datafile >> records[i].sales[1];
datafile >> records[i].sales[2];
datafile >> records[i].sales[3];
//Calculate product's total annual profit:
records[i].total = records[i].sales[0] + records[i].sales[1] + records[i].sales[2] + records[i].sales[3];
//Calculate product's average quarterly profit:
records[i].avg = records[i].total/4;
}
cout << left
<< setw(14) << "ITEM"
<< setw(6) << "Q1" << setw(6) << "Q2" << setw(6) << "Q3" << setw(6) << "Q4"
<< setw(7) << "GROSS" << setw(7) << "AVG" << endl << endl;
for (int r=0; r<n; r++)
print (records[r]);
for (int r=0; r<n; r++)
abctotal = abctotal + records[r].total;
cout << "\n" << "ABC Corp. total annual profits = " << abctotal << endl;
datafile.close();
return 0;
}
void print (products instance){
cout << setw(14) << instance.item
<< setw(6) << instance.sales[0]
<< setw(6) << instance.sales[1]
<< setw(6) << instance.sales[2]
<< setw(6) << instance.sales[3]
<< setw(7) << setprecision(0) << fixed << instance.total
<< setw(7) << setprecision(1) << fixed << instance.avg
<< endl;
return;
}