-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathHelper.cpp
More file actions
80 lines (72 loc) · 1.81 KB
/
Copy pathHelper.cpp
File metadata and controls
80 lines (72 loc) · 1.81 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
#include <iostream>
#include <iomanip>
#include <limits>
#include <string>
#include "Helper.h"
using namespace std;
void log(string type, string content)
{
cout << "[" << type << "]: " << content << endl;
}
int Helper::getRangeInput(int min, int max)
{
int userInput = 0;
while (true)
{
cin >> userInput;
if (cin.fail())
{
cin.clear();
cin.ignore(std::numeric_limits<std::streamsize>::max(), '\n');
log("error", "Invalid input, please try again");
}
else
{
if (userInput < min || userInput > max)
{
log("error", "Invalid input, please try again");
}
else
{
cin.ignore(std::numeric_limits<std::streamsize>::max(), '\n');
return userInput;
}
}
}
}
int Helper::searchName(string searchQuery, Contact contacts[], int count)
{
int contactId;
for (contactId = 0; contactId < count; contactId++)
{
if (searchQuery == contacts[contactId].firstName || searchQuery == contacts[contactId].lastName)
{
return contactId;
break;
}
}
return contactId = -1;
}
int Helper::searchPhoneNumber(string searchQuery, Contact contacts[], int count)
{
int contactId;
for (contactId = 0; contactId < count; contactId++)
{
if (searchQuery == contacts[contactId].phoneNumber)
{
return contactId;
break;
}
}
return contactId = -1;
}
void Helper::noResultFound()
{
cout << "\n\n::::::::::::: No Result Found! :::::::::::::\n\n";
}
void Helper::pressEnterToReturn()
{
cin.ignore();
cout << "\n\n<- Press Enter to return to the Menu";
cin.ignore(std::numeric_limits<streamsize>::max(), '\n');
}