Advertisement
Guest User

KUTAS

a guest
Apr 20th, 2018
76
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.63 KB | None | 0 0
  1. #include <iostream>
  2. #include <string>
  3. #include <cstdio>
  4.  
  5. #pragma warning(disable: 4996)
  6. using namespace std;
  7.  
  8. class Monitor {
  9. private:
  10. string producent;
  11. int gwarancja;
  12. double przekatna;
  13. int pion;
  14. int poziom;
  15. int rok;
  16. string technologia;
  17. int gniazda;
  18. bool glosniki;
  19. double cena;
  20.  
  21. public:
  22. Monitor();
  23. Monitor(string producent, int gwarancja, double przekatna, int pion, int poziom, int rok, string technologia,
  24. int gniazda, bool glosniki, double cena);
  25. void skanujDane();
  26. void drukujDane();
  27. bool dajGlosniki() const;
  28. int dajCene() const;
  29. int dajGniazda() const;
  30. string dajProducenta() const;
  31. };
  32.  
  33. Monitor::Monitor() {
  34. producent = "";
  35. gwarancja = 0;
  36. przekatna= 0;
  37. pion = 0;
  38. poziom = 0;
  39. rok = 0;
  40. technologia = "";
  41. gniazda = 0;
  42. glosniki=0;
  43. cena = 0.0;
  44. }
  45.  
  46. Monitor::Monitor(string producent, int gwarancja, double przekatna, int pion, int poziom, int rok, string technologia,
  47. int gniazda, bool glosniki, double cena) {
  48.  
  49. this->producent = producent;
  50. this->gwarancja = gwarancja;
  51. this->przekatna = przekatna;
  52. this->pion = pion;
  53. this->poziom = poziom;
  54. this->rok = rok;
  55. this->technologia = technologia;
  56. this->gniazda = gniazda;
  57. this->glosniki = glosniki;
  58. this->cena = cena;
  59. }
  60.  
  61. void Monitor::skanujDane() {
  62. Monitor &Monitor = *this;
  63.  
  64. cout << "\tPodaj producenta monitora: "; cin >> Monitor.producent;
  65. cout << "\tPodaj dlugosc gwarancji: "; cin >> Monitor.gwarancja;
  66. cout << "\tPodaj dlugosc przekatnej: "; cin >> Monitor.przekatna;
  67. cout << "\tPodaj ilosc pikseli w pionie: "; cin >> Monitor.pion;
  68. cout << "\tPodaj ilosc pikseli w poziomie: "; cin >> Monitor.poziom;
  69. cout << "\tPodaj rok produkcji monitora: "; cin >> Monitor.rok;
  70. cout << "\tPodaj technologie wyswietlania obrazu: "; cin >> Monitor.technologia;
  71. cout << "\tPodaj liczbe gniazd: "; cin >> Monitor.gniazda;
  72. cout << "\tCzy monitor ma glosniki? (jesli ma - kliknij 1, a jesli nie ma - kliknij 0): "; cin >> Monitor.glosniki;
  73. cout << "\tPodaj cene monitora: "; cin >> Monitor.cena;
  74. cout << endl;
  75. }
  76.  
  77. void Monitor::drukujDane() {
  78. Monitor &monitor = *this;
  79.  
  80. cout << "\tProducent: " << monitor.producent << endl;
  81. cout << "\tGwarancja: " << monitor.gwarancja << endl;
  82. cout << "\tPrzekatna: " << monitor.przekatna << endl;
  83. cout << "\tIlosc pikseli w pionie: " << monitor.pion << endl;
  84. cout << "\tIlosc pikseli w poziomie: " << monitor.poziom << endl;
  85. cout << "\tRok produkcji monitora: " << monitor.rok << endl;
  86. cout << "\tTechnologia wyswietlania obrazu: " << monitor.technologia << endl;
  87. cout << "\tLiczba gniazd: " << monitor.gniazda << endl;
  88. cout << "\tWyposazenie w glosniki: " << monitor.glosniki << endl;
  89. cout << "\tCena: " << monitor.cena << endl;
  90.  
  91. }
  92.  
  93.  
  94.  
  95. int Monitor::dajCene() const {
  96. return this->cena;
  97. };
  98.  
  99. int Monitor::dajGniazda() const {
  100. return this->gniazda;
  101. }
  102.  
  103. bool Monitor::dajGlosniki() const {
  104. return this->glosniki;
  105. }
  106.  
  107. string Monitor::dajProducenta() const {
  108. return this->producent;
  109. }
  110.  
  111. int Porownaj(const Monitor &X, const Monitor &Y);
  112.  
  113. int main()
  114. {
  115.  
  116. cout << "Podaj liczbe monitorow: ";
  117. int liczbaMonitorow;
  118. cin >> liczbaMonitorow;
  119. Monitor *monitor = new Monitor[liczbaMonitorow];
  120.  
  121. for (int i = 0; i != liczbaMonitorow; i++) {
  122. monitor[i].skanujDane();
  123. }
  124.  
  125. for (int i = 0; i != liczbaMonitorow; i++) {
  126. monitor[i].drukujDane();
  127. }
  128.  
  129. for (int i = 0; i != liczbaMonitorow; i++) {
  130.  
  131. for (int j = i + 1; j != liczbaMonitorow; j++) {
  132. if (Porownaj(monitor[i], monitor[j]) == -1) {
  133. monitor[i] = monitor[i];
  134. monitor[j] = monitor[j];
  135. }
  136. else {
  137. Monitor temp = monitor[i];
  138. monitor[i] = monitor[j];
  139. monitor[j] = temp;
  140. }
  141. }
  142. }
  143.  
  144. cout << endl << endl << "POSORTOWANE WEDLUG OPLACALNOSCI: ";
  145. cout << endl << endl;
  146. for (int i = 0; i != liczbaMonitorow; i++) {
  147. cout << "Producent: " << monitor[i].dajProducenta() << endl;
  148. cout << "Cena: " << monitor[i].dajCene() << endl;
  149. cout << "Liczba gniazd: " << monitor[i].dajGniazda() << endl << endl;
  150. }
  151.  
  152. delete[] monitor;
  153.  
  154. }
  155.  
  156. int Porownaj(const Monitor &x, const Monitor &y) {
  157.  
  158. if (x.dajCene() > y.dajCene() && x.dajGniazda() < y.dajGniazda()) {
  159. return 1;
  160. }
  161. else if (x.dajCene() < y.dajCene() && x.dajGniazda() > y.dajGniazda()) {
  162. return -1;
  163. }
  164. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement