dathuc daoham; // Dao ham cap n dathuc tinhnguyenham; // tinh nguyen ham dathuc nguyenham; // Nguyen ham cap n dathuc tangbac; // tang da thuc len mot bac dathuc giambac; // giam da t
Trang 1UBND TỈNH AN GIANG CỘNG HÒA XÃ HỘI CHỦ NGHĨA VIỆT NAM Trường Đại học An Giang Độc lập – Tự do – Hạnh phúc
ĐỀ TÀI 01: XÂY DỰNG LỚP ĐA THỨC
Trang 2Biên dịch bằng Dev C++
Thành viên trong nhóm 03: gồm 4 thành viên
1 MSSV: DST091282 Lớp: DH10ST Họ và tên: Lê Văn Dủ
2 MSSV: DST091285 Lớp: DH10ST Họ và tên: Huỳnh Thanh Hùng
3 MSSV: DST091291 Lớp: DH10ST Họ và tên: Nguyễn Văn Nhớ
4 MSSV: DST091491 Lớp: DH10ST Họ và tên: Nguyễn Thị huyền Trang (Nhóm trưởng)
dathuc(); // khoi tao mac dinh da thuc = 0
dathuc(int bac1); // Khoi tao tu bac va mang he so cho truoc
dathuc(const dathuc&x); // Khoi tao tu mot doi tuong da thuc khac ~dathuc(); // Ham huy
int laybac(); // Lay bac da thuc
float layheso(int bac); // Lay he so tai bac nao do
dathuc tinhdaoham(int k); // Dao ham cap k
dathuc tinhdaoham(); // Dao ham cap 1
Trang 3dathuc daoham(); // Dao ham cap n
dathuc tinhnguyenham(); // tinh nguyen ham
dathuc nguyenham(); // Nguyen ham cap n
dathuc tangbac(); // tang da thuc len mot bac
dathuc giambac(); // giam da thuc xuong mot bac
bool sosanh(const dathuc &p); // So sanh voi da thuc khac
float tinhgiatri(float fx); // tinh gia tri
friend dathuc operator+(dathuc a,dathuc b); // Cong
friend dathuc operator-(dathuc a,dathuc b); // Tru
friend dathuc operator*(dathuc a,dathuc b); // Nhan
friend dathuc operator/(dathuc a,dathuc b); // Chia lay phan nguyen
friend dathuc operator+=(dathuc a,dathuc b); // Cong
friend dathuc operator-=(dathuc a,dathuc b); // Tru
friend dathuc operator*=(dathuc a,dathuc b); // Nhan
friend dathuc operator/=(dathuc a,dathuc b); // Chia
bool operator>(dathuc); // Toan tu >
bool operator<(dathuc); // Toan tu <
bool operator>=(dathuc); // Toan tu >=
bool operator<=(dathuc); // Toan tu <=
bool operator==(dathuc); // Toan tu ==
bool operator!=(dathuc); // Toan tu !=
float operator[](int bac); // Toan tu mang, lay he so tai bac nao do
friend istream& operator>>(istream&, dathuc &d); // Toan tu nhap
friend ostream& operator<<(ostream&, dathuc &d); // Toan tu xuat
};
istream &operator>>(istream &is, dathuc &d)
{
cout<<"\n Bac da thuc n= "; cin>>d.bac;
d.heso = new float[d.bac+1];
cout<<" Nhap cac he so cua da thuc: "<<endl;
for(int i=d.bac;i>=0;i )
{
cout<<" a["<<i<<"]= "; is>>d.heso[i];
}
Trang 5for (int i=bac;i>=0;i )
if(i==bac) return heso[i];
if(tong1>=tong2) return true;
else return false;
Trang 11dathuc operator*=(dathuc a,dathuc b) // Toan tu gan *=
for (int i=bac;i>=0;i )
if(i==bac) return heso[i];
Trang 12{
tong2=tong2+(p.heso[i])*(pow(x,i));
}
if(tong1>tong2) return true;
else return false;
if(tong1<tong2) return true;
else return false;
Trang 13if(tong1>=tong2) return true;
else return false;
if(tong1<=tong2) return true;
else return false;
Trang 14if(tong1==tong2) return true;
else return false;
if(tong1!=tong2) return true;
else return false;
Trang 16cout<<"\nTinh nguyen ham cap: ";
Trang 17cout<<"\n\t\t\t==========Thanh vien nhom==========";
cout<<"\n\t\t\t= 1 Le Van Du =";
cout<<"\n\t\t\t= 2 Nguyen Van Nho =";
cout<<"\n\t\t\t= 3 Huynh Thanh Hung =";
cout<<"\n\t\t\t= 4 Nguyen Thi Huyen Trang =";
cout<<"\n\t\t\t= De tai 01: Xay dung lop da thuc =";
cout<<"\t== 2 Nhap da thuc A va B: Toan tu >> =="<<endl;
cout<<"\t== 3 In da thuc da thuc A va B: Toan tu << =="<<endl;
cout<<"\t== 4 Dao ham da thuc =="<<endl;
cout<<"\t== 5 Nguyen ham da thuc =="<<endl;
cout<<"\t== 6 Tang bac da thuc =="<<endl;
cout<<"\t== 7 Giam bac da thuc =="<<endl;
cout<<"\t== 8 Lay bac Da thuc =="<<endl;
cout<<"\t== 9 Lay he so da thuc =="<<endl;
cout<<"\t== 10 So sanh 2 da thuc =="<<endl;
cout<<"\t== 11 Tinh gia tri da thuc =="<<endl;
cout<<"\t== 12 Cac toan tu so hoc =="<<endl;
cout<<"\t== 13 Cac toan tu gan =="<<endl;
cout<<"\t== 14 Cac toan tu so sanh =="<<endl;
cout<<"\t== 15 Toan tu [] lay he so tai bac nao do =="<<endl;
cout<<"\t== 0 Thoat =="<<endl;
char chon1;
float layheso,x,gt,layheso1;
Trang 19cout<<" Da thuc vua nhap: "<<g<<endl;
cout<<" Da thuc giam mot bac: "<<g1<<endl;
case 9: cout<<" Da thuc F";cin>>f;
cout<<"\n Da thuc E he so cua bac thu: ";
case 10: cout<<"\tDa thuc A1";cin>>a1; cout<<"\n\tDa thuc A2";cin>>a2;
cout<<" So sanh 2 da thuc A1 va A2 ";
ss=a1.sosanh(a2);
if(ss==true) cout<<"\n Da thuc A1>=A2";
else cout<<"\n Da thuc A1<A2";
getch();
break;
case 11:
cout<<" Da thuc A3: "; cin>>a3;
cout<<"\n Gia tri tai X= ";
case 12: cout<<"\t Nhap 2 da thuc moi!";
cout<<"\n Da thuc B1";cin>>b1;
cout<<"\n Da thuc B2";cin>>b2;
do
Trang 20{
cout<<"\n\t\t Ban go chu thuong nhe!"<<endl;
cout<<"\t\t== Menu cac toan tu =="<<endl;
cout<<"\t\t== a Toan tu + =="<<endl;
cout<<"\t\t== b Toan tu - =="<<endl;
cout<<"\t\t== c Toan tu * =="<<endl;
cout<<"\t\t== d Toan tu / =="<<endl;
cout<<"\t\t== e Thoat =="<<endl;
cout<<"\t Lua chon 1 chuc nang trong Menu: ";
cin>>chon1;
switch(chon1)
{
case 'a':
d=b1+b2; cout<<" Da thuc A: "<<b1;cout<<"\n Da thuc B: "<<b2;
cout<<"\n Da thuc A+B: "<<d; getch();
break;
case 'b':
d1=b1-b2; cout<<" Da thuc A: "<<b1;cout<<"\n Da thuc B: "<<b2;
cout<<"\n Da thuc A-B: "<<d1; getch();
break;
case 'c':
d2=b1*b2; cout<<" Da thuc A: "<<b1;cout<<"\n Da thuc B: "<<b2;
cout<<"\n Da thuc A*B: "<<d2; getch();
case 13: cout<<"\t Nhap 2 da thuc moi!";
cout<<"\n Da thuc A";cin>>a;
cout<<"\n Da thuc B";cin>>b;
do
{
Trang 21cout<<"\n\t\t Ban go chu thuong nhe!"<<endl;
cout<<"\t\t== Menu cac toan tu gan =="<<endl;
cout<<"\t\t== a Toan tu += =="<<endl;
cout<<"\t\t== b Toan tu -= =="<<endl;
cout<<"\t\t== c Toan tu *= =="<<endl;
cout<<"\t\t== d Toan tu /= =="<<endl;
cout<<"\t\t== e Thoat =="<<endl;
cout<<"\t Lua chon 1 chuc nang trong Menu: ";
cin>>chon1;
switch(chon1)
{
case 'a':
l=a+=b; cout<<" Da thuc A: "<<a;cout<<"\n Da thuc B: "<<b;
cout<<"\n Da thuc A+=B: "<<l; getch();
break;
case 'b':
l1=a-=b; cout<<" Da thuc A: "<<a;cout<<"\n Da thuc B: "<<b;
cout<<"\n Da thuc A-=B: "<<l1; getch();
break;
case 'c':
l2=a*=b; cout<<" Da thuc A: "<<a;cout<<"\n Da thuc B: "<<b;
cout<<"\n Da thuc A*=B: "<<l2; getch();
case 14: cout<<"\t Nhap 2 da thuc moi!";
cout<<"\n Da thuc C2";cin>>c2;
cout<<"\n Da thuc C3";cin>>c3;
do
{
cout<<"\n\t\t Ban go chu thuong nhe!"<<endl;
Trang 22cout<<"\t\t== Menu cac toan tu gan =="<<endl;
cout<<"\t\t== a Toan tu so sanh > =="<<endl;
cout<<"\t\t== b Toan tu so sanh < =="<<endl;
cout<<"\t\t== c Toan tu so sanh == =="<<endl;
cout<<"\t\t== d Toan tu so sanh >= =="<<endl;
cout<<"\t\t== f Toan tu so sanh <= =="<<endl;
cout<<"\t\t== g Toan tu so sanh != =="<<endl;
cout<<"\t\t== e Thoat =="<<endl;
cout<<"\t Lua chon 1 chuc nang trong Menu: ";
if(s1==true) cout<<" Da thuc C2>C3";
else cout<<" Da thuc C2<=C3";
if(s1==true) cout<<" Da thuc C2<C3";
else cout<<" Da thuc C2>=C3";
if(s1==true) cout<<" Da thuc C2==C3";
else cout<<" Da thuc C2!=C3";
if(s1==true) cout<<" Da thuc C2>=C3";
else cout<<"\n Da thuc C2<C3";
getch();
break;
case 'f':
Trang 23cout<<" So sanh 2 Da thuc C2 va C3";
s1=c2<=c3;
if(s1==true) cout<<" Da thuc C2<=C3";
else cout<<" Da thuc C2>C3";
if(s1==true) cout<<" Da thuc C2!=C3";
else cout<<" Da thuc C2==C3";