Add a third box to the calculation.
Calculate length (L), width (W), and height (H) for the third box.
Calculate the total volume for all three boxes in question.

I have gotten this far but i am unable to fig out how the proper syntax should be for this.


Here is the code :

// Ex7_02.cpp
// Creating and using boxes
#include <iostream>
using std::cout;
using std::endl;

class CBox                             // Class definition at global scope
{
  public:
    double m_Length;                   // Length of a box in inches
    double m_Width;                    // Width of a box in inches
    double m_Height;                   // Height of a box in inches
    
   double Volume()
   {
    return m_Length*m_Width*m_Height;
   }
};

int main()
{
  CBox box1;                           // Declare box1 of type CBox
  CBox box2;  
  CBox box3;
                                       // Declare box2 of type CBox

  double boxVolume = 0.0;             // Stores the volume of a box

  box1.m_Height = 18.0;                // Define the values
  box1.m_Length = 78.0;                // of the members of
  box1.m_Width = 24.0;                 // the object box1
  

  box2.m_Height = box1.m_Height - 10;  // Define box2
  box2.m_Length = box1.m_Length/2.0;   // members in
  box2.m_Width = 0.25*box1.m_Length;   // terms of box1

  box3.m_Height = 20.0;
  box3.m_Length = 56.0;
  box3.m_Width =  30.0; 
 


  // Calculate volume of boxes
  boxVolume = (box1.Volume, box2.Volume, box3.Volume); 

  cout << endl
       << "Volume of box1 = "
	   << box1.Volume;

    cout << endl
       << "Volume of box2 = "
       << box2.Volume(); 
	  
	cout << endl
       << "Volume of box3 = "
       << box3.Volume();

	cout << endl
		<< " Total volume for all three boxes: " 
		<< boxVolume
		<< endl; 

  cout << endl
       << "box1 has sides which total "
       << box1.m_Height+ box1.m_Length+ box1.m_Width
       << " inches.";

    cout << endl
       << "box2 has sides which total "
       << box2.m_Height+ box2.m_Length+ box2.m_Width
       << " inches.";

	  cout << endl
       << "box3 has sides which total "
       << box3.m_Height+ box3.m_Length+ box3.m_Width
       << " inches." << endl;



  cout << endl                         // Display the size of a box in memory
       << "A CBox object occupies "
       << sizeof box1 << " bytes." << endl;  

  cout <<endl;
  system("PAUSE"); 
  return 0;
}

the error i get is
error C3867: 'CBox::Volume': function call missing argument list; use '&CBox::Volume' to create a pointer to member

I am just confused. Any ideas on making this more officiant would be great thank you for your time.

Look at Lines 45 and 49. What's missing...? Hint: You have 4 function calls crammed into 2 lines. You need to add 4 pairs of 2 characters.

Also, line 45 isn't doing what you think it is. You should reconsider the operators you are using there.

While you're at it, look at Line 36. Was that your intent? Based on Lines 34 and 35, I have my doubts.

iv tried for a few hours to fig out how to calculate the total the volume for all three boxes but i can fig out how to properly pass the data to a function to do the calculates here is the code i have so far

// Ex7_02.cpp
// Creating and using boxes
#include <iostream>
using std::cout;
using std::endl;

class CBox                             // Class definition at global scope
{
  public:
    double m_Length;                   // Length of a box in inches
    double m_Width;                    // Width of a box in inches
    double m_Height;                   // Height of a box in inches
    double Volume(void);				// member function prototype	
    double volcalcTotal(void);         // calculate total volume from all three boxes
   
};

 double CBox::Volume()
  {
   
    return m_Length*m_Width*m_Height;
 
    volcalcTotal(); 
  }


 double CBox::volcalcTotal(void)
 {
   
 return 0; 

 }


int main()
{
	



  CBox box1;                           // Declare box1 of type CBox
  CBox box2;                           // Declare box2 of type CBox
  CBox box3;                           // Declare box3 of type CBox
  
  
  box1.m_Height = 18.0;                // Define the values
  box1.m_Length = 78.0;                // of the members of
  box1.m_Width = 24.0;                 // the object box1

  box2.m_Height = box1.m_Height - 10;  // Define box2
  box2.m_Length = box1.m_Length/2.0;   // members in
  box2.m_Width = 0.25*box1.m_Length;   // terms of box1

  box3.m_Height = 10.0;                // Define the values
  box3.m_Length = 67.0;                // of the members of
  box3.m_Width = 24.0;                 // the object box3
  
 
   
 

  cout << endl
       << "Volume of box1 = " << box1.Volume();

   cout << endl
       << "Volume of box3 = " << box2.Volume();

    cout << endl
       << "Volume of box3 = " << box3.Volume() << endl; 

  cout << endl
       << "box1 has sides which total "
       << box1.m_Height+ box1.m_Length+ box1.m_Width
       << " inches.";
 cout << endl
       << "box2 has sides which total "
       << box2.m_Height+ box2.m_Length+ box2.m_Width
       << " inches.";
 cout << endl
       << "box2 has sides which total "
       << box3.m_Height+ box3.m_Length+ box3.m_Width
       << " inches." << endl;

 cout << endl
       << "Total Volume for all three boxes " << endl;
 


  cout << endl                         // Display the size of a box in memory
       << "A CBox object occupies "
       << sizeof box1 << " bytes." << endl;

  system("PAUSE"); 

  cout <<endl;
  return 0;
}

