[0301]统计图书销售信息 (运算符重载)
Description:
Code:
#include<iostream>
#include<cstring>
#include<fstream> 
using namespace std;
struct Sales_Item{
    string name;
    int sum;
    double value;
    
    Sales_Item operator +(const Sales_Item &others){
        Sales_Item tmp;
        tmp.sum=this->sum+others.sum;
        tmp.value=(this->sum*this->value+others.sum*others.value)/tmp.sum;
        tmp.name=this->name;
        return tmp;
    }
    
}; 
istream &operator >>(istream &i,Sales_Item &tmp){
    i>>tmp.name>>tmp.sum>>tmp.value;
    return i;
} 
ostream &operator <<(ostream &o,const Sales_Item &tmp){
    o<<tmp.name<<" "<<tmp.sum<<" "<<tmp.sum*tmp.value<<" "<<(int)tmp.value<<endl;
    return o;
}
int main()
{
    ifstream fin;
    ofstream fout;
    fin.open("Homework1.in");
    fout.open("Homework1.out");
    Sales_Item item1,item2;
    fin>>item1>>item2;
    fout<<item1+item2<<endl;
    fin.close();
    fout.close();
    return ; 
}Runshot:
![[0301]统计图书销售信息 (运算符重载) [0301]统计图书销售信息 (运算符重载)](https://cdn.ancii.com/article/image/v1/sY/fn/RV/VRfYnsfiw8FmOoknmURpINNpVSAFhSOluTdiTXAF7AqO6DEA955G0ZXiPNuHs-AJMUlXlvqpWjTtBLJ6ZGTnD-lT8paoZJE8ROvEaE4_D8GZOxuhX_eLD22vMeorwMyo.png) 
 相关推荐
  mieleizhi0    2019-11-07  
   wbczyh    2019-11-02  
   ppppl    2010-03-17  
   choupiaoyi    2017-10-11  
   ephesians    2016-08-24  
   peterlee    2017-05-04  
   JnX    2010-03-26  
   wztwzt    2019-04-07  
   文山羊    2015-08-19  
   Winterto0    2017-08-27  
   HeyShHeyou    2019-04-26  
   小金屋    2015-06-01  
   uglygirl    2015-05-28  
   chenmingwei    2009-09-04  
   dgdafas    2009-08-31  
   ARTELE    2009-08-12  
   fundebug    2019-03-29  
 