Exemplo n.º 1
0
int main()
{
	Sales_item total; // variable to hold data for the next transaction 
	// read the first transaction and ensure that there are data to process
	if(std::cin >> total)
	{
		Sales_item trans; // variable to hold the running sum
		// read and process the remainning transactions
		while(std::cin >> trans)
		{
			// if we're still processing the same book
			if(total.isbn() == trans.isbn())
			{
				total += trans;
			}
			else
			{
				// print results for the previous book

				std::cout << total << std::endl;
				total = trans; // total now refers to the next book
			}
		}
		std::cout << total << std::endl; // print the last transaction
	}
	else
	{
Exemplo n.º 2
0
inline bool
operator==(const Sales_item &lhs, const Sales_item &rhs)
{
	// must be made a friend of Sales_item
	return lhs.units_sold == rhs.units_sold &&
		lhs.revenue == rhs.revenue &&
		lhs.isbn() == rhs.isbn();
}
Exemplo n.º 3
0
int main()
{
    Sales_item total;
    if( cin >> total ){
        Sales_item trans;
        while( cin >> trans ){
            if( total.isbn() == trans.isbn() ){
                total += trans;
            }else{
                cout<< total << endl;
                total = trans;
            }
        }
        cout<< total << endl;
    }else{
Exemplo n.º 4
0
int main()
{
	Sales_item total;
	if(std::cin >> total) {
		Sales_item trans;
		while(std::cin >> trans) {
			if(total.isbn() == trans.isbn()) {
				total += trans;
			}else {
				std::cout << total << std::endl;
				total = trans;
			}
		}
		std::cout << total << std::endl;
	}else {
Exemplo n.º 5
0
int main()
{
	Sales_item total;
	if(cin >> total){
		Sales_item current;
		while(cin >> current){
			if(total.isbn() == current.isbn())
				total += current;
			else{
				cout << total << endl;
				total = current;
			}				
		}
		cout << total << endl;
	}
	return 0;
}
Exemplo n.º 6
0
int main()
{
    Sales_item total;
    if(std::cin >> total){
        Sales_item foo;
        while(std::cin >> foo)
        {
            if(total.isbn() == foo.isbn())
                total += foo;
            else
            {
                std::cout << total << std::endl;
                total = foo;
            }
            std::cout << total << std::endl;
        }
    }
    else
    {
Exemplo n.º 7
0
int main() 
{
	// iterators that can read and write Sales_items
	istream_iterator<Sales_item> item_iter(cin), eof;
	ostream_iterator<Sales_item> out_iter(cout, "\n");

	// store the first transaction in sum and read the next record
	Sales_item sum = *item_iter++; 

	while (item_iter != eof) {
		// if the current transaction (which is in item_iter) 
		// has the same ISBN
	    if (item_iter->isbn() == sum.isbn())
	        sum += *item_iter++; // add it to sum 
		                         // and read the next transaction
	    else {
	        out_iter = sum;      // write the current sum
	        sum = *item_iter++;  // read the next transaction
	    }
	}
	out_iter = sum;  // remember to print the last set of records

	return 0;
}
Exemplo n.º 8
0
bool compareIsbn(const Sales_item &lhs, const Sales_item &rhs)
{
	return lhs.isbn() == rhs.isbn();
}
Exemplo n.º 9
0
bool compare(const Sales_item &s1, const Sales_item &s2)
{
	return s1.isbn() < s2.isbn();
}		/* -----  end of function compareIsbn  ----- */