#include<conio.h>
#include<stdio.h>
class ts
{
private:
float *a;
int n;
public:
ts();
~ts();
void nhap();
void xuat();
ts operator=(ts &);
float tb();
float max();
friend int soso(ts &a,ts &b); };
ts::ts()
{
n=0;a=NULL;
};
ts::~ts()
{
n=0;delete a;
};
void ts::nhap()
{
Trang 2cout<<"\n nhap so cac so ";
cin>>n;
a=new float[n];
for(int i=0;i<n;i++)
{
cout<<"\n nhap so thu "<<i+1<<" : "; cin>>a[i];
};
};
void ts::xuat()
{
for(int i=0;i<n;i++)
{
cout<<"\n so thu "<<i+1<<" la : "<<a[i]; };
};
ts ts::operator=(ts&c)
{
n=c.n;
a=new float[n];
for(int i=0;i<n;i++)
a[i]=c.a[i];
return c;
};
float ts::tb()
{
float temp;
temp=0;
Trang 3for(int i=0;i<n;i++) temp=temp+a[i];
temp=temp/n;
return temp;
};
float ts::max()
{
float temp;
temp=a[0];
for(int i=1;i<n;i++) if(temp<a[i])temp=a[i]; return temp;
};
int soso(ts &a,ts &b)
{
int ss,i,j,k;
ss=0;
ts t;
t=a;
for(i=0;i<t.n;i++) t.a[i]=0;
for(i=0;i<a.n;i++) for(j=0;j<b.n;j++) if(t.a[i]==0)
{
if(a.a[i]==b.a[j]) {
ss=ss+1;
Trang 4for(k=0;k<a.n;k++) if(a.a[k]==a.a[i])t.a[k]=1;
};
};
return ss;
};
int main()
{
ts a,b,c;
cout<<"\n nhap cac phan tu cua tap a : ";
a.nhap();
cout<<"\n nhap cac phan tu cua tap b : ";
b.nhap();
cout<<"\n so trung binh cua tap a la "<<a.tb();
cout<<"\n so lon nhat cua tap a la "<<a.max();
cout<<"\n so cac so trung giua tap a va tap b la "<<soso(a,b); c=b;
cout<<"\n tap c la ";
c.xuat();
getch();
};