Advertisement
Guest User

Untitled

a guest
Jul 17th, 2018
64
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.38 KB | None | 0 0
  1. #include<iostream>
  2. #include<fstream>
  3. using namespace std;
  4. class Dathuc{
  5. private:
  6. float Heso[100];
  7. int n;
  8. public:
  9. void nhap(){
  10. cin>>n;
  11. for(int i=n;i>=0;i--){
  12. cin>>Heso[i];
  13. }
  14. }
  15. void hienthi(){
  16. for(int i=n;i>=0;i--){
  17. if(i==0){
  18. cout<<Heso[i];
  19. }
  20. else{
  21. cout<<Heso[i]<<"*x^"<<i<<"+";
  22. }
  23. }
  24. }
  25. void docFile(){
  26. ifstream f;
  27. f.open("Dathuc.in");
  28. f>>n;
  29. for(int i=n;i>=0;i--){
  30. f>>Heso[i];
  31. }
  32. for(int i=n;i>=0;i--){
  33. if(i==0){
  34. cout<<Heso[i];
  35. }
  36. else{
  37. cout<<Heso[i]<<"*x^"<<i<<"+";
  38. }
  39. }
  40. f.close();
  41. }
  42. void ghiFile(){
  43. ofstream f;
  44. f.open("Dathuc.out");
  45. f<<n<<endl;
  46. for(int i=n;i>=0;i--){
  47. if(i==0){
  48. f<<Heso[i];
  49. }
  50. else{
  51. f<<Heso[i]<<"*x^"<<i<<"+";
  52. }
  53. }
  54. f.close();
  55. }
  56. Dathuc Tongdathuc(Dathuc a,Dathuc b){
  57. if(a.n>=b.n){
  58. Tongdathuc.n=a.n;
  59. }
  60. else{
  61. Tongdathuc.n=b.n;
  62. }
  63. for(int i=Tongdathuc.n;i>=0;i--){
  64. if(i<=a.n&&i<=b.n){
  65. Tongdathuc.Heso[i]=a.Heso[i]+b.Heso[i];
  66. }
  67. else if(i<=a.n&&i>b.n){
  68. Tongdathuc.Heso[i]=a.Heso[i];
  69. }
  70. else if(i<=b.n&&i>a.n){
  71. Tongdathuc.Heso[i]=b.Heso[i];
  72. }
  73. }
  74. return Tongdathuc.Heso;
  75. }
  76. };
  77. int main(){
  78. Dathuc a,b;
  79. a.nhap();
  80. a.hienthi();
  81. b.nhap();
  82. b.hienthi();
  83. Dathuc c=a.Tongdathuc(a,b);
  84. c.hienthi();
  85. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement