Article View: cn.bbs.comp.program
Article #38Re: BC������
From: ��Ҫȥ��
Date: Thu, 11 Nov 1999 00:00
Date: Thu, 11 Nov 1999 00:00
81 lines
3909 bytes
3909 bytes
> [1;36m==> Astute_Firefly(n) ˵��: [37;40m[0m
> ���˳�ѧ��������̣���BCдһ����ѧ������࣬���������������⣬
> ����ָ�̡�
> 1 �Ծ���������в�����һ��Ԫ�ؾ�������0�����ֻ�ö������ڴ�ռ�
> (�ڳ����б���Ϊÿ���±��Ҫ��1��ʵ��̫��Ť�ˡ�)
> 2 �˷���������غ��ڸú����ж������м�������temp��
> ���в��� m3=m1*m2 ʱ��temp ��ָ��ָ��m2����˽��m3����
> ͬʱm2�е����Ҳ���ġ�
> �����Ǹ������ݽ���ֺ������λ�������æ���ڴ�����л��
> -------------------------------------------------
> #include <iostream.h>
> #include <fstream.h>
> #include <math.h>
> class Cmatrix {
> private:
> long int row,col;
> double *buffer;
> public:
> Cmatrix(){row=0;col=0;buffer=NULL;};
may be should use delete(buffer);
> ~Cmatrix(){if (buffer!=NULL){row=0;col=0;delete[] buffer;buffer=NULL;}}
> void LoadFromFile(char *);
> void operator=(const Cmatrix &);
> void disp();
> double & operator[](long int);
> Cmatrix turn();
> friend Cmatrix operator+(const Cmatrix&,const Cmatrix&);
> friend Cmatrix operator+(const Cmatrix&,double);
> friend Cmatrix operator+(double ,const Cmatrix&);
> void operator+=(double);
> void operator+=(const Cmatrix &);
> friend Cmatrix operator-(const Cmatrix&,const Cmatrix&);
> friend Cmatrix operator-(const Cmatrix&,double);
> friend Cmatrix operator-(double ,const Cmatrix&);
> void operator-=(double);
> void operator-=(const Cmatrix &);
> Cmatrix operator-();
> friend Cmatrix operator*(const Cmatrix &, const Cmatrix &);
> friend Cmatrix operator*(const Cmatrix&, double);
> friend Cmatrix operator*(double, const Cmatrix &);
> void operator*=(double);
> };
> void Cmatrix::LoadFromFile(char *str)
> {
> ifstream myfile(str);
> myfile>>row>>col;
> if (row<0||row>20000||col<0||col>20000)
> {
> row=0;col=0;
> myfile.close();
> }
> else
> {
> if (buffer) {delete[] buffer;buffer=NULL;}
> buffer=new double [row*col+1];
> for (long int i=0;i<row;i++)
> for (long int j=0;j<col;j++)
> myfile>>buffer[i*col+j+1];
> }
> myfile.close();
> }
> void Cmatrix::operator=(const Cmatrix & m)
> {
> if (buffer) {delete[] buffer; buffer=NULL;}
> buffer=new double[m.row*m.col+1];
> row=m.row;
> col=m.col;
> for (long int i=0;i<row;i++)
> for (long int j=0;j<col;j++)
> buffer[i*col+j+1]=m.buffer[i*col+j+1];
> return;
> }
> void Cmatrix::disp()
> {
> cout<<row<<" "<<col<<endl;
> for (long int i=0;i<row;i++)
> {
--
�� ��Դ: �й�ƴ�BBSվ [bbs.ustc.edu.cn]
Technical Details
Message-ID:
<991111.11libU$PBBS@bbs.ustc.edu.cn>Path:
arc1-ca.pugleaf.net!unknown!not-for-mailShow Full Headers
Complete Article Headers
X-Google-Language: Chinese,GB X-Google-Thread: fc86e,2b02d5f91cc00604,start X-Google-Attributes: gidfc86e,public From: Bird_Bless@bbs.ustc.edu.cn (��Ҫȥ��) Subject: Re: BC������ Date: 1999/11/11 Message-ID: <991111.11libU$PBBS@bbs.ustc.edu.cn> X-Deja-AN: 547136924 Organization: �й�ƴ�BBSվ Newsgroups: cn.bbs.comp.program