User Name Password Register
DaniWeb IT Discussion Community
All
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
Reply
Join Date: Jul 2008
Posts: 3
Reputation: Fault is an unknown quantity at this point 
Rep Power: 0
Solved Threads: 0
Fault Fault is offline Offline
Newbie Poster

C++ help needed please

  #1  
Jul 18th, 2008
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
Last edited by Tekmaven : Jul 18th, 2008 at 5:39 am. Reason: Code tags
AddThis Social Bookmark Button
Reply With Quote  
Join Date: Oct 2006
Location: the Netherlands
Posts: 1,598
Reputation: niek_e is just really nice niek_e is just really nice niek_e is just really nice niek_e is just really nice 
Rep Power: 8
Solved Threads: 163
niek_e's Avatar
niek_e niek_e is offline Offline
Posting Virtuoso

Re: C++ help needed please

  #2  
Jul 18th, 2008
Originally Posted by Fault View Post
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...
Reply With Quote  
Join Date: Jul 2008
Posts: 3
Reputation: Fault is an unknown quantity at this point 
Rep Power: 0
Solved Threads: 0
Fault Fault is offline Offline
Newbie Poster

Re: C++ help needed please

  #3  
Jul 18th, 2008
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
Reply With Quote  
Join Date: Sep 2004
Posts: 6,050
Reputation: Narue has much to be proud of Narue has much to be proud of Narue has much to be proud of Narue has much to be proud of Narue has much to be proud of Narue has much to be proud of Narue has much to be proud of Narue has much to be proud of 
Rep Power: 26
Solved Threads: 416
Super Moderator
Narue's Avatar
Narue Narue is offline Offline
Expert Meanie

Re: C++ help needed please

  #4  
Jul 18th, 2008
>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.
Member of: Beautiful Code Club.
Reply With Quote  
Join Date: Jul 2008
Posts: 3
Reputation: Fault is an unknown quantity at this point 
Rep Power: 0
Solved Threads: 0
Fault Fault is offline Offline
Newbie Poster

Re: C++ help needed please

  #5  
Jul 19th, 2008
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
Last edited by Tekmaven : Jul 19th, 2008 at 1:32 pm. Reason: added information
Reply With Quote  
Join Date: Sep 2004
Posts: 6,050
Reputation: Narue has much to be proud of Narue has much to be proud of Narue has much to be proud of Narue has much to be proud of Narue has much to be proud of Narue has much to be proud of Narue has much to be proud of Narue has much to be proud of 
Rep Power: 26
Solved Threads: 416
Super Moderator
Narue's Avatar
Narue Narue is offline Offline
Expert Meanie

Re: C++ help needed please

  #6  
Jul 19th, 2008
>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:
  1. int n1 = 10;
  2.  
  3. if (n1 > 11)
  4. {
  5. if (n1 > 2)
  6. {
  7. n1 = 0;
  8. }
  9. else
  10. {
  11. n1 = 1;
  12. }
  13. }
Member of: Beautiful Code Club.
Reply With Quote  
Join Date: May 2008
Posts: 20
Reputation: tecktalk is an unknown quantity at this point 
Rep Power: 0
Solved Threads: 0
tecktalk tecktalk is offline Offline
Banned

Re: C++ help needed please

  #7  
Jul 19th, 2008
i too think sooo..
______________________
Last edited by Narue : Jul 19th, 2008 at 3:04 pm. Reason: Fake signature
Reply With Quote  
Reply

Only community members can participate in forum threads. You must register or log in to contribute.

Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)

 

DaniWeb C++ Marketplace
Thread Tools Display Modes

Similar Threads
Other Threads in the C++ Forum

All times are GMT -4. The time now is 2:08 am.
Forum system based on vBulletin Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
©2003 - 2008 DaniWeb® LLC