-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathKeyboard.cpp
More file actions
70 lines (57 loc) · 1.22 KB
/
Keyboard.cpp
File metadata and controls
70 lines (57 loc) · 1.22 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
#include "Keyboard.h"
#include <iostream>
Keyboard::Keyboard()
{
}
Keyboard::~Keyboard()
{
}
Keyboard* Keyboard::getKeyboard()
{
static Keyboard keyboard; //initialized when method is called the first time
return &keyboard; //won't go out of scope as keyboard is static
}
int Keyboard::readInt(string prompt)
{
cout << prompt;
int val = 0;
cin >> val;
return val;
}
int Keyboard::getValidatedInt(string prompt, int min, int max)
{
int validated = readInt(prompt);
cout << validated << endl;
while(validated < min || validated > max)
{
validated = readInt(prompt);
cout << validated << endl;
}
return validated;
}
double Keyboard::readDouble(string prompt)
{
cout << prompt;
double val = 0;
cin >> val;
return val;
}
double Keyboard::getValidatedDouble(string prompt, double min, double max)
{
double validated = readDouble(prompt);
cout << validated << endl;
while(validated < min || validated > max)
{
validated = readDouble(prompt);
cout << validated << endl;
}
return validated;
}
String* Keyboard::readString(string prompt)
{
cout << prompt;
string text;
getline(cin, text);
String* str = new String(text.c_str());
return str;
}