Dec 9, 2015 at 6:12am Dec 9, 2015 at 6:12am UTC
I almost have this complete but I am not sure how to change my input collection. Directions are to: You have to change your input collection to get 4 values (quarterly sales) before calling that one function that stores them in the array.
Any help is appreciated, Thanks!!
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85
#include <iomanip>
#include <cmath>
#include <iostream>
using namespace std;
class DivSales // Class name
{
private : // Private members
static float corpSales;
float divSales[4]; //stores quarterly sales per division
public :
// Constructor initialization
DivSales()
{
divSales[4] = {0.0,0.0,0.0,0.0};
}
// Member function passing parameter
void addDivSales (float s1, float s2, float s3, float s4)
{ // Equation operations
divSales[0] = s1;
divSales[1] = s2;
divSales[2] = s3;
divSales[3] = s4;
corpSales += s1 + s2 + s3 + s4;
}
// Return quarterly values to display
float getDivisionSales (int qtr)
{
return divSales[qtr];
}
// Return corporate values to display
static float getCorpSales ()
{
return corpSales;
}
};
//initializing static data member
float DivSales::corpSales = 0.0;
// Main
int main ()
{
DivSales divisions [6]; // Object array class
int count;
for (count = 0; count < 6; count ++) //loop for prompting user for values
{
float sales = 0; // Initialize variables
cout << "Enter the sales for each division " ; // Get user inputs
cout << (count + 1) << " : " ; // Display loop divisions
while (sales < 1) // Validates that inputs are greater than 1
{
cin >> sales;
divisions[count].addDivSales(sales); // Passes sale to addDivsales to complete the operation
if (sales < 1)
cout << "Enter a positive number: \n" ; // Validates that inputs are greater than 1
}
}
cout << setprecision(2);
cout << showpoint << fixed;
cout << "\nHere are the division sales: \n" ;
for (count = 0; count < 6; count++) // Loops to display user inputs on sales
{
cout << "Division " << (count + 1) << " $ " ;
cout << divisions[count].getDivisionSales() << endl;
}
cout << "Total corporate sales:\t$ " ;
cout << divisions[0].getCorpSales() << endl; // Displays total corporate sales
return 0;
}
Last edited on Dec 9, 2015 at 6:12am Dec 9, 2015 at 6:12am UTC
Dec 9, 2015 at 6:42am Dec 9, 2015 at 6:42am UTC
a) line 12: float divSales[4] = { 0 }; //stores quarterly sales per division
b) delete line 18
c) line 65: the logic of this is wrong. You need to collect the four sales values and send them all at once via the function addDivSales i.e. s1 , s2 , s3 and s4
void addDivSales (float s1 , float s2 , float s3 , float s4 )
Last edited on Dec 9, 2015 at 7:14am Dec 9, 2015 at 7:14am UTC
Dec 9, 2015 at 7:12am Dec 9, 2015 at 7:12am UTC
you need to replace line 12 with what I wrote :)
Dec 9, 2015 at 7:13am Dec 9, 2015 at 7:13am UTC
Sorry replace with this my bad : float divSales[4] = { 0 };
Dec 9, 2015 at 7:17am Dec 9, 2015 at 7:17am UTC
Ahh that worked! I am still confused on line 65 and how to change the collection to 4 inputs. Sorry I am really slow at learning this.
Dec 9, 2015 at 7:20am Dec 9, 2015 at 7:20am UTC
Wait, my error is not line 65, it is line 78 of the first code and line 76 on the second time I sent it.
Dec 9, 2015 at 7:25am Dec 9, 2015 at 7:25am UTC
Have a think about it but I reckon you need an array of sales in main, it would have 4 elements that you collect the data on in a loop and then send to addDivSales( float[] sales) instead of 4 separate values. See if it makes sense.
Dec 9, 2015 at 7:41am Dec 9, 2015 at 7:41am UTC
Okay, I will do that. thank you very much!
Dec 9, 2015 at 8:02am Dec 9, 2015 at 8:02am UTC
Cheers, you still have to make a few changes elsewhere to make it compatible with this change. Yell out if you have any queries. Cheers :)