Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <string>
- #include <cstdio>
- #pragma warning(disable: 4996)
- using namespace std;
- class Monitor {
- private:
- string producent;
- int gwarancja;
- double przekatna;
- int pion;
- int poziom;
- int rok;
- string technologia;
- int gniazda;
- bool glosniki;
- double cena;
- public:
- Monitor();
- Monitor(string producent, int gwarancja, double przekatna, int pion, int poziom, int rok, string technologia,
- int gniazda, bool glosniki, double cena);
- void skanujDane();
- void drukujDane();
- bool dajGlosniki() const;
- int dajCene() const;
- int dajGniazda() const;
- string dajProducenta() const;
- };
- Monitor::Monitor() {
- producent = "";
- gwarancja = 0;
- przekatna= 0;
- pion = 0;
- poziom = 0;
- rok = 0;
- technologia = "";
- gniazda = 0;
- glosniki=0;
- cena = 0.0;
- }
- Monitor::Monitor(string producent, int gwarancja, double przekatna, int pion, int poziom, int rok, string technologia,
- int gniazda, bool glosniki, double cena) {
- this->producent = producent;
- this->gwarancja = gwarancja;
- this->przekatna = przekatna;
- this->pion = pion;
- this->poziom = poziom;
- this->rok = rok;
- this->technologia = technologia;
- this->gniazda = gniazda;
- this->glosniki = glosniki;
- this->cena = cena;
- }
- void Monitor::skanujDane() {
- Monitor &Monitor = *this;
- cout << "\tPodaj producenta monitora: "; cin >> Monitor.producent;
- cout << "\tPodaj dlugosc gwarancji: "; cin >> Monitor.gwarancja;
- cout << "\tPodaj dlugosc przekatnej: "; cin >> Monitor.przekatna;
- cout << "\tPodaj ilosc pikseli w pionie: "; cin >> Monitor.pion;
- cout << "\tPodaj ilosc pikseli w poziomie: "; cin >> Monitor.poziom;
- cout << "\tPodaj rok produkcji monitora: "; cin >> Monitor.rok;
- cout << "\tPodaj technologie wyswietlania obrazu: "; cin >> Monitor.technologia;
- cout << "\tPodaj liczbe gniazd: "; cin >> Monitor.gniazda;
- cout << "\tCzy monitor ma glosniki? (jesli ma - kliknij 1, a jesli nie ma - kliknij 0): "; cin >> Monitor.glosniki;
- cout << "\tPodaj cene monitora: "; cin >> Monitor.cena;
- cout << endl;
- }
- void Monitor::drukujDane() {
- Monitor &monitor = *this;
- cout << "\tProducent: " << monitor.producent << endl;
- cout << "\tGwarancja: " << monitor.gwarancja << endl;
- cout << "\tPrzekatna: " << monitor.przekatna << endl;
- cout << "\tIlosc pikseli w pionie: " << monitor.pion << endl;
- cout << "\tIlosc pikseli w poziomie: " << monitor.poziom << endl;
- cout << "\tRok produkcji monitora: " << monitor.rok << endl;
- cout << "\tTechnologia wyswietlania obrazu: " << monitor.technologia << endl;
- cout << "\tLiczba gniazd: " << monitor.gniazda << endl;
- cout << "\tWyposazenie w glosniki: " << monitor.glosniki << endl;
- cout << "\tCena: " << monitor.cena << endl;
- }
- int Monitor::dajCene() const {
- return this->cena;
- };
- int Monitor::dajGniazda() const {
- return this->gniazda;
- }
- bool Monitor::dajGlosniki() const {
- return this->glosniki;
- }
- string Monitor::dajProducenta() const {
- return this->producent;
- }
- int Porownaj(const Monitor &X, const Monitor &Y);
- int main()
- {
- cout << "Podaj liczbe monitorow: ";
- int liczbaMonitorow;
- cin >> liczbaMonitorow;
- Monitor *monitor = new Monitor[liczbaMonitorow];
- for (int i = 0; i != liczbaMonitorow; i++) {
- monitor[i].skanujDane();
- }
- for (int i = 0; i != liczbaMonitorow; i++) {
- monitor[i].drukujDane();
- }
- for (int i = 0; i != liczbaMonitorow; i++) {
- for (int j = i + 1; j != liczbaMonitorow; j++) {
- if (Porownaj(monitor[i], monitor[j]) == -1) {
- monitor[i] = monitor[i];
- monitor[j] = monitor[j];
- }
- else {
- Monitor temp = monitor[i];
- monitor[i] = monitor[j];
- monitor[j] = temp;
- }
- }
- }
- cout << endl << endl << "POSORTOWANE WEDLUG OPLACALNOSCI: ";
- cout << endl << endl;
- for (int i = 0; i != liczbaMonitorow; i++) {
- cout << "Producent: " << monitor[i].dajProducenta() << endl;
- cout << "Cena: " << monitor[i].dajCene() << endl;
- cout << "Liczba gniazd: " << monitor[i].dajGniazda() << endl << endl;
- }
- delete[] monitor;
- }
- int Porownaj(const Monitor &x, const Monitor &y) {
- if (x.dajCene() > y.dajCene() && x.dajGniazda() < y.dajGniazda()) {
- return 1;
- }
- else if (x.dajCene() < y.dajCene() && x.dajGniazda() > y.dajGniazda()) {
- return -1;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement