Hey i have a few random questions that i can't seem to get my head around at the moment.
Any help would be appreciated


1) What criteria would you apply in deciding which of the three forms of loop
to use in a program?

2) What does this function prototype mean?
char aFunction (int x, float & y);

3) How is private data made accessible outside of the class?
(is it friends?)

4)

int n1 = 10;
while (n1 < 5)
{
n1++;
}
int n2 = 10;
do
{
n2++;
} while (n2 < 5);

does n1 and n2 just equal 10?


regards
:(

Hey i have a few random questions that i can't seem to get my head around at the moment.

This smells like homework to me. And we don't give away free homework here.
How about you try to answer the questions yourself and come back with what you have. We'll be more then happy to correct/help you if you show some effort.

good point
1) im still lost on, i know the three types of loop but not the method to discover which one to use and when.

2) the function returns a char, takes an int and a reference as float. int is unchanged and exits but the float is modified?

3) Is it through public member functions that private data can be accessed. They can return and modify data outside of the class ?

4) When i follow through the code i see it as both n1 and n2 = 10. But im sure that cant be simple like that . I know that there stated as = 10. But both n1 and n2 are incrementing while < 5. But its not less than five , its stated as 10 :s

regards

>1) im still lost on, i know the three types of loop but not
>the method to discover which one to use and when.
You use the loop best suited to the problem. For example, if you always execute the body of the loop at least once, a do..while loop may be better suited. If you're looking an exact number of times, a for loop may be better suited.

>2) the function returns a char, takes an int and a reference as float.
>int is unchanged and exits but the float is modified?
Looks good to me, though the float might not be modified. This is the case where a good const guideline makes reading declarations easier.

>3) Is it through public member functions that private data can be accessed.
>They can return and modify data outside of the class ?
That's one correct answer, yes. Basically the public and protected interface of the class can make private data accessible. The interface includes friends.

>4) When i follow through the code i see it as both n1 and n2 = 10.
Please see the do..while example for answer 1 to see why you're not correct.

Thank you for the response im still overlooking question 4
i understand that you execute the code until the while statment is true, correct?
sureley if it has to execute the body at least once n1 must be less than 5, making it 4 and n2 the same?


One more thing this program

int n1 = 10;
if (n1 > 11)
{ if (n1 > 2)
{
n1 = 0;
}
else
{ n1 = 1;
}
}

i worked this out to n1 = 0 as once and expression is tested if(n1>11) is false you move on to execute the next statment. Therefore n1>2 is true and n1=0


oops wanted to check one more thing ok i have this class as follows

class Box {
private:
int height, width, depth;
public:
Box(int, int, int);
~Box();
int volume();
};.

i have the constructor code as - Box(int,int,int)
and the destructor code as - ~Box()

also to work out the volume of the box i used

Int height, width, depth
Box(in,int,int)
Int Volume (Box)

that is all sorry to keep bothering you peeps

regards

>im still overlooking question 4
n1 is 10 because the loop is never executed, 10 is greater than 5, after all. n2 is 11 because the condition is checked after the loop executes once. This analysis falls right out of a direct description of how the while and do..while loops work.

>i worked this out to n1 = 0 as once and expression is tested if(n1>11)
>is false you move on to execute the next statment.
This is correct.

>Therefore n1>2 is true and n1=0
This is not correct. n1 is still 10 because the test fails and nothing happens. Here's the same code with reasonable formatting:

int n1 = 10;

if (n1 > 11)
{ 
  if (n1 > 2)
  {
    n1 = 0;
  }
  else
  { 
    n1 = 1;
  }
}

i too think sooo..
______________________

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.