-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathTvproblem.cpp
More file actions
84 lines (64 loc) · 2.06 KB
/
Copy pathTvproblem.cpp
File metadata and controls
84 lines (64 loc) · 2.06 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
/*Implemente uma televisão. A televisão tem um controle de volume
do som (0-100) e um controle de seleção de canal (1 a 99).
- A operação construtora inicia a TV no canal 10 e volume 0
- A operação que altera o canal pode receber o caracter ‘+’ ou ‘-’
para alterar o canal em uma unidade
- A operação que altera o volume recebe um caracter (‘+’, ‘-’ ou
‘M’ para mudo) referente à ação desejada
- Crie uma função main que constroi o objeto TV, aumenta o
volume até 3 e muda para o canal 15.
- Quem serão os atributos? É necessário criar getters e setters?
*/
#include<iostream>
using namespace std;
class Television{
private:
int volume;
int channel;
public:
Television(){
volume=0;
channel=10;
};
void Changechannel(char button){
if((button=='+') && (channel<99)){
channel+=1;
}
else if((button='-') && (channel!=0)){
channel-=1;
}
}
void ChangeVolume(char button){
if(button=='+' && volume<100){
volume+=1;
}
else if(button=='-' && volume>0){
volume-=1;
}
else if(button=='M'){
volume=0;
}
}
int getChannel(){
return channel;
}
int getVolume(){
return volume;
}
};
int main(){
Television SempToshiba;
std::cout<<SempToshiba.getChannel()<<std::endl;
std::cout<<SempToshiba.getVolume()<<std::endl;
SempToshiba.ChangeVolume('+');
SempToshiba.ChangeVolume('+');
SempToshiba.ChangeVolume('+');
SempToshiba.Changechannel('+');
SempToshiba.Changechannel('+');
SempToshiba.Changechannel('+');
SempToshiba.Changechannel('+');
SempToshiba.Changechannel('+');
std::cout<<SempToshiba.getVolume()<<std::endl;
std::cout<<SempToshiba.getChannel()<<std::endl;
return 0;
}