Comparing and assigning strings Would you please run through this code and provide your comments?

void quote_container::allocate(string *i_string, string *i_value){
    string temp_name = *i_string;
    double temp_value; 

    // Convert the input string to upper case. 
    stringToUpper(temp_name);

    if (temp_name =="OPEN"){
        temp_value = atof( (*i_value).c_str() );
        open = (float)temp_value;
    }
    else if (temp_name =="DAYHIGH") {
        temp_value = atof( (*i_value).c_str() );
        high  = (float)temp_value;
    }
    else if (temp_name =="DAYLOW") {
        temp_value = atof( (*i_value).c_str() );
        low  = (float)temp_value;
    }
    else if (temp_name =="LOW52") {
        temp_value = atof( (*i_value).c_str() );
        year_low  = (float)temp_value;
    }
    else if (temp_name =="HIGH52") {
        temp_value = atof( (*i_value).c_str() );
        year_high  = (float)temp_value;
    }
    else if (temp_name =="PRICEBANDLOWER") {
        temp_value = atof( (*i_value).c_str() );
        lower_price_band  = (float)temp_value;
    }
    else if (temp_name =="PRICEBANDUPPER") {
        temp_value = atof( (*i_value).c_str() );
        upper_price_band  = (float)temp_value;
    }
    else if (temp_name =="TOTALBUYQUANTITY"){
        temp_value = atof( (*i_value).c_str() );
        tbq  = temp_value;
    }
    else if (temp_name =="TOTALSELLQUANTITY") {
        temp_value = atof( (*i_value).c_str() );
        tsq  = temp_value;
    }
    else if (temp_name == "BUYQUANTITY5" || temp_name == "BUYQUANTITY4" || temp_name == "BUYQUANTITY3"|| 
        temp_name == "BUYQUANTITY2"|| temp_name == "BUYQUANTITY1") {
        temp_value = atof( (*i_value).c_str() );
        tbq2  = tbq2 + temp_value;
    }
    else if (temp_name == "SELLQUANTITY5" || temp_name == "SELLQUANTITY4" || temp_name == "SELLQUANTITY3"|| 
        temp_name == "SELLQUANTITY2" || temp_name == "SELLQUANTITY1")  {
            temp_value = atof( (*i_value).c_str() );
        tsq2  = (float)tsq2 + temp_value;
    }
    else if (temp_name == "BUYPRICE1" || temp_name == "BUYPRICE2" || temp_name == "BUYPRICE3"|| 
        temp_name == "BUYPRICE4" || temp_name == "BUYPRICE5") {
            temp_value = atof( (*i_value).c_str() );
        avg_buy_price  = avg_buy_price + (float)temp_value ;
    }
    else if (temp_name == "SELLPRICE5" || temp_name == "SELLPRICE4" || temp_name == "SELLPRICE3"|| 
        temp_name == "SELLPRICE2" || temp_name == "SELLPRICE1") {
            temp_value = atof( (*i_value).c_str() );
        avg_sell_price  =  tsq2 + (float)temp_value;
    }
    else if (temp_name == "FACEVALUE") {
        temp_value = atof( (*i_value).c_str() );
        face_value = (float)temp_value;
    }
    else if (temp_name == "PREVIOUSCLOSE") {
        temp_value = atof( (*i_value).c_str() );
        prev_close = (float)temp_value;
    }
    else if (temp_name == "LASTPRICE") {
        temp_value = atof( (*i_value).c_str() );
        last_price = (float)temp_value;
    }
    else if (temp_name == "TOTALTRADEDVOLUME") {
        temp_value = atof( (*i_value).c_str() );
        ttv = (float)temp_value;
    }
    else
        cout &lt;&lt;"\n\t Ignoring --"&lt;&lt;temp_name&lt;&lt;"---"&lt;&lt;*i_value;

}


Also

void quote_container::stringToUpper(string &amp;s)
{
   for(unsigned int l = 0; l &lt; s.length(); l++) 
    s[l] = toupper(s[l]);  
}


Could the above code be improved in any way?
Lets start with the simple one:

void quote_container::stringToUpper(string &amp;s)
{
   for(unsigned int l = 0; l &lt; s.length(); l++) 
    s[l] = toupper(s[l]);  
}


How about:

std::transform(s.begin(), e.end(), s.begin(), ::toupper);


Knowledge of the standard library is very useful.

Never pass anything as a pointer (this is C++ not C).

