C# .NET - C++ HELP

Asked By make Slimshady
30-Jun-05 10:58 PM
i would like to ask help from u guys.. i dun understand what the below c++ code means. so please help me to explain.

void main()
{
   int hour1,minute1,hour2,minute2,zone[4]={0};
   
   input_time(&hour1,&minute1,&hour2,&minute2);
   duration(hour1,minute1,hour2,minute2,zone);
   printf("\nDurations = (%3d,%3d,%3d,%3d) \n",zone[0],zone[1],zone[2],zone[3]);
   printf("Total charge = $%.2f\n\n",charge(zone));
}

void input_time(int *h1, int *m1, int *h2, int *m2)
{
   printf("\nEnter start time (in hr and min): ");
   scanf("%d %d",h1,m1);
   printf("Enter end time (in hr and min): ");
   scanf("%d %d",h2,m2);
}

void duration(int h1, int m1, int h2, int m2, int z[])
{
   const int limit[4]={6,14,20,24}
   int i=0,temph,tempm;

   temph=h1;
   tempm=m1;

   while (interval (temph,tempm,h2,m2)>0)
      {
         if (temph<limit[i]) 
         {
            if (h2>=limit[i])
               z[i]=interval(temph,tempm,limit[i],0);
            else
               z[i]=interval(temph,tempm,h2,m2);
            temph=limit[i];
            tempm=0;
         }
         i++;
      }   
}

int interval(int h1,int m1,int h2,int m2)
{
   return ((h2*60+m2)-(h1*60+m1));
}

float charge(int z[])
{
   return (float) (z[0]*5+z[1]*10+z[2]*8+z[3]*5)/100;
}

Here is what it does  Here is what it does

30-Jun-05 11:13 PM
the main method is main() and it's the entry point to the code...

You have 4 methods that do the processing for you and they are:
input_time
   The parameters to the method are pointers so the values being passed into the method get changed; they are not copied.
   This method will prompt the user to enter a start time using printf and reads it from the command line using scanf.  It then prompts for the end time and reads it from the command line.

duration
   the paramters to this method are "pass by value" not referenced like the pointers used in input_time so they will not changed when the method returns.  This is not true for z since it is an array and it's storing the calculation for the interval between the times.  there are some special values that are being checked in this too and you can see it in the const int limit.
   
interval
   calculates the interval between two times (in minutes) because it is multiplying by 60.

charge
   z[0]*5+z[1]*10+z[2]*8+z[3]*5)/100;
   Looks like this is taking the 4 intervals and multiplying by the values 5, 10, 8, 5 and adding them together.  This is then being divided by 100.


Good luck with it!

thank u so much  thank u so much

30-Jun-05 11:30 PM
thanks a lot man..
erm, can u explain a bit more on the :
temph=h1
tempm=m1

 and the interval part..

that is just the hour and minute  that is just the hour and minute

30-Jun-05 11:51 PM
That is just the hour and the minute.  It just makes a copy of hr and m1 to be used instead of the original.  They don't do much because tempm gets reset at the bottom of the while loop everytime and the temph gets set the the new limit at the bottom of the while loop.

the interval looks like it just is multiplying the time by 60 and adding the minutes to that calculation and the return value is the difference between them.
Create New Account
help
Handling user input - Float, and globalisation .NET Framework Hi guys, I have a winforms scree, which allows a user to enter a decimal GPS position, such as -27.34212 Problem is, in Romainia, they would enter -27, 34212, and in the US, it would be -27.34212 So what I am doing is handling all float with the Invarient type, and they all get treated as US style. However, when thre that seems very dodgy. Is there a better way for this? C# Discussions Decimal (1) Float (1) Bit (1) Pete Thanks Pete (1) TryParse (1) Craig Lister (1) Arne Cralis (1) Decimal period think you have done what you can do. Arne If you expect the user to enter the data using their current culture's conventions, then you should be parsing the data a google KML file, which expects the US format (point, as opposed to comma, in float type numbers). I have gone with the string.replace, which seems hackey, but it is
Compare< int , int > ; int MyInt = compare.Larger(3, 5); Same function can be used for float as well: Compare< float , float> f_compare = new Compare< float , float > ; float MyFloat = f_compare.Larger(1.23f, 4.32f); Enjoy!!! You might want to look at http always a tad tedious and actually consumed more memory than I'd like it to. Enter .NET 2.0 Predicates and Actions. If you take a look at the documentation for pretty much the same thing as a delegate but it's signature is a little bit different. A Predicate is basically a pointer to a method that will perform a task
Turning off Arithmetic Overflow error SQL Server I want to change the column type from float to Numeric(38, 35). I try the statement, but I get overflow error. Is there not getting this? I do the following to change from current field type, which is float, to Numeric(38, 25). ALTER TABLE [dbo].[InventoryTransactions] ALTER COLUMN [Quantity] [Numeric] (38, 35) NULL Server 2005 (1) SQL Server 2000 (1) SQL Server (1) ALTER TABLE (1) Decimal (1) Float (1) Money (1) Bit (1) Mike9900 (Mike9900@) writes: SET ANSI_WARNINGS OFF SET ARITHABORT OFF Then the values that does way, your text says numeric(38, 25), your code numeric(38, 35). Both seems a bit funny for a column called Quantity. numeric(38, 35) will only fit values up 999 text of the error message - carefully. You are * *not* * starting with a column of datatype float. Regardless of that fact, you are changing the datatype to one that has only three to the error message, the answer is no. The data type of the field is float and it has been fine. It has one value and it is the main unit of measurement, say dozen (DOZ). But a customer is allowed to enter another unit in the UI, say pieces (PCS). But in the server this PCS is
PORTING C" > Why float gets rounded off ??? C++ / VB , Why, float, gets, rounded, off, ???" / > Hello, Okay, this question has to do alot with my previous post that I posted yesterday. I do not understand why the answer (of type float) gets rounded off the the lower number and looses its precision after the decimal. Here is the code again. = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = main.c int main() { unsigned int us_delay = 16; float x; x = (float)RATIO((float)MICRO_SEC, (float)OSC_PERIOD, (float)DELAY_LOOP_IC) * (float)us_delay; return 0; } = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = In response to x, the representauon of the RATIO macro
CComboBox-Droplist: float values? C++ / VB Is there an easy way to have float-valued item data in one of these? VC MFC Discussions PowerPoint (1) CNumEdit.shtml (1 CMyDoubleCombo (1) CMyFloatCombo (1) Comboboxcvar.GetCurSel (1) Edit.GetWindowText (1) AfxMessageBox (1) (a) format the float value as a string (b) add the string to the combo box Now, if it a *sorted* combo box, you have the classic "numeric sort" problem. If you are using 'float', it is fairly easy; you create an owner-draw combo box without LBS_HASSTRINGS and implement CompareItem. Store the float in the itemData part. There is a trick, however: you can't cast a float to an LPARAM without causing it to be converted to an integer, so the trick is to do the following: typedef union { DWORD i; float f; } FLOATHACK. *LPFLOATHACK; (for double, you would do something different, see below) Then you have the following: int CMyFloatCombo::AddString(float f) { FLOATHACK hack; hack.f = f; return CComboBox::AddString( (LPCTSTR)hack.i); } It gets a