Skip to content

Instantly share code, notes, and snippets.

@marinat
Created June 5, 2019 06:24
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save marinat/f437a6d89ecdb3df9029bdada5c6ed08 to your computer and use it in GitHub Desktop.
Save marinat/f437a6d89ecdb3df9029bdada5c6ed08 to your computer and use it in GitHub Desktop.
#include <iostream>
#include "TV.h"
using namespace std;
int main() {
TV t;
int choice;
do {
t.show_obj ();
cout << endl;
cout << 1 << "On/Off" << endl;
cout << 2 << "Setup" << endl;
cout << 3 << "Channel up" << endl;
cout << 4 << "Channel down" << endl;
cout << 5 << "Volume up" << endl;
cout << 6 << "Volume down" << endl;
cout << 7 << "Exit" << endl;
cin >> choice;
switch (choice) {
case 1: t.on_off ();
break;
case 2: t.setup_tv ();
break;
case 3: t.chan_up ();
break;
case 4: t.chan_down ();
break;
case 5: t.vol_up ();
break;
case 6: t.vol_down ();
}
}
while (choice!=7);
return 0;
}
#include "TV.h"
#include <iostream>
using namespace std;
TV::TV()
{
is_on = 0;
chan = 0;
volume = 0;
chan_count = 0;
}
TV::TV( int new_on,
int new_chan,
int new_volume,
int new_chan_count)
{
is_on = new_on;
chan = new_chan;
volume = new_volume;
chan_count = new_chan_count;
}
TV::~TV()
{
}
void TV::on_off()
{
is_on=!is_on;
}
void TV::vol_up()
{
if (volume <= 100) {
volume++;
}
}
void TV::vol_down()
{
if (volume > 0 ) {
volume--;
}
}
void TV::setup_tv()
{
chan_count = 3 + rand() % 10;
}
void TV::chan_up()
{
if (chan_count == 0) {
return;
}
if (chan == chan_count) {
chan = 0;
}
else {
chan++;
}
}
void TV::chan_down()
{
if (chan_count == 0) {
return;
}
if (chan == 0) {
chan = chan_count
}
else {
chan--;
}
}
#ifndef TV_H
#define TV_H
class TV
{
public:
TV();
virtual ~TV();
void on_off();
void chan_up();
void chan_down();
void vol_up();
void vol_down();
void setup_tv();
void show_ob
private:
int is_on;
int chan;
int volume;
int chan_count;
};
#endif
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment