FILE_MT
#include"conio.h"
#include"iostream.h"
#include"string.h"
#include"iomanip.h"
#include"stdio.h"
class matran
{ private:int a[50][50];
int n;
public:void doc(char *tentep);
void xuat();
void tangcot();
void max();
};
void taofile(char *tentep)
{FILE *f;
int i,j,n,so;
f=fopen(tentep,"wb");
cout<<"
nhap so phan tu cua ma tran n=";
cin>>n;
putw(n,f);
for(i=1;i<=n;i++)
for(j=1;j<=n;j++)
{cout<<"["<<i<<"]["<<j<<"]=";
cin>>so;
putw(so,f);
}
fclose(f);
}
void matran::xuat()
{int i,j;
for(i=1;i<=n;i++)
{cout<<"
";
for(j=1;j<=n;j++)
cout<<setw(5)<<a[i][j];
}
}
void matran::doc(char *tentep)
{FILE *f;
int i,j;
f=fopen(tentep,"rb");
n=getw(f);
for(i=1;i<=n;i++)
for(j=1;j<=n;j++)
a[i][j]=getw(f);
fclose(f);
}
/*void matran::tangcot()
{int i,j,k,tg;
for(j=1;j<=n;j++)
{for(i=1;i<=n;i++)
for(k=i+1;k<=n;k++)
if(a[i][j]>a[k][j])
{tg=a[i][j];
a[i][j]=a[k][j];
a[k][j]=tg;
}
}
}
void matran::max()
{int i,j,max;
max=a[1][1];
for(i=1;i<=n;i++)
for(j=1;j<=n;j++)
{ if(i==j)
{if(max<a[i][j])
max=a[i][j];
}
}
cout<<"
phan tu lon nhat tren duong cheo chinh la "<<max;
} */
void main()
{clrscr();
matran mt;
char *tentep;
cout<<"
nhap ten file: ";
gets(tentep);
taofile(tentep);
mt.doc(tentep);
cout<<"
ma tran vua nhap la";
mt.xuat();
/*cout<<"
ma tran sau khi xep tang theo cot la:";
mt.tangcot();
mt.xuat();
mt.max();*/
getch();
}
Bạn đang đọc truyện trên: AzTruyen.Top