That is not the correct approach. Re-read my previous post. All you need to do is change the operators you're using in Line 45 of your previous version of the program.

You are using the "comma" operator which is basically telling the computer to completely ignore the left-hand and center values and only look at the right-hand value. You need to be using the addition operator ('+'). It's that simple.

In the current version of your program, volcalcTotal() will never run. It is after a return. When execution hits a return statement, it immediately jumps back to wherever it came from before the function was called and ignores the rest of the function.

That is not the correct approach. Re-read my previous post. All you need to do is change the operators you're using in Line 45 of your previous version of the program.

You are using the "comma" operator which is basically telling the computer to completely ignore the left-hand and center values and only look at the right-hand value. You need to be using the addition operator ('+'). It's that simple.

In the current version of your program, volcalcTotal() will never run. It is after a return. When execution hits a return statement, it immediately jumps back to wherever it came from before the function was called and ignores the rest of the function.

so this code

// Calculate volume of boxes

boxVolume = (box1.Volume, box2.Volume, box3.Volume);

change to

// Calculate volume of boxes

boxVolume = (box1.Volume + box2.Volume + box3.Volume);

i get

error C3867: 'CBox::Volume': function call missing argument list; use '&CBox::Volume' to create a pointer to member

error C3867: 'CBox::Volume': function call missing argument list; use '&CBox::Volume' to create a pointer to member

error C2296: '+' : illegal, left operand has type 'double (__thiscall CBox::* )(void)'

error C2297: '+' : illegal, right operand has type 'double (__thiscall CBox::* )(void)'


if i change it to

// Calculate volume of boxes

boxVolume += (box1.Volume, box2.Volume, box3.Volume);

: error C3867: 'CBox::Volume': function call missing argument list; use '&CBox::Volume' to create a pointer to member

You're trying to call a function, but your call isn't formatted properly. Again, re-read my previous post.

int aFunction();  //prototype

int aFunction() {  //function header
  int anInt;
 /* ... do something ... */
  return anInt;
}  //end aFunction()

int aReturn = aFunction();  //function call

Notice what the call has that yours don't.

ok im completly confused ok here is what i have done re read your replies and reverted back to the code i previously had posted the first time around so im back to square 1 and you said that i need to change the operator from (, ) to a (+) i dont understand at all... i have confused my self even more. thank you for your help i really appreciate it i really want to learn and you dong it for me wont allow me to learn and i appreciate the tips you are giving me.

When you call a function, you need to provide arguments to the function. Some functions don't have parameters/arguments. When you call a function that has no parameters/arguments, you still need to provide arguments. To do this, you call it using empty parentheses as in Line 9 of my previous post (post #6).

I have seen it explained before as "the parentheses are the operator that actually causes the function call". I don't know if I agree with this, but it suffices for explanation purposes.

In your case, Volume is a function. As such you need to use it like a function. The problem is you are using it in the lines in question as a variable, not a function.

how would i Calculate the total volume for all three boxes in question. Thats what i dont understand i know that volume does the calculations for each box individually but once that happens how do i store that in a variable to calculate all three?

I'm not sure how much more I can say without giving you the code...

You get a total volume by adding together the return values from calling Volume() on all 3 objects. You have that concept correct, you just need to fix your syntax. What operator is addition?

It is legal to place calls to functions that return values in locations where you would use a variable, you just need to call the function(s) properly. When you do this, the return value just exists and is used, you don't need to store it.

i.e.

int functionCall(int);

int functionCall(int inputVal) {
  int aReturnValue;

  /* various operations to determine aReturnValue */

  return aReturnValue;
}

int result = 0;

result = functionCall(1) + functionCall(2) + functionCall(3);
commented: Hooray for you you finally got through +1

AHHHH ok thank you this was a killer one normally i can fig it out. So simple yet so hard... lame! all part of learning thank you for your time helping me learn ! i wont forget this one hahah.

Be a part of the DaniWeb community

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