第四題

#include <iostream>
using namespace std;
class Juzhen                                          
 {
    public:
	  Juzhen();                                         
	  friend Juzhen operator+(Juzhen &,Juzhen &);      
      void input();                                    
      void display();                                    
    private:
      int jz[2][3];
 };

Juzhen::Juzhen()                                     
{
    for(int i=0;i<2;i++)
    for(int j=0;j<3;j++)
    jz[i][j]=0;
}

Juzhen operator+(Juzhen &a,Juzhen &b)               
{
     Juzhen c;
     for(int i=0;i<2;i++)
     for(int j=0;j<3;j++)
     {
	 c.jz[i][j]=a.jz[i][j]+b.jz[i][j];
	 }
     return c;
} 
void Juzhen::input()                                 
{
     cout<<"input value of juzhen:"<<endl;
     for(int i=0;i<2;i++)
     for(int j=0;j<3;j++)
     cin>>jz[i][j];
}

void Juzhen::display()                                
{
     for (int i=0;i<2;i++)
    {
	   for(int j=0;j<3;j++)
       {
	   cout<<jz[i][j]<<" ";
	   }
    cout<<endl;
	}
}

int main()
{
     Juzhen a,b,c;
     a.input();
     b.input();
     cout<<endl<<"Juzhen a:"<<endl; 
     a.display();
     cout<<endl<<"Juzhen b:"<<endl;
     b.display();
     c=a+b;                                        
     cout<<endl<<"Juzhen c = Juzhen a + Juzhen b :"<<endl;
     c.display();
     return 0;
}

發佈了55 篇原創文章 · 獲贊 0 · 訪問量 9274
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章