•
•
•
•
What is DaniWeb IT Discussion Community?
You're currently browsing the C++ section within the Software Development category of DaniWeb, a massive community of 397,719 software developers, web developers, Internet marketers, and tech gurus who are all enthusiastic about making contacts, networking, and learning from each other. In fact, there are 2,599 IT professionals currently interacting right now! Registration is free, only takes a minute and lets you enjoy all of the interactive features of the site.
Please support our C++ advertiser:
Views: 262 | Replies: 6
![]() |
•
•
Join Date: Jul 2008
Posts: 3
Reputation:
Rep Power: 0
Solved Threads: 0
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)
does n1 and n2 just equal 10?
regards
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);regards
Last edited by Tekmaven : Jul 18th, 2008 at 5:39 am. Reason: Code tags
•
•
Join Date: Oct 2006
Location: the Netherlands
Posts: 1,598
Reputation:
Rep Power: 8
Solved Threads: 163
•
•
•
•
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.
do NOT pm me for help, it makes me angry. You wouldn't like me when I'm angry...
•
•
Join Date: Jul 2008
Posts: 3
Reputation:
Rep Power: 0
Solved Threads: 0
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.
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.
>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.
Member of: Beautiful Code Club.
•
•
Join Date: Jul 2008
Posts: 3
Reputation:
Rep Power: 0
Solved Threads: 0
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
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
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
that is all sorry to keep bothering you peeps
regards
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;
}
}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
Last edited by Tekmaven : Jul 19th, 2008 at 1:32 pm. Reason: added information
>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:
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:
cplusplus Syntax (Toggle Plain Text)
int n1 = 10; if (n1 > 11) { if (n1 > 2) { n1 = 0; } else { n1 = 1; } }
Member of: Beautiful Code Club.
![]() |
•
•
•
•
Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
•
•
•
•
•
•
•
•
DaniWeb C++ Marketplace
Similar Threads
- Harddrive failure and 100% CPU under Win2K, Help Needed! (Windows NT / 2000 / XP / 2003)
- XP PRO iis help needed (Windows NT / 2000 / XP / 2003)
- CWS. help needed (Viruses, Spyware and other Nasties)
- are all these needed (Windows NT / 2000 / XP / 2003)
- help much needed !! (OS X)
Other Threads in the C++ Forum
- Previous Thread: Is this correct?
- Next Thread: Need an easy way around an access violation



Linear Mode