Wrox Programmer Forums

Need to download code?

View our list of code downloads.

Go Back   Wrox Programmer Forums > C# and C > C# 1.0 > C#
Password Reminder
Register
| FAQ | Members List | Search | Today's Posts | Mark Forums Read
C# Programming questions specific to the Microsoft C# language. See also the forum Beginning Visual C# to discuss that specific Wrox book and code.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the C# section of the Wrox Programmer to Programmer discussions. This is a community of tens of thousands of software programmers and website developers including Wrox book authors and readers. As a guest, you can read any forum posting. By joining today you can post your own programming questions, respond to other developers’ questions, and eliminate the ads that are displayed to guests. Registration is fast, simple and absolutely free .
DRM-free e-books 300x50
Reply
 
Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old November 20th, 2006, 02:55 PM
Registered User
 
Join Date: Nov 2006
Location: , , .
Posts: 6
Thanks: 0
Thanked 0 Times in 0 Posts
Default c# confused.. bigginer

hi guys i was using wrox professional c# ebook to learn c#.. and i came across the following code in the ebook
Code:
public class Nevermore60Customer : GenericCustomer
   {
      private uint highCostMinutesUsed;
      public override void RecordCall(TypeOfCall callType, uint nMinutes)
      {
         switch (callType)
         {
            case TypeOfCall.CallToLandline:
               balance += (0.02M * nMinutes);
               break;
            case TypeOfCall.CallToCellPhone:
         uint highCostMinutes, lowCostMinutes;
         uint highCostMinutesToGo = 
            (highCostMinutesUsed < 60) ? 60 - highCostMinutesUsed : 0;
         if (nMinutes > highCostMinutesToGo)
         {
            highCostMinutes = highCostMinutesToGo;
            lowCostMinutes = nMinutes - highCostMinutes;
         }
         else
         {
            highCostMinutes = nMinutes;
            lowCostMinutes = 0;
         }
         highCostMinutesUsed += highCostMinutes;
         balance += (0.50M * highCostMinutes + 0.20M * 
            lowCostMinutes);
         break;
            default:
               break;



and i want to knw what is the use of

private uint highCostMinutesUsed;


i mean how do we set the initial value for that n calculation please explain the logic of the use of the above field

(highCostMinutesUsed < 60) ? 60 - highCostMinutesUsed : 0;

what is the use of above code also???
Reply With Quote
  #2 (permalink)  
Old November 21st, 2006, 11:40 AM
Friend of Wrox
 
Join Date: May 2006
Location: San Diego, CA, USA.
Posts: 643
Thanks: 0
Thanked 0 Times in 0 Posts
Default

1 - by the name, it appears that highCostMinutesUsed contains the number of high cost minutes that have been used by a caller over a number of calls. Other than that, I am sure the book must explain the purpose of this code.

2 - In the code, each time RecordCall is invoked with a call type of CallToCellPhone the highCostMinutesUsed variable increased by the number of minutes calculated for the purpose in the conditional block starting with "If (nMinutes > highCostMinutesToGo)"

3 - The initial value for highCostMinutesUsed is 0 when the class is instantiated.

4 - The line "(highCostMinutesUsed < 60) ? 60 - highCostMinutesUsed : 0;" uses a construct called a Conditional Operator, which is the question mark character: "?". It returns one of two values depending on the value of a Boolean expression. The Boolean expression is what comed before the question mark - and must resolve to true or false, the two values follow the question mark and are separated by the colon. If the boolean expression resolves to true, the first value is returned by the operator, and if it resolves to false, the second value is returned.expression of the following

5 - I don't know the purpose of the code beyond what the code is named: It changes some internal varialbs and returns a uint value as an operation named "RecordCall".

Woody Z http://www.learntoprogramnow.com
Reply With Quote
  #3 (permalink)  
Old November 21st, 2006, 03:36 PM
Registered User
 
Join Date: Nov 2006
Location: , , .
Posts: 6
Thanks: 0
Thanked 0 Times in 0 Posts
Default

but for each instance of the class

uint highCostMinutesToGo =
            (highCostMinutesUsed < 60) ? 60 - highCostMinutesUsed : 0;


dis would be alwayz true right??? coz its alwayz 0 when its initializing
Reply With Quote
  #4 (permalink)  
Old November 21st, 2006, 06:33 PM
Friend of Wrox
 
Join Date: May 2006
Location: San Diego, CA, USA.
Posts: 643
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Yes and no. Yes that for each instance the highCostMinutesUsed will be initialized to zero, but as you make multiple calls to the RecordCall on that instance, the result will eventually by greater than 60 - so no, it won't always be true. It will only always be true if you always make only a single call to the RecordCall method for each instance of the object that you create.

We know that this is just sample code, and the use in the sample application isn't typical of how you might use this sort of thing in a real application. As far as the code goes, they probably intend that you would instantiate the class and then make some calls on this method to see how it works. In a production app you would be persisting the data to a data store, such as a database table, and retrieving it the next time you work with the customer.

Woody Z http://www.learntoprogramnow.com
Reply With Quote
Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
confused mohabedalgani VB.NET 2002/2003 Basics 3 March 30th, 2005 11:48 PM
Confused about C# and Access baker_eliz C# 5 November 4th, 2004 05:03 PM
I'm Confused. Help!!! dangel75 General .NET 1 July 10th, 2004 09:54 AM
Confused on error fs22 Javascript 5 June 23rd, 2004 11:53 AM



All times are GMT -4. The time now is 08:33 AM.


Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
© 2013 John Wiley & Sons, Inc.