void quote_container::allocate(string *i_string, string *i_value){


I see no testing of i_string or i_value for NULL so they can't be NULL so there is no need to pass them as pointers. So you should be passing them as references. Since neither value is modified by the function you should also probably be passing them as const to prevent accidental modification of the original value.

void quote_container::allocate(string const&amp; iString, string const&amp; iValue){


Don't explicitly cast values.

open = (float)temp_value;
 //    ^^^^^^^


This is code smell. If you must cast (and usually you should not) then use one of the C++ cast operators (there should never be a need to use a C cast operator (as above)). But in this case it looks like it is not needed. If you don't cast the same conversion will happen anyway.

In this case

avg_buy_price  = avg_buy_price + (float)temp_value ;


You are getting worse results. Let the compiler to the cast for you. If you had let the compiler do the cast for you with:

avg_buy_price  = avg_buy_price + temp_value;

// Then the compiler would have generated this code
avg_buy_price  = static_cast&lt;float&gt;(static_cast&lt;double&gt;(avg_buy_price) + temp_value);


This way you would have retained a tiny bit more accuracy during the addition (which may have mattered). Before you cast it back to float.

As mentioned by "The Dr" (MrSmith) above factor out any common code. But I would do it differently. Put all your conditions in a map to make the code more readable. You actually have two types of assignment. The first is simple assignment while the second is accumulation. So we break these two types of action into their own maps

std::map&lt;std::string, float*&gt; assign= {
    {"OPEN",             &amp;open},
    {"DAYHIGH",          &amp;high},
    {"DAYLOW"            &amp;low},
    {"LOW52",            &amp;year_low},
    {"HIGH52",            &amp;year_high},
    {"PRICEBANDLOWER",    &amp;lower_price_band},
    {"PRICEBANDUPPER",    &amp;upper_price_band},
    {"TOTALBUYQUANTITY",  &amp;tbq},
    {"TOTALSELLQUANTITY", &amp;tsq},
    {"FACEVALUE",         &amp;face_value},
    {"PREVIOUSCLOSE",     &amp;prev_close},
    {"LASTPRICE",         &amp;last_price},
    {"TOTALTRADEDVOLUME", &amp;ttv}
  };
std::map&lt;std::string, float*&gt; accum = {
  {"BUYQUANTITY5",   &amp;tbq2},
  {"BUYQUANTITY4",   &amp;tbq2},
  {"BUYQUANTITY3",   &amp;tbq2},
  {"BUYQUANTITY2",   &amp;tbq2},
  {"BUYQUANTITY1",   &amp;tbq2},
  {"SELLQUANTITY5",  &amp;tsq2},
  {"SELLQUANTITY4",  &amp;tsq2},
  {"SELLQUANTITY3",  &amp;tsq2},
  {"SELLQUANTITY2",  &amp;tsq2},
  {"SELLQUANTITY1",  &amp;tsq2},
  {"BUYPRICE1",      &amp;avg_buy_price},
  {"BUYPRICE2",      &amp;avg_buy_price},
  {"BUYPRICE3",      &amp;avg_buy_price},
  {"BUYPRICE4",      &amp;avg_buy_price},
  {"BUYPRICE5"       &amp;avg_buy_price},
  {"SELLPRICE5",     avg_sell_price}, /*avg_sell_price  =  tsq2 + (float)temp_value;*/
  {"SELLPRICE4",     avg_sell_price}, /* I assumed this was a copy paste mistake you */
  {"SELLPRICE3",     avg_sell_price}, /* made. If it is not then this array is slightly */
  {"SELLPRICE2",     avg_sell_price}, /* More complex for SELL (but not much) */
  {"SELLPRICE1",     avg_sell_price}
 };


Now that we have all the data stored in maps the code is highly simplified.

 std::map&lt;std::string,float*&gt;::const_iterator find;
 find = assign.find(iString);
 if (find != assign.end())
 {
     (*find-&gt;second) = atof( iValue.c_str() );
 }
 else
 {
     find = accum.find(iString);
     if (find != accum.end())
     {
         (*find-&gt;second) += atof( iValue.c_str() );
     }
     else
     {
         std::cout &lt;&lt; "\n\t Ignoring --" &lt;&lt; iString &lt;&lt; "---" &lt;&lt; iValue;
     }
 }


You can compreses the two maps into a single map (and thus reduce the code here) by using a functor or class abstraction as described by (@utnapistim) in his answer. Personally I would go with using std::function rather than building my own class hierarchy (but that's a you say potato I say tomato argument and down to personal preference).