anybody can help me? How to culculate totalsale for each division..
I've tried many time but failed..
my coding is below
#ifndef DIVISIONSALE_H
#define DIVISIONSALE_H
class DivisionSale{
private:
double sales [3];
double totalSales;
public:
DivisionSale(double,double ,double ,double);
double getQuaterSale(int);
double getDivisionSale();
void culculateTotalSale(DivisionSale[], int);
};
#endif
#include "DivisionSale.h"
#include<iostream>
using namespace std;
DivisionSale::DivisionSale(double qtr1, double qtr2, double qtr3, double qtr4){
sales[0] = qtr1;
sales[1] = qtr2;
sales[2] = qtr3;
sales[3] = qtr4;
}
double DivisionSale::getQuaterSale(int y){
return sales[y];
}
double DivisionSale::getDivisionSale(){
return totalSales;
}
void DivisionSale::culculateTotalSale(DivisionSale arr[], int size){
for(int i=0; i<size; i++){
totalSales += arr[i].sales[i];
}
}
#include<iostream>
#include "Division.cpp"
#include<iomanip>
using namespace std;
int main(){
const int NUM_DIVS = 6;
const int NUM_QTRS = 4;
DivisionSale div [NUM_DIVS]={DivisionSale(120.50, 250.65, 300.85, 2000.10),
DivisionSale(789.56, 2500.46, 500.15, 120.60),
DivisionSale(800.55, 950.15, 150.25, 400.22),
DivisionSale(350.29, 450.45, 750.15, 800.25),
DivisionSale(450.50, 500.15, 750.15, 800.25),
DivisionSale(400.65, 650.22, 780.10, 250.35)};
/*for(int i=0; i<NUM_DIVS; i++){
div[i].culculateTotalSale(div,NUM_DIVS);
}*/
cout<< fixed << showpoint << setprecision (2);
for(int i=0; i<NUM_DIVS; i++){
cout<<"Sales for division: "<<(i+1) <<endl;
for(int j=0; j<NUM_QTRS; j++){
cout<<"Quater "<<(j+1)<<" :RM "<< div[i].getQuaterSale(j)<<endl;
}
cout<<"Total Year Sales: "<<div[i].getDivisionSale()<<endl<<endl;
}
system("pause");
return 0;
}