Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include<iostream>
- #include<cmath>
- using namespace std;
- class dathuc{
- public:
- int bac;
- int *heso;
- dathuc(){
- cout<< "nhap bac da thuc: ";
- cin>> this->bac;
- heso = (int *) malloc(sizeof(int)* (this->bac + 1));
- for (int i=bac; i>=0; i--){
- cout<< "nhap he so bac "<<i << ": ";
- cin>> heso[i];
- }
- cout<< "da thuc vua nhap la: "<<"\n";
- for (int i=bac; i>=1; i--){
- cout<<heso[i]<<"X^"<<i << "+";
- }
- cout<<heso[0]<<" = 0"<< "\n";
- }
- ~dathuc(){
- free(heso);
- }
- int giatri(){
- int x;
- int giatri=0;
- cout<< "nhap X: ";
- cin>> x;
- for (int i=bac; i>=0; i--){
- giatri += heso[i]*pow(x,bac);
- }
- return giatri;
- }
- };
- int main(int argc, char const *argv[])
- {
- dathuc dt;
- cout<< dt.giatri();
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement