Solved

Sequential calculations

Posted on 1998-08-18
10
290 Views
Last Modified: 2010-04-01
I am working on a thermal model of the human body, It has six segment (e.g. arm) each with four layers (e.g. muscle).I
have a class segment and a class layer.  How can I do calculations for the four layers in each segment sequentially, for the six segments?   Each segment will have different values for each attribute.

Thanks,

Regards,
Trevor Coen
0
Comment
Question by:Trevorcoen
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 5
  • 3
  • 2
10 Comments
 
LVL 1

Accepted Solution

by:
jdyer earned 100 total points
ID: 1170632
One way to do this would be to supply the arguments in the constructor. For example, declare the constructor as

public Segment( double layer1, double layer2, double layer3, double layer4 );
{
   this.layerOne = layer1;
   etc....
}

Then create your six segments with the appropriate values and calculate.

Or, a somewhat cleaner, albeit more tedious task would be to subclass your segments. For Example

class Arm : public Segment
class Leg : public Segment
class Head : public Segment
class Torso : public Segment
etc....

And then define the value for the layers in each of your new subclasses.

Hopefully i am understanding your question correctly. Let me know if I can provide more info.

Regards,
  jdyer

0
 
LVL 22

Expert Comment

by:nietod
ID: 1170633
Actually, I don't see any evidence presented in the question, that the different segments need to be different classes.  At least with what you presented they could be different objects of the same class like

Segment Arm;
Segment Leg;
Segment Head;
Segment Torso;

However, the question was
>> How can I do calculations for the four layers in each segment sequentially

I'm guessing that you mean how to perform the simulation.  For that you need some sort of loop that runs many times and performs the calculation on each iteration, like

for (int i = 0; i < 10000; ++i)
{
   Arm.Calculate();
   Leg.Calculate();
   Head.Calculate();
   Torso.Calculate();
   PrintCurrentResults();
}
0
 

Author Comment

by:Trevorcoen
ID: 1170634
Could I please get more info. from jdyer?
 
0
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 1

Expert Comment

by:jdyer
ID: 1170635
I didn't think separate classes were needed either (if you'll see my first comment, nietod). However, it could be a little more elegant if he needs to enter a bazillion parameters (very precise number!) in the constructor. Otherwise, he doesn't.

But for Trevorcoen, here is a little more info.

First off I hope that your definition of Segment looks something like this:

class Segment
{

Layer skin;
Layer muscle;
Layer bone;
Layer fat;

public double Calculate();        // could return anything, I'm using double
public Segment( double layer1, double layer2, double layer3, double layer4 );
}

and the implementation of your constructor is similar to:

public Segment( double layer1, double layer2, double layer3, double layer4 )
{
  skin.SetValue( layer1 );
  muscle.SetValue( layer2 );
  bone.SetValue( layer3 );
  fat.SetValue( layer4 );
}

This assumes that a Layer is essentially a wrapper class for a double-precision value. Really you should just fill in the necessary parameters for the layers in the Segment constructor. You may have three values for each layer for a segment, or whatever. Instead of above it might look like this:

public Segment( double layer1Thickness, int layer1Hardness, char* layer1Name, double layer2Thickness, int layer2Hardness, ETC.....

then Layer.SetValue might look like this:

skin.SetValues( layer1Thickness, layer1Hardness, layer1Name );
muscle.SetValues( layer2Thickness, layer2Hardness, layer2Name );

all Calculate in the segment would do would be to call each layers Calculate() function in succession and save the value returned.

or whatever is needed.

Hope this helps!

Regards,
  jdyer

PS What do you think [nietod], are we on the same base here?
0
 
LVL 22

Expert Comment

by:nietod
ID: 1170636
I agree, I just suspect that isn't what trevocoroen is asking about.  It seems like the question is about calculation in some way, but I'm not sure what his difficulty is.
0
 
LVL 1

Expert Comment

by:jdyer
ID: 1170637
yes, I'm still a little fuzzy on what exactly he's looking for. I guess I'm sorta shooting in the dark on this one. :)

Regards,
  jdyer

Help us out Trevor if this still isn't what you're looking for.
0
 

Author Comment

by:Trevorcoen
ID: 1170638
Sorry if the question was vague.  There is 24 layers altogether for the six segments.  Each has different attributes.  I have to do
several calculations on the attributes of each layer.  I want to write a function and have it go sequentially through the layers.
A friend recommended an array of pointers.  Thanks again.

0
 
LVL 22

Expert Comment

by:nietod
ID: 1170639
You could do

// define a class for storing the data and doing the calculation.
class Layer
{
   // data members to calculate on.
  void calculate(); // Calculate on current data members.
}

// define your 24 layer objects.
Layer ArmMuscle;
Layer ArmSkin;
// etc.

// define a table of 24 layers.
Layer *LayerTable[24]  = {&ArmMuscle,&ArmSkin, etc };

// Calculate for the 24 layers in the table.
for (int i = 0; i < 24; ++i)
   LayerTable[i]->Calculate()
0
 
LVL 22

Expert Comment

by:nietod
ID: 1170640
Another approach is to define 2 class jdyer suggested.  You would do

class Layer
{
   // data members to calculate on.
    void calculate(); // Calculate on current data members.
} ;

// Define a segment class that has all 4 layers included and has a
// single calculate() procedure that calls the 4 layer's calculate()
// procedure.
class  Segment
{
   Layer muscle;
   Layer skin;
   // etc

   void calculate()
   {
      muscle.calculate()
      skin.calculate();
   }
};

// Then define your 6 segments
Segment Arm;
Segment Head;

// Then you ned to call calculate one each Segment, rather than each layer, like
Arm.Calculate();
Head.Calculate();

Does that help at all?
0
 
LVL 22

Expert Comment

by:nietod
ID: 1170641
We've been assuming you want to do the calculation in a class.  If not, let me know, the array of pointers answer could be changed to provide data to a non-class procedure.
0

Featured Post

Free Tool: Postgres Monitoring System

A PHP and Perl based system to collect and display usage statistics from PostgreSQL databases.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
Arduino EDI - Programming language 3 114
Outlook 13 80
Finding Divisors 5 35
Can Live bindings change TGrid Cell Colour ? 1 30
Written by John Humphreys C++ Threading and the POSIX Library This article will cover the basic information that you need to know in order to make use of the POSIX threading library available for C and C++ on UNIX and most Linux systems.   [s…
Go is an acronym of golang, is a programming language developed Google in 2007. Go is a new language that is mostly in the C family, with significant input from Pascal/Modula/Oberon family. Hence Go arisen as low-level language with fast compilation…
The goal of the video will be to teach the user the concept of local variables and scope. An example of a locally defined variable will be given as well as an explanation of what scope is in C++. The local variable and concept of scope will be relat…
The viewer will learn how to user default arguments when defining functions. This method of defining functions will be contrasted with the non-default-argument of defining functions.

763 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question