A corporation has six divisions, each responsible for sales to different geographic locations.
Design a DivSales class that keeps sales data for a division, with the following
• An array with four elements for holding four quarters of sales figures for the division
• A private static variable for holding the total corporate sales for all divisions for the
entire year.
• A member function that takes four arguments, each assumed to be the sales for a quarter.
The value of the arguments should be copied into the array that holds the sales data.
The total of the four arguments should be added to the static variable that holds the total yearly corporate sales.

•A function that takes an integer argument within the range of 0 to 3.

The argument is to be used as a subscript into the division quarterly sales array.

The function should return the value of the array element with that subscript.

Write a program that creates an array of six DivSales objects. The program should ask the user to enter the sales for four quarters for each division.

After the data is entered, the program should display a table showing the division sales for each quarter.

The program should then display the total corporate sales for the year.

Input Validation: Only accept positive values for quarterly sales figures.

// I cant figure it out the total corporate sales, and the member function for quartely on each division ***


#include <iomanip>
#include <cmath>
#include <iostream>
using namespace std;

class DivSales      // Class name

private:            //Private function variables
 float corpSales;       // it has to be static, but when i try it it gives me error
float divSales;

DivSales() {divSales = 0;}  //constructor initialization, not sure of this

                            // here it suppose to be an member function with array for the quarterly but i don't understand how to do it.

void addDivSales (float s)          // Member function passing parameter
{ divSales += s; corpSales += divSales;}        // operations (not quite sure)
 float getDivisionSales () {return divSales;}   // returning values for displaying
  float getCorpSales () { return corpSales;}


int main ()


DivSales divisions [6];     //class with object array

int count;

for (count = 0; count < 6; count ++)     //loop for prompting user for values
float sal = 0;  // variable initialization

cout << "Enter the sales for each division ";     //prompting user

cout << (count + 1) << " : ";       //displaying the loop divisions
while (sal < 1)                      // input validation.. not negative numbers
cin >> sal;
divisions[count].addDivSales(sal);      // passing sal to member function addDivsales to do operation
if (sal < 1)
cout << "Enter a positive number: \n";    //  input validation

cout << setprecision(2);
cout << showpoint << fixed;
cout << "\nHere are the division sales: \n";

for (count = 0; count < 6; count++)      //loop for displaying the numbers the user input
cout << "Division " << (count + 1) << " $ ";
cout << divisions[count].getDivisionSales() << endl;    // not quite sure, i follow instructions from my course.. 
                                                        // but it display what user put into each division, guess it adds s to divSales


cout << "Total corporate sales:\t$ ";             
cout << divisions[0].getCorpSales() << endl;        // displaying the TOTAL CORPORATE SALES on the member function ( but I get wrong number )

return 0;


Recommended Answers

Why did you start a NEW thread? And why did you ignore this help?

Jump to Post

All 2 Replies

Why did you start a NEW thread? And why did you ignore this help?

On the static variable part: you have to initialise a static variable to something, so just doing this won't work:

class MyClass
public :
    void AddOne(){ ++myStaticVar; }
    float Get() const { return myStaticVar; }
private :
    float myStaticVar;

You will get a compilation error. The variable must be initialised somewhere outside the class:

class MyClass
public :
    void AddOne() { ++myStaticVar; }
    float Get() const { return myStaticVar; }
private :
    float myStaticVar;

float MyClass::myStaticVar = 0.0;

int main()
    /* ... */

Then everything should be OK.

You might also want to re-read the question. It says that the addDivSales function should take four arguments, one for each quarter. Your function only takes a single argument. You should also have an array to store the values for each quater. and the getDivSales function should take a single int argument to tell it which quater to return the sales for.

Have fun :)

Be a part of the DaniWeb community

We're a friendly, industry-focused community of 1.21 million developers, IT pros, digital marketers, and technology enthusiasts learning and sharing knowledge.