welcome tinhocK1 website

Sunday, 09/08/2020, 12:15 PM

Chào Guest

Login form

Đăng nhập:
mật khẩu:

Ẩn

Tán Gẫu

500

Bạn thấy web tinhoc K1 thế nào?

Rate my site
Total of answers: 108
[ New messages · Members · Forum rules · Search · RSS ]
  • Page 1 of 1
  • 1
Forum » download » tài liệu chuyên ngành » phan so
phan so
quocdat11 Date: Thursday, 06/11/2008, 8:46 AM | Message # 1
Nhóm: Removed





#include
#include
#include
class Phanso{
int tu, mau;
int ucln(int,int);
void rutgon();
public:
Phanso() {tu=0; mau=1;};
Phanso(int,int);
Phanso(const Phanso& );
void nhap();
void xuat();
void gan(int,int);
Phanso nghichdao();
float trithuc();

Phanso cong(Phanso);
Phanso tru(Phanso);
Phanso nhan(Phanso);
Phanso chia(Phanso);

Phanso cong(int);
Phanso tru(int);
Phanso nhan(int);
Phanso chia(int);
};

int Phanso::ucln(int a,int b){
if(a==0 || b==0) return 0;
a=abs(a);
b=abs(b);
while(a!=b)
(a>b)? (a-=b) : (b-=a);
return a;
}

void Phanso::rutgon (){
int t=ucln(tu,mau);
tu/=t;
mau/=t;
}
Phanso::Phanso(int t, int m){
tu=t;
mau=m;
}
Phanso::Phanso(const Phanso& ps){
tu=ps.tu;
mau=ps.mau;
}
void Phanso::nhap(){
cout<<"Tu so: ";cin>>tu;
cout<<"Mau so: ";cin>>mau;
}
void Phanso::xuat(){
cout< }
Phanso Phanso::nghichdao(){
Phanso kq;
kq.tu=mau;
kq.mau=tu;
return kq;
}
float Phanso::trithuc(){
return (float)tu/mau;
}
Phanso Phanso::cong (Phanso ps){
Phanso kq;
kq.tu=tu*ps.mau*ps.tu;
kq.mau=mau*ps.mau;
kq.rutgon();
return kq;
}
Phanso Phanso::tru (Phanso ps){
Phanso kq;
kq.tu=tu*ps.mau-mau*ps.tu;
kq.mau=mau*ps.mau;
kq.rutgon();
return kq;
}
void Phanso::gan(int t,int m){
tu=t;
mau=m;
}
Phanso Phanso::nhan(Phanso ps){
Phanso kq;
kq.tu=tu*ps.tu;
kq.mau=mau*ps.mau;
kq.rutgon();
return kq;
}
Phanso Phanso::chia(Phanso ps){
Phanso kq;
kq=this->nghichdao();
kq=ps.nhan(kq);
return kq;
}
Phanso Phanso::cong(int a){
Phanso kq(a,1);
kq=kq.cong(*this);
return kq;
}
Phanso Phanso::tru(int a){
Phanso kq(a,1);
kq=kq.tru(*this);
return kq;
}
Phanso Phanso::nhan(int a){
Phanso kq(a*tu,mau);
return kq;
}
Phanso Phanso::chia(int a){
Phanso kq(tu,mau*a);
return kq;
}

void main(){
Phanso a(3,7),b(4,9);
clrscr();
cout<<"a= ";a.xuat();
cout<<"\nb= ";b.xuat();
cout< //tao 2 phan so x,y
Phanso x,y;
cout<<"Nhap x:\n";
x.nhap();
cout<<"Nhap y:\n";
y.nhap();
cout< cout<<"x= ";x.xuat();
cout<<"y= ";y.xuat();
cout< cout<<"Nghich dao cua x= ";
x.nghichdao().xuat();
cout< //tinh tong cua x,y va in ra man hinh
Phanso tong;
tong=x.cong(y);
cout<<"x + y = ";
tong.xuat();
cout< //tich x va 10;
Phanso tichx10;
tichx10 = x.nhan(10);
cout<<"Tich cua x va 10 la: ";
tichx10.xuat();
cout< //nhap danh sach n phan so
int n;
Phanso *ds;
cout<<"Nhap vao so phan tu cua danh sach: ";
cin>>n;
ds=new Phanso[n];
for (int i=0;i cout<<"Nhap phan tu thu "< ds[i].nhap();
}
//tinh tong n phan so trong ds
Phanso tongn;
for (i=0;i tongn=tongn.cong(ds[i]);
cout< cout<<"Tong n phan so: ";
tongn.xuat();
delete []ds;
getch();

}

 
Forum » download » tài liệu chuyên ngành » phan so
  • Page 1 of 1
  • 1
Search: