fork(1) download
  1. #include <iostream>
  2. #include <cstdlib>
  3. #include <numeric>
  4.  
  5. using namespace std;
  6.  
  7. class Bullet{
  8. public:
  9. virtual float damagePerShot()=0;
  10. virtual void animationOfShot()=0;
  11. virtual ~Bullet(){}
  12. };
  13.  
  14. class Explosive: public Bullet{
  15. protected:
  16. void animationOfShot()
  17. {
  18. cout<<"BooM !!!\n";
  19. }
  20. float damagePerShot()
  21. {
  22. return 7.4;
  23. }
  24. public:
  25. virtual ~Explosive(){}
  26. };
  27.  
  28.  
  29.  
  30. class Magazine{
  31. Bullet *bullets[30];
  32. int newBullet,bulletType;
  33. float damageOfShot;
  34. public:
  35. Magazine()
  36. {
  37. ...
  38. damageOfShot=0.0;
  39. }
  40. void addBulletsToMagazine()
  41. {
  42. ...
  43. }
  44. float damageOfShots()
  45. {
  46. damageOfShot=0.0;
  47. for(int i=0;i<newBullet;i++)
  48. {
  49. damageOfShot+=bullets[i]->damagePerShot();
  50. }
  51. return damageOfShot;
  52. }
  53. };
  54.  
  55. class Gun{
  56. Magazine *full_magazine;
  57. int howBullets,typeBullets;
  58. float totalDamageOfMagazine;
  59. public:
  60. Gun(int bulletsHowMuch)
  61. {
  62. ...
  63. howBullets=bulletsHowMuch;
  64. full_magazine=new Magazine;
  65. totalDamageOfMagazine=0.0;
  66. }
  67. void createGun()
  68. {
  69. for(int i=0;i<howBullets;i++)
  70. {
  71. (*full_magazine).addBulletsToMagazine();
  72. }
  73. }
  74. float totalDamageOfGun()
  75. {
  76. return (*full_magazine).damageOfShots();
  77. }
  78. };
  79.  
  80. ostream& operator<<(ostream &totalDamageOfGun,Gun &gun)
  81. {
  82. totalDamageOfGun<<gun.totalDamageOfGun();
  83. return totalDamageOfGun;
  84. }
  85.  
  86. int main()
  87. {
  88. int ile_naboi;
  89. cout<<"Ile chcesz wystrzelic naboi?\n";
  90. cin>>ile_naboi;
  91. Gun M4(ile_naboi);
  92. M4.createGun();
  93. cout<<"\nSuma zadanych obrazen: "<<M4;
  94. Gun M3=M4;
  95. cout<<"\nSuma zadanych obrazen: "<<M3;
  96. }
  97.  
Compilation error #stdin compilation error #stdout 0s 0KB
stdin
Standard input is empty
compilation info
prog.cpp: In constructor ‘Magazine::Magazine()’:
prog.cpp:37:9: error: expected primary-expression before ‘...’ token
         ...
         ^
prog.cpp:37:9: error: expected ‘;’ before ‘...’ token
prog.cpp: In member function ‘void Magazine::addBulletsToMagazine()’:
prog.cpp:42:6: error: expected primary-expression before ‘...’ token
      ...
      ^
prog.cpp:42:6: error: expected ‘;’ before ‘...’ token
prog.cpp: In constructor ‘Gun::Gun(int)’:
prog.cpp:62:9: error: expected primary-expression before ‘...’ token
         ...
         ^
prog.cpp:62:9: error: expected ‘;’ before ‘...’ token
stdout
Standard output is empty