Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // main.cpp
- #include "base.hpp"
- void printFMRadio(const FMRadio &rf)
- {
- system("cls");
- cout << "*** FM Radio je u stanju: ";
- switch(rf.getState())
- {
- case sON:
- cout << "ON! ***" << endl;
- break;
- case sOFF:
- cout << "OFF! ***" << endl;
- break;
- case sOUT:
- cout << "OUT! ***" << endl;
- break;
- default:
- cout << "N/A ***" << endl;
- break;
- }
- cout << "Frekvencija je: " << rf.getFQ() << " MHz" << endl;
- cout << "Jacina zvuka je: " << rf.getVol() << endl;
- cout << endl;
- }
- char meni()
- {
- char odg;
- do
- {
- cout << "Izabrerite opciju :" << endl;
- cout << "1. Ukljuci FMRadio" << endl;
- cout << "2. Iskljuci FMRadio" << endl;
- cout << "3. Pokvari FMRadio" << endl;
- cout << "4. Popravi FMRadio" << endl;
- cout << "5. Povecaj frekvenciju" << endl;
- cout << "6. Smanji frekvenciju" << endl;
- cout << "7. Povecaj jacinu zvuka" << endl;
- cout << "8. Smanji jacinu zvuka" << endl;
- cout << "9. Kraj rada" << endl;
- cin >> odg;
- }
- while (odg < '1' || odg > '9');
- return odg;
- }
- int main()
- {
- FMRadio f;
- char ch;
- do
- {
- ch = meni();
- switch(ch)
- {
- case '1':
- if (f.turnOn())
- cout << "Operacija izvrsena!" << endl;
- else
- cout << "Operacija nije izvrsena!" << endl;
- printFMRadio(f);
- break;
- case '2':
- if (f.turnOff())
- cout << "Operacija izvrserna!" << endl;
- else
- cout << "Operacija nije izvrsena!" << endl;
- printFMRadio(f);
- break;
- case '3':
- if (f.turnOut())
- cout << "Operacija izvrsena!" << endl;
- else
- cout << "Operacija nije izvrsena!" << endl;
- printFMRadio(f);
- break;
- case '4':
- if (f.repair())
- cout << "Operacija izvrsena!" << endl;
- else
- cout << "Operacija nije izvrsena!" << endl;
- printFMRadio(f);
- break;
- case '5':
- if (f.incF())
- cout << "Operacija izvrsena!" << endl;
- else
- cout << "Operacija nije izvrsena!" << endl;
- printFMRadio(f);
- break;
- case '6':
- if (f.decF())
- cout << "Operacija izvrsena!" << endl;
- else
- cout << "Operacija nije izvrsena!" << endl;
- printFMRadio(f);
- break;
- case '7':
- if (f.incV())
- cout << "Operacija izvrsena!" << endl;
- else
- cout << "Operacija nije izvrsena!" << endl;
- printFMRadio(f);
- break;
- case '8':
- if (f.decV())
- cout << "Operacija izvrsena!" << endl;
- else
- cout << "Operacija nije izvrsena!" << endl;
- printFMRadio(f);
- break;
- }
- }
- while (ch != '9');
- return 0;
- }
- // radio.hpp
- #ifndef RADIO_HPP_INCLUDED
- #define RADIO_HPP_INCLUDED
- #include <iostream>
- #include <cstdlib>
- #include <math.h>
- using namespace std;
- // Config:
- #define MINF 87.5
- #define MAXF 108.0
- #define MINV 0
- #define MAXV 20
- #define PV 1
- #define PF 0.5
- enum stanje
- {
- sON, sOFF, sOUT
- };
- class FMRadio
- {
- private:
- stanje state;
- double FQ;
- int vol;
- public:
- // Konstruktor + Konstruktor kopije!
- FMRadio();
- FMRadio(const FMRadio&);
- // Metode!
- stanje getState() const;
- int getVol() const;
- double getFQ() const;
- bool turnOn();
- bool turnOff();
- bool turnOut();
- bool repair();
- bool incV();
- bool decV();
- bool incF();
- bool decF();
- };
- #endif // RADIO_HPP_INCLUDED
- // radio.cpp
- #include "radio.hpp"
- FMRadio :: FMRadio()
- {
- state = sOFF;
- FQ = MINF;
- vol = MINV;
- }
- FMRadio :: FMRadio(const FMRadio &rf)
- {
- state = rf.state;
- FQ = rf.FQ;
- vol = rf.vol;
- }
- stanje FMRadio :: getState() const
- {
- return state;
- }
- double FMRadio :: getFQ() const
- {
- return FQ;
- }
- int FMRadio :: getVol() const
- {
- return vol;
- }
- bool FMRadio :: turnOn()
- {
- if (state == sOFF)
- {
- state = sON;
- return true;
- }
- else
- return false;
- }
- bool FMRadio :: turnOff()
- {
- if (state == sON)
- {
- state = sOFF;
- return true;
- }
- else
- return false;
- }
- bool FMRadio :: turnOut()
- {
- if (state == sON || state == sOFF)
- {
- state = sOUT;
- FQ = -1;
- vol = -1;
- return true;
- }
- else
- return false;
- }
- bool FMRadio :: repair()
- {
- if (state == sOUT)
- {
- state = sOFF;
- return true;
- }
- else
- return false;
- }
- bool FMRadio :: incV()
- {
- if (state == sON && vol+PV <= MAXV)
- {
- vol+=PV;
- return true;
- }
- else
- return false;
- }
- bool FMRadio :: decV()
- {
- if (state == sON && vol-PV >= MINV)
- {
- vol-=PV;
- return true;
- }
- else
- return false;
- }
- bool FMRadio :: incF()
- {
- if (state == sON && FQ+PF <= MAXF)
- {
- FQ+=PF;
- return true;
- }
- else
- return false;
- }
- bool FMRadio :: decF()
- {
- if (state == sON && FQ-PF >= MINF)
- {
- FQ-=PF;
- return true;
- }
- else
- return false;
- }
Advertisement
Add Comment
Please, Sign In to add comment