Daysomaxmin
/* Xay dung lop Dayso(Day so thuc)
Thuoc tinh
float a[50];//khoang chua cac pt day so: a[1],..,a[n]
int n; //Bien nguyen n chua so pt cua day
Phuong thuc :nhap , xuat,tinh gia tri lon nhat va gia tri nho nhat cua day so
sap xep day so theo chieu giam
Ham main: nhap 1 day so,tim gia tri max,gia tri min cua day */
#include<conio.h>
#include<stdio.h>
#include<iostream.h>
class dayso
{
int n;
float a[50];
public:
void nhap();
void xuat();
void max_min(float&max,float&min);
void sap_xep();
};
void dayso::nhap()
{
cout<<"
so pt N=";
cin>>n;
for(int i=1;i<=n;++i)
{
cout<<"
pt"<<i<<"=";
cin>>a[i];
}
}
void dayso::xuat()
{
for(int i=1;i<=n;++i)
{
cout<<"
pt"<<i<<"="<<a[i];
}
}
void dayso::max_min(float&max,float&min)
{
max=min=a[1];
for(int i=2;i<=n;++i)
{
if(a[i]>max) max=a[i];
if(a[i]<min) min=a[i];
}
}
void dayso::sap_xep()
{
int i,j;
float tg;
for(i=1;i<=n;++i)
for(j=i+1;j<=n;++j)
{
if(a[i]<a[j])
{
tg=a[i];
a[i]=a[j];
a[j]=tg;
}
}
}
void main()
{ clrscr();
dayso u;
float gtmax,gtmin;
u.nhap();
u.max_min(gtmax,gtmin);
cout<<"
gtmax="<<gtmax<<"
gtmin="<<gtmin;
u.sap_xep();
cout<<"
day so theo chieu giam";
u.xuat();
getch();
}
Bạn đang đọc truyện trên: AzTruyen.Top