Thread View: cn.bbs.comp.program
1 messages
1 total messages
Started by ��Ҫȥ��
Thu, 11 Nov 1999 00:00
Re: BC������
Author: ��Ҫȥ��
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]
Thread Navigation
This is a paginated view of messages in the thread with full content displayed inline.
Messages are displayed in chronological order, with the original post highlighted in green.
Use pagination controls to navigate through all messages in large threads.
Back to All Threads