home bbs files messages ]

Forums before death by AOL, social media and spammers... "We can't have nice things"

   comp.lang.c++.moderated      Moderated discussion of C++ superhackery      33,346 messages   

[   << oldest   |   < older   |   list   |   newer >   |   newest >>   ]

   Message 32,962 of 33,346   
   Ike Naar to nvangogh   
   Re: calculate 'average price' problem   
   01 Apr 13 13:03:15   
   
   From: ike@iceland.freeshell.org   
      
   On 2013-03-31, nvangogh  wrote:   
   > 3. Turning to page 72, there is an introduction to defining 'our own   
   > data structures'. This is the verbatim wording for defining a   
   > 'sales_data' ?: (struct / class? they use the word interchangebly)   
   >   
   > "Although we can't yet write our sales_item class, we can write a more   
   > concrete class that groups the same data elements. Our strategy for   
   > using this class is that users will be able to access the data   
   > elements directly and must implement needed operations for themselves.   
   > Because our data structure does not support any operations, we'll name   
   > our version sales_data to distinguish it from sales_item. We'll define   
   > our class as follows:   
   >   
   > struct sales_data{   
   > std::string bookNo;   
   > unsigned units_sold = 0;   
   > double revenue = 0.0;   
   > }   
      
   This is not the definition that you use in your program,   
   where you have   
      
   struct sales_data   
   {   
     std::string isbn;   
     unsigned units_sold;   
     double unit_price;   
   };   
      
   The first member only differs in name, so let's not worry about that.   
   The last member, though, has a different meaning as well.   
   Where 'revenue' represents the total revenue for the book, 'unit_price'   
   represents the unit price for the book at one specific sales point.   
      
   Your program would become a bit simpler is you would use the struct   
   definition from the book and use 'revenue'. It would eliminate the   
   need for the extra variable 'totalrevenue' which appears to be a   
   source of confusion in your program.   
      
      
   --   
         [ See http://www.gotw.ca/resources/clcm.htm for info about ]   
         [ comp.lang.c++.moderated.    First time posters: Do this! ]   
      
   --- SoupGate-Win32 v1.05   
    * Origin: you cannot sedate... all the things you hate (1:229/2)   

[   << oldest   |   < older   |   list   |   newer >   |   newest >>   ]


(c) 1994,  bbs@darkrealms.ca