#include <iostream>
#include <string>
#include <vector>
#include <cctype>
#include <cstdlib>
#include <stdexcept>
#include <initializer_list>
struct SalesData
{
std:: string book_no;
unsigned units_sold = 0 ;
double revenue = 0.0 ;
std:: istream & read ( std:: istream & , SalesData& ) ;
SalesData ( ) = default ;
SalesData ( const std:: string & s) : book_no( s) { }
SalesData ( const std:: string & s, unsigned n, double p)
: book_no( s) , units_sold( n) , revenue( p* n) { }
SalesData ( std:: istream & is)
{
read ( is, * this ) ;
}
std:: string isbn( ) const { return book_no; }
SalesData& combine( const SalesData& ) ;
double avg_price( ) const ;
} ;
SalesData add ( const SalesData& , const SalesData& ) ;
std:: ostream & print ( std:: ostream & , const SalesData& ) ;
// std::istream &read (std::istream&, SalesData&);
double SalesData:: avg_price ( ) const
{
if ( units_sold)
return revenue/ units_sold;
else
return 0 ;
}
SalesData& SalesData:: combine ( const SalesData & rhs)
{
units_sold + = rhs.units_sold ;
revenue + = rhs.revenue ;
return * this ;
}
std:: istream & read ( std:: istream & is, SalesData & item)
{
double price = 0.0 ;
is >> item.book_no >> item.units_sold >> price;
item.revenue = price * item.units_sold ;
return is;
}
std:: ostream & print ( std:: ostream & os, const SalesData & item)
{
os << item.isbn ( ) << " " << item.units_sold <<
" " << item.revenue << " " << item.avg_price ( ) ;
return os;
}
SalesData add ( const SalesData & lhs, const SalesData & rhs)
{
SalesData sum = lhs;
sum.combine ( rhs) ;
return sum;
}
int main( )
{
SalesData total( std:: cin ) , trans( std:: cin ) , sum;
std:: cout << total.revenue << trans.revenue << std:: endl ;
print ( std:: cout , total) << std:: endl ;
print ( std:: cout , trans) << std:: endl ;
sum = add ( trans, total) ;
total.combine ( trans) ;
print ( std:: cout , sum) << std:: endl ;
print ( std:: cout , total) << std:: endl ;
return 0 ;
}
I2luY2x1ZGUgPGlvc3RyZWFtPgojaW5jbHVkZSA8c3RyaW5nPgojaW5jbHVkZSA8dmVjdG9yPgojaW5jbHVkZSA8Y2N0eXBlPgojaW5jbHVkZSA8Y3N0Z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N0ZDo6Y291dCwgdHJhbnMpIDw8IHN0ZDo6ZW5kbDsKCglzdW0gPSBhZGQgKHRyYW5zLCB0b3RhbCk7Cgl0b3RhbC5jb21iaW5lICh0cmFucyk7CgoJcHJpbnQgKHN0ZDo6Y291dCwgc3VtKSA8PCBzdGQ6OmVuZGw7CglwcmludCAoc3RkOjpjb3V0LCB0b3RhbCkgPDwgc3RkOjplbmRsOwoJcmV0dXJuIDA7Cn0=
compilation info
/home/8T7H6O/ccSvktTR.o: In function `SalesData::SalesData(std::istream&)':
prog.cpp:(.text._ZN9SalesDataC2ERSi[_ZN9SalesDataC5ERSi]+0x23): undefined reference to `SalesData::read(std::istream&, SalesData&)'
collect2: error: ld returned 1 exit status
stdout