zoukankan      html  css  js  c++  java
  • [0301]统计图书销售信息 (运算符重载)

    Description:

    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 0; 
    }

    Runshot:

    RunScreanShot

  • 相关阅读:
    uniapp请求拦截
    stellar视差插件
    fullpage全屏插件应用
    fullpage全屏插件简介
    WdatePicker日期插件
    Ueditor富文本编辑器
    layer弹出层
    验证码绘制
    Ajax跨域访问
    JQuery封装的ajax方法
  • 原文地址:https://www.cnblogs.com/shy-/p/8543888.html
Copyright © 2011-2022 走看看