Guest User

Untitled

a guest
Jul 21st, 2018
81
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.55 KB | None | 0 0
  1. # include <iostream>
  2. # include <string.h>
  3. # include <stdlib.h>
  4. # include <stdio.h>
  5. using namespace std;
  6.  
  7. class FORTA {
  8. double masa;
  9. double acceleratia;
  10. public:
  11. FORTA (): masa(0),acceleratia(0){};
  12. FORTA (double, double); // Primul constructor
  13. FORTA (FORTA &); // Al doilea constructor
  14.  
  15. ~FORTA() { cout << "Trec prin destructor" << endl; }
  16.  
  17. double get_masa()
  18. {
  19. return masa;
  20. }
  21.  
  22. double get_acc()
  23. {
  24. return acceleratia;
  25. }
  26.  
  27. void operator=(const FORTA &g)
  28. {
  29. masa=g.masa;
  30. acceleratia=g.acceleratia;
  31. }
  32.  
  33. FORTA operator+(const FORTA &g)
  34. {
  35. FORTA h(masa + g.masa, acceleratia + g.acceleratia);
  36. return h;
  37. }
  38.  
  39. };
  40.  
  41. FORTA :: FORTA (double mm, double aa)
  42. {
  43. masa = mm;
  44. acceleratia = aa;
  45. cout << "Trec prin constructorul FORTA (double, double)" << endl;
  46. }
  47.  
  48. FORTA :: FORTA (FORTA &g) // Constructor inþializator de forma C(C &)
  49. {
  50. masa = g.masa;
  51. acceleratia = g.acceleratia;
  52. cout << "Trec prin constructorul FORTA (FORTA &)" << endl;
  53. }
  54.  
  55. void idle (FORTA f)
  56. {
  57. cout << "Sunt in functia idle()" << endl;
  58. }
  59. // Programul apelant
  60.  
  61. int main ()
  62. {
  63. FORTA f1(10., 9.8);
  64. cout<<f1.get_masa()<<endl;
  65. cout<<f1.get_acc()<<endl;
  66. FORTA f2;
  67. f2 = f1;
  68. cout<<f2.get_masa()<<endl;
  69. cout<<f2.get_acc()<<endl;
  70. FORTA f3;
  71. f3=f1+f2;
  72. cout<<f3.get_masa()<<" "<<f3.get_acc()<<endl;
  73. idle(f2);
  74. // system("pause");
  75. return 0;
  76. }
Add Comment
Please, Sign In to add comment