C++中重載和運(yùn)算符重載加號(hào)實(shí)現(xiàn)矩陣相加的示例分析

小編給大家分享一下C++中重載和運(yùn)算符重載加號(hào)實(shí)現(xiàn)矩陣相加的示例分析,相信大部分人都還不怎么了解,因此分享這篇文章給大家參考一下,希望大家閱讀完這篇文章后大有收獲,下面讓我們一起去了解一下吧!

成都創(chuàng)新互聯(lián)公司始終堅(jiān)持【策劃先行,效果至上】的經(jīng)營(yíng)理念,通過(guò)多達(dá)10多年累計(jì)超上千家客戶的網(wǎng)站建設(shè)總結(jié)了一套系統(tǒng)有效的全網(wǎng)營(yíng)銷解決方案,現(xiàn)已廣泛運(yùn)用于各行各業(yè)的客戶,其中包括:成都木屋等企業(yè),備受客戶好評(píng)。

 C++ 重載+運(yùn)算符重載加號(hào) 實(shí)現(xiàn)矩陣相加

實(shí)例代碼:

#include<iostream>
#include<iomanip>
using namespace std;
class Complex
{
  private:
    int i,j,n,a[2][3];
  public:
    Complex();
    Complex operator+(Complex &c);
    void display();
    void input();
} t1;


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


 void Complex::input()
 {
  for(i=0;i<2;i++)
   for(j=0;j<3;j++)
   cin>>a[i][j];
 } 
 void Complex::display()
 {
  n=1;
  for(i=0;i<2;i++)
   for(j=0;j<3;j++)
   {
    n++;
    if(n%2==0)
    cout<<endl;
    cout<<setw(5)<<a[i][j];
   }
   cout<<endl; 
 }
Complex Complex::operator+(Complex &c)
{
  for(int i=0;i<2;i++) 
   for(int j=0;j<3;j++) 
  t1.a[i][j]=a[i][j]+c.a[i][j];
  return t1; 
}

int main()
{
  Complex t2,t3,t4;
  cout<<"請(qǐng)輸入2*3個(gè)整數(shù)"<<endl; 
  t2.input();
  cout<<endl;
  cout<<"請(qǐng)輸入2*3個(gè)整數(shù)"<<endl; 
  t3.input();
  cout<<endl;
  cout<<"t2";
  t2.display();
  cout<<"t3";
  t3.display();
  t4=t2+t3;
  cout<<"t4=t2+t3=";
  t4.display();
  return 0;
}

以上是“C++中重載和運(yùn)算符重載加號(hào)實(shí)現(xiàn)矩陣相加的示例分析”這篇文章的所有內(nèi)容,感謝各位的閱讀!相信大家都有了一定的了解,希望分享的內(nèi)容對(duì)大家有所幫助,如果還想學(xué)習(xí)更多知識(shí),歡迎關(guān)注創(chuàng)新互聯(lián)行業(yè)資訊頻道!

網(wǎng)站題目:C++中重載和運(yùn)算符重載加號(hào)實(shí)現(xiàn)矩陣相加的示例分析
本文鏈接:http://bm7419.com/article30/jddcso.html

成都網(wǎng)站建設(shè)公司_創(chuàng)新互聯(lián),為您提供網(wǎng)站設(shè)計(jì)網(wǎng)站建設(shè)、定制網(wǎng)站關(guān)鍵詞優(yōu)化、靜態(tài)網(wǎng)站、標(biāo)簽優(yōu)化

廣告

聲明:本網(wǎng)站發(fā)布的內(nèi)容(圖片、視頻和文字)以用戶投稿、用戶轉(zhuǎn)載內(nèi)容為主,如果涉及侵權(quán)請(qǐng)盡快告知,我們將會(huì)在第一時(shí)間刪除。文章觀點(diǎn)不代表本網(wǎng)站立場(chǎng),如需處理請(qǐng)聯(lián)系客服。電話:028-86922220;郵箱:631063699@qq.com。內(nèi)容未經(jīng)允許不得轉(zhuǎn)載,或轉(zhuǎn)載時(shí)需注明來(lái)源: 創(chuàng)新互聯(lián)

手機(jī)網(wǎng)站建設(shè)