-
Notifications
You must be signed in to change notification settings - Fork 0
/
helper.cpp
66 lines (55 loc) · 1.03 KB
/
helper.cpp
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
#include <iostream>
#include <fstream>
#include <string>
#include "helper.h"
#include "errors.h"
using namespace std;
bool repetition_test (int num_array[], int array_pos, int& repeat_index)
{
for (int i = array_pos - 1; i >= 0; i--)
{
if(num_array[i] == num_array[array_pos])
{
repeat_index = i;
return false;
}
}
return true;
}
bool range_test(int num_array[], int array_pos)
{
if(num_array[array_pos] < 0 || num_array[array_pos] > 25)
{
return false;
} else
{
return true;
}
}
bool symbol_test(ifstream& input_file)
{
int position = input_file.tellg();
string next;
input_file >> next;
for (int i = 0; i < int(next.length()) && !input_file.eof(); i++)
{
if(!isdigit(next[i]) && !(i == 0 && next[0] == '-'))
{
return false;
}
}
input_file.seekg(position, ios_base::beg);
return true;
}
bool eof_test(ifstream& input_file)
{
char c = 0;
int offset = input_file.tellg();
input_file >> c;
if(c == '\n' || input_file.eof())
{
return true;
}
input_file.seekg(offset, ios_base::beg);
return false;
}