You are here:

C++/class code translation



I'm using MS Visual C++ 6.0 on WIN XP professional.  I do not understand the idea of a class, mainly how it is written.  I have an assignment that goes like this:

""An open box is to be made from a piece of rectangle cardboard by cutting out squares of equal size from the four corners and bending up the sides. What size should the squares be to obtain a box with largest possible volume?

Design a class to define a specific object to solve the above problem.

The program is worth 20 points and the due date is March 12, 2004 at noon.""

I got the math done, it's just calculus, but going from the algorithm to code is hard, unless I cheated with simple algebra like this:

vol = (w - 2 * c) * c * (l - 2 * c);

Can you give me a template to work with, I figure someone with an input and small calculation like addition, would work.  The text does not help with simple examples.

could you help me out?


PJ, Thank you for your question.

Since your deadline has passed, I assume you have already solved this problem.

If not....

I would design a class that represents an open box. It would have a member variable that represents the size of the cutout squares. It would have a function 'calc' to calculate the box's volume.

I would then apply a standard numerical method for evaluating the maximum volume. One simple algorithm would be to evaluate the volume when the square size is equal to 1/2 of the original square size. The volume in this case should be zero. Next, do the same evaluation for square size equal the last square size divided by two and repeat this step until the maximum volume is found. The direction of modifying the square size depends on whether the volume increases or decreases from the previous step.

Obviously, the use of a class in this case confers no advantage. The teacher is probably just trying hard (but failing) to create a real-world example.

David Spector


All Answers

Answers by Expert:

Ask Experts


David Spector


Highly knowledgeable in the C++ language, Visual C++ (MSVC), Windows API, documentation and other quality-assurance techniques, and debugging. Knowledgeable in MFC, COM, GUI design, and object-oriented design.


I have been a software engineer since 1965. I have been published. My specializations have been: biomedical programming, compiler implementation, and many kinds of Windows programming. I don't do Databases or other business-oriented stuff.

Windows?/DOS Developer's Journal, ACM SIGPLAN Notices, and Computer Science Press.

ICCP Systems Programming Certification
Master's degree equivalent in Computer Science

©2017 All rights reserved.

[an error occurred while processing this directive]