「已注销」 2021-06-08 22:27 采纳率: 55.6%
浏览 7

c++qiujieda。。

 

  • 写回答

1条回答 默认 最新

  • qfl_sdu 2021-06-09 09:21
    关注

    代码如下,如有帮助,请采纳一下,谢谢。

    #include <iostream>
    using namespace std;
    class shang_stock;
    class shen_stock
    {
    private:
    	int general;
    	int st;
    	int pt;
    public:
    	shen_stock(){general = 0; st = 0; pt = 0;}
    	shen_stock(int g,int s,int p):general(g),st(s),pt(p){}
    	friend int caculate(shen_stock sz);
    	friend int count(shen_stock &sz,shang_stock &sh);
    };
    
    class shang_stock
    {
    private:
    	int general;
    	int st;
    	int pt;
    public:
    	shang_stock(){general = 0; st = 0; pt = 0;}
    	shang_stock(int g,int s,int p):general(g),st(s),pt(p){}
    	friend int caculate(shang_stock sh);
    	friend int count(shen_stock &sz,shang_stock &sh);
    };
    int caculate(shen_stock sz)
    {
    	return sz.general + sz.st + sz.pt;
    }
    int caculate(shang_stock sh)
    {
    	return sh.general + sh.st + sh.pt;
    }
    int count(shen_stock &sz,shang_stock &sh)
    {
    	return caculate(sz) + caculate(sh);
    }
    int main()
    {
    	shen_stock sz(1000,28,30);
    	shang_stock sh(2000,40,60);
    	cout << "total number of shen_stock = " << caculate(sz) << endl;
    	cout << "total number of shang_stock = " << caculate(sh) << endl;
    	cout << "total number of shen_stock and shang_stock = " << count(sz,sh);
    	return 0;
    }
    评论

报告相同问题?