Ejemplo 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
	{
Ejemplo n.º 2
0
int main() {
	Sales_item item;
	item.setIsbn("wuxinting");
	item.pIsbn();
	cout << item.getP() << endl;
	return 0;
}
Ejemplo n.º 3
0
void tractionStatistic()
{
    Sales_item firstItem;
    Sales_item newItem;
    int amount = 1;
    
    if(cin >> firstItem)
    {
        while(cin >> newItem)
        {  
            if (newItem.same_isbn(firstItem))
            {
                /* The original expression is like this: */
                firstItem = firstItem + newItem;
                
                /* rather than this one*/
                //firstItem += newItem;
                
                ++amount;
            }
            else
            {
                cout << "the transaction for the previous one is: "<< firstItem << endl; 
                cout << "the previous transaction count is: "<< amount << endl; 
                /* used for next comparison */
                firstItem = newItem;
                amount = 1;
            }
        }
        
        cout << "the last time transaction is: " << firstItem << endl;
        cout << "the last transaction count is: " << amount << endl;
    }
    else
    {
Ejemplo n.º 4
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();
}
int main(){
    Sales_item item;
    cout<<"Enter some transactions: "<<endl;
    while(item.input(cin)){
        cout<<"The transaction readed is: "<<endl;
        item.output(cout);
        cout<<endl;
    }
    return 0;
}
Ejemplo n.º 6
0
// throws exception if both objects do not refer to the same isbn
Sales_item 
operator+(const Sales_item& lhs, const Sales_item& rhs) 
{
    if (!lhs.same_isbn(rhs))
        throw isbn_mismatch("isbn mismatch",
                            lhs.book(), rhs.book());
    Sales_item ret(lhs);  // copy lhs into a local object that we'll return
    ret += rhs;           // add in the contents of rhs 
    return ret;           // return ret by value
}
Ejemplo n.º 7
0
int main()
{
	Sales_item total , trans;

	if(cin >> total) {
		while(cin >> trans)
			if(total.same_isbn(trans))
				total = total + trans;
			else{
				cout << total << endl;
				total = trans;
			}
		cout << total << endl;
	}else {
Ejemplo n.º 8
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 {
Ejemplo n.º 9
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{
Ejemplo n.º 10
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;
}
Ejemplo n.º 11
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
    {
Ejemplo n.º 12
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;
}
Ejemplo n.º 13
0
unsigned add (const Sales_item &s1, const Sales_item &s2  )
{
	return s1.total_price() + s2.total_price();
}		/* -----  end of function add  ----- */
Ejemplo n.º 14
0
//compare function of Sales_Item for multiset to use
inline bool compare(const Sales_item& rh1,const Sales_item& rh2)
{
    return rh1->book() < rh2->book() ;

}
Ejemplo n.º 15
0
bool compareIsbn(const Sales_item &lhs, const Sales_item &rhs)
{
	return lhs.isbn() == rhs.isbn();
}
Ejemplo n.º 16
0
bool compare ( const Sales_item& i, const Sales_item& j )
{
  return i->book() < j->book();
}
Ejemplo n.º 17
0
bool compare(const Sales_item &s1, const Sales_item &s2)
{
	return s1.isbn() < s2.isbn();
}		/* -----  end of function compareIsbn  ----- */