forked from koko89090k-design/Student_Management_System
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathutils.cpp
More file actions
59 lines (59 loc) · 1.15 KB
/
Copy pathutils.cpp
File metadata and controls
59 lines (59 loc) · 1.15 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
#include "utils.h"
using namespace std;
int getIntInput(const std::string& prompt){
int n;
while(true){
cout<<prompt<<'\n';
cin>>n;
if (cin.fail()){
cin.clear();
cin.ignore(std::numeric_limits<std::streamsize>::max(), '\n');
cout<<"input failed try again\n";
}
else{
break;
}
}
return n;
}
double getDoubleInput(const std::string& prompt){
double n;
while(true){
cout<<prompt<<'\n';
cin>>n;
if (cin.fail()){
cin.clear();
cin.ignore(std::numeric_limits<std::streamsize>::max(), '\n');
cout<<"input failed try again\n";
}
else{
break;
}
}
return n;
}
std::string getStringInput(const std::string& prompt){
cin.ignore(numeric_limits<streamsize>::max(), '\n');
string n;
while(true){
cout<<prompt<<'\n';
getline(cin,n);
if (n.empty()){
cout<<"input cannot be empty\n";
}
else{
break;
}
}
return n;
}
template <typename T>
T findMax(const std::vector<T>& items){
T mx=items[0];
for(int i=1;i<items.size();i++){
if(mx<items[i]){
mx=items[i];
}
}
return mx;
}