Corporate sales

Sorry if this post is a little lengthy

Page 1 of 1

6 Replies - 4088 Views - Last Post: 01 May 2009 - 04:39 AM Rate Topic: -----

#1 Choko  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 11
  • Joined: 21-April 09

Corporate sales

Post icon  Posted 30 April 2009 - 02:00 PM

So I'll just type out exactly what it is the assignment is asking of me and see if there is anyone out there that can help me with a step up.

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 members:

Req's:

1. Needs an array with four elements for holding four quarters of sales figures for the division.

2. Needs a private static variable for holding the total corporate sales for all divisions for the entire year.

3. Needs A member function that takes four arguments, each assumed to be the sales for a quarter. ALSO, this member function needs to 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.

4. 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.

Essentially, the program needs to be created with sic DivSales objects. It should ask the user to enter the sales for four quarters of each division. After the data is entered, the program should display a table showing the division sales for each quarter. Then is should display the total sales for the year.

Here is all I have. Sorry it's so little, but it's all my mind is wrapping around:

class DivSales
{
	  private:
			  float totalsales;
			  float q1;
			  float q2;
			  float q3;
			  float q4;
			  
	  public:
			 DivSales(float q1 = 0, float q2 = 0, float q3 = 0, float q4 = 0)
			 
			 void setSales();
			 
			 
};

int main()
{
	


I don't really understand arrays or how to set them up very well. I also am confused on how to copy a value into an array. And also I am confused on how to create a subscript or use them.

Any help on helping me get started would be great. Thank you so much.

Is This A Good Question/Topic? 0
  • +

Replies To: Corporate sales

#2 JackOfAllTrades  Icon User is offline

  • Saucy!
  • member icon

Reputation: 6048
  • View blog
  • Posts: 23,473
  • Joined: 23-August 08

Re: Corporate sales

Posted 30 April 2009 - 02:06 PM

An array tutorial
Was This Post Helpful? 0
  • +
  • -

#3 Choko  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 11
  • Joined: 21-April 09

Re: Corporate sales

Posted 30 April 2009 - 02:16 PM

View PostJackOfAllTrades, on 30 Apr, 2009 - 01:06 PM, said:




this doesn't really help me find a relation that I can apply here. How do you copy into an array?

would I write the array I need like this:

 float QSales[4] = {0, 0 ,0 ,0}


Was This Post Helpful? 0
  • +
  • -

#4 eker676  Icon User is offline

  • Software Engineer
  • member icon

Reputation: 378
  • View blog
  • Posts: 1,833
  • Joined: 18-April 09

Re: Corporate sales

Posted 30 April 2009 - 02:38 PM

You could but this would be easier:
Whenever you are initializing arrays to zero all you have to do is put one zero in the brackets.
float QSales[4] = {0};

This post has been edited by eker676: 30 April 2009 - 02:38 PM

Was This Post Helpful? 0
  • +
  • -

#5 Choko  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 11
  • Joined: 21-April 09

Re: Corporate sales

Posted 30 April 2009 - 02:48 PM

View Posteker676, on 30 Apr, 2009 - 01:38 PM, said:

You could but this would be easier:
Whenever you are initializing arrays to zero all you have to do is put one zero in the brackets.
float QSales[4] = {0};



Is this the proper way to set up an array so values can later be copied into it?
Was This Post Helpful? 0
  • +
  • -

#6 eker676  Icon User is offline

  • Software Engineer
  • member icon

Reputation: 378
  • View blog
  • Posts: 1,833
  • Joined: 18-April 09

Re: Corporate sales

Posted 30 April 2009 - 08:24 PM

float QSales[4] = {0}


That code is the exact same as the code you posted. There is no difference. Your code is just longer.

I pointed out this capability so you would know that you can do this instead of initializing 100 array indices to zero manually.

This post has been edited by eker676: 30 April 2009 - 08:25 PM

Was This Post Helpful? 0
  • +
  • -

#7 JackOfAllTrades  Icon User is offline

  • Saucy!
  • member icon

Reputation: 6048
  • View blog
  • Posts: 23,473
  • Joined: 23-August 08

Re: Corporate sales

Posted 01 May 2009 - 04:39 AM

View PostChoko, on 30 Apr, 2009 - 04:16 PM, said:

View PostJackOfAllTrades, on 30 Apr, 2009 - 01:06 PM, said:




this doesn't really help me find a relation that I can apply here. How do you copy into an array?

Maybe you should actually read it and try to understand it.

View PostChoko, on 30 Apr, 2009 - 04:16 PM, said:

would I write the array I need like this:

 float QSales[4] = {0, 0 ,0 ,0}



That will only work in initializing the array, and I would suggest float QSales[4] = { 0.0 };.

You write into the array by writing to the element index you wish to change. If you want to change the second element, you do:
// Note index of 1 for the second element because 
// arrays are ALWAYS indexed starting from 0
QSales[1] = 4.5;

Was This Post Helpful? 1
  • +
  • -

Page 1 of 1