Advertisement
Guest User

Untitled

a guest
Mar 29th, 2020
198
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.97 KB | None | 0 0
  1. #include <string>
  2. #include <iostream>
  3.  
  4. using namespace std;
  5.  
  6. class Silnik{
  7. private:
  8. string producent;
  9. int pojemnosc;
  10.  
  11. public:
  12.  
  13. Silnik (string a, int b){
  14. producent = a;
  15. pojemnosc = b;
  16. };
  17.  
  18. string producent_show(){
  19. return producent;
  20. }
  21.  
  22. int pojemnosc_show(){
  23. return pojemnosc;
  24. }
  25. };
  26.  
  27. class Device{
  28. private:
  29. const string producent;
  30. int obroty;
  31. Silnik silnik;
  32.  
  33. public:
  34.  
  35. Device (string producent, int c, string silnik_producent, int silnik_pojemnosc)
  36. :producent(producent), silnik(silnik_producent, silnik_pojemnosc)
  37. {
  38. obroty = c;
  39. };
  40.  
  41. string producent_show() {
  42. return producent;
  43. }
  44.  
  45. int obroty_show(){
  46. return obroty;
  47. }
  48.  
  49. string silnik_producent_show(){
  50. return silnik.producent_show();
  51. }
  52.  
  53. int silnik_pojemnosc_show(){
  54. return silnik.pojemnosc_show();
  55. }
  56.  
  57. void Showtime(){
  58. cout<<"Urzadzenie:\n";
  59. cout<<"Producent urzadzenia: "<<producent_show()<<"\n";
  60. cout<<"Obroty urzadzenia: "<<obroty_show()<<"\n";
  61. cout<<"Producent silnika: "<<silnik_producent_show()<<"\n";
  62. cout<<"Pojemnosc silnika: "<<silnik_pojemnosc_show()<<"\n";
  63. }
  64.  
  65. };
  66.  
  67. Device* szukaj(Device tab, int z)
  68. {
  69. int x = 0;
  70. Device* a[z];
  71.  
  72. for ( int i = 0; i < 6; i++) {
  73. if(tab[i].producent_show() == tab[i].silnik_producent_show()){
  74. a[x] = tab[i];
  75. x++;
  76. }
  77. }
  78. return a;
  79. }
  80.  
  81. int zlicz(Device tab[])
  82. {
  83. int zlicz = 0;
  84. for ( int i = 0; i < 6; i++) {
  85. if(tab[i].producent_show() == tab[i].silnik_producent_show()){
  86. {
  87. zlicz++;
  88. }
  89. }
  90. return zlicz;
  91. };
  92. int main (){
  93. Device y[6] = {
  94. Device ("BMW", 8000, "BMW", 6),
  95. Device ("HONDA", 3000, "HONDA", 2),
  96. Device ("BMW", 6000, "HONDA", 4),
  97. Device ("MERCEDES", 7000, "BMW", 5),
  98. Device ("FORD", 5000, "FORD", 3),
  99. Device ("AUDI", 4000, "AUDI", 2),
  100. };
  101. int zlicz1=zlicz(y);
  102.  
  103. Device *a=szukaj(y,zlicz1);
  104. for (int i = 0; i < zlicz1; i++)
  105. {
  106. a[i].wypisz();
  107. }
  108. return 0;
  109. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement