Advertisement
anhlocpr

Untitled

Apr 9th, 2017
74
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.92 KB | None | 0 0
  1. #include<iostream>
  2. #include<cmath>
  3.  
  4. using namespace std;
  5. class dathuc{
  6. public:
  7. int bac;
  8. int *heso;
  9.  
  10. dathuc(){
  11. cout<< "nhap bac da thuc: ";
  12. cin>> this->bac;
  13. heso = (int *) malloc(sizeof(int)* (this->bac + 1));
  14. for (int i=bac; i>=0; i--){
  15. cout<< "nhap he so bac "<<i << ": ";
  16. cin>> heso[i];
  17. }
  18. cout<< "da thuc vua nhap la: "<<"\n";
  19. for (int i=bac; i>=1; i--){
  20. cout<<heso[i]<<"X^"<<i << "+";
  21. }
  22. cout<<heso[0]<<" = 0"<< "\n";
  23. }
  24.  
  25. ~dathuc(){
  26. free(heso);
  27. }
  28.  
  29. int giatri(){
  30. int x;
  31. int giatri=0;
  32. cout<< "nhap X: ";
  33. cin>> x;
  34. for (int i=bac; i>=0; i--){
  35. giatri += heso[i]*pow(x,bac);
  36. }
  37. return giatri;
  38. }
  39. };
  40. int main(int argc, char const *argv[])
  41. {
  42. dathuc dt;
  43. cout<< dt.giatri();
  44. return 0;
  45. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement