jordanov

igroteka

Apr 18th, 2016
299
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.68 KB | None | 0 0
  1. #include <iostream>
  2. #include <cstring>
  3. #include <cstdio>
  4. #include <cmath>
  5. using namespace std;
  6. class igracki{
  7. protected:
  8. char boja[100];
  9. int gustina;
  10. public:
  11. igracki(){
  12. gustina=0;
  13. }
  14. igracki(char b[100],int g){
  15. strcpy(boja,b);
  16. gustina=g;
  17. }
  18. virtual double getMasa()=0;
  19. virtual double getVolumen()=0;
  20. };
  21. class kocka: public igracki{
  22. private:
  23. int visina;
  24. int sirina;
  25. int dlabocina;
  26. public:
  27. kocka():igracki(){
  28. visina=0;
  29. sirina=0;
  30. dlabocina=0;
  31. }
  32. kocka(char b[100],int g,int v,int s,int d):igracki(b,g){
  33. visina=v;
  34. sirina=s;
  35. dlabocina=d;
  36. }
  37. double getMasa(){
  38. return gustina*getVolumen();
  39. }
  40. double getVolumen(){
  41. return visina*sirina*dlabocina;
  42. }
  43. };
  44. class topka:public igracki{
  45. private:
  46. int radius;
  47. public:
  48. topka():igracki(){
  49. radius=0;
  50. }
  51. topka(char b[100],int g ,int r):igracki(b,g){
  52. radius=r;
  53. }
  54. double getMasa(){
  55. return getVolumen()*gustina;
  56. }
  57. double getVolumen(){
  58. return (4*radius*radius*radius*3.14)/3.0;
  59. }
  60. };
  61. int main(){
  62. int n,b,gustina,radius,visina,sirina,dlabocina;
  63. char ime[50];
  64. cin>>n;
  65. igracki **kupche=new igracki*[n];
  66. for(int i=0;i<n;i++)
  67. {
  68. cin>>b;
  69. if(b==1)
  70. {
  71. cin>>ime;
  72. cin>>gustina;
  73. cin>>radius;
  74. //topka t(ime,gustina,radius);
  75. kupche[i]=new topka(ime,gustina,radius);
  76. }
  77. else if(b==2)
  78. {
  79. cin>>ime;
  80. cin>>gustina;
  81. cin>>visina;
  82. cin>>sirina;
  83. cin>>dlabocina;
  84. kupche[i]= new kocka(ime,gustina,visina,sirina,dlabocina);
  85. //kocka k(ime,gustina,visina,sirina,dlabocina);
  86. //kupche[i]=&k;
  87.  
  88. }
  89. }
  90.  
  91. cin>>ime;
  92. cin>>gustina;
  93. cin>>visina;
  94. cin>>sirina;
  95. cin>>dlabocina;
  96. kocka Petra=kocka(ime,gustina,visina,sirina,dlabocina);
  97.  
  98. double vkupnamasa=0;double maxVol=(*kupche[0]).getVolumen();
  99. for(int i=0;i<n;i++)
  100. {
  101. vkupnamasa+=(*kupche[i]).getMasa();
  102. //cout << (*kupche[i]).getMasa();
  103. if(maxVol<(*kupche[i]).getVolumen())
  104. maxVol=(*kupche[i]).getVolumen();
  105. }
  106. if(vkupnamasa>Petra.getMasa())
  107. cout<<"DA"<<endl;
  108. else
  109. cout<<"NE"<<endl;
  110. //cout << maxVol;
  111. //printf("%.2f",maxVol);
  112. cout<<"Razlikata e: "<<abs(maxVol-Petra.getVolumen());
  113. //vnesi informacii za kupche
  114.  
  115.  
  116. //vnesi informacii za igrachkata na Petra
  117.  
  118.  
  119. //baranje 1
  120.  
  121.  
  122. //baranje 2
  123.  
  124. return 0;
  125. }
Add Comment
Please, Sign In to add comment