-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.cpp
92 lines (79 loc) · 1.51 KB
/
main.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
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
#include <iostream>
#include <string.h>
#include <stdexcept>
using namespace std;
class student {
public:
char name[50];
char surname[50];
char number[50];
};
student s;
void init() {
strcpy(s.name, "");
strcpy(s.surname, "");
strcpy(s.number, "");
}
bool isString(string str)
{
for (int i = 0; i < str.length(); i++){
char x = str.at(i);
if (int(x) >= 48 && int(x) <= 57)
return false;
}
return true;
}
bool isDigit(string str){
for (int i = 0; i < str.length(); i++){
char x = str.at(i);
if (int(x) > 57)
return false;
}
return true;
}
void enter_name() {
cout << "Enter name: ";
cin >> s.name;
if (!isString(s.name)){
strcpy(s.name, "");
throw runtime_error("You use number in name.");
}
}
void enter_surname() {
cout << "Enter surname: ";
cin >> s.surname;
if (!isString(s.surname)){
strcpy(s.surname, "");
throw runtime_error("You use number in surname.");
}
}
void enter_number() {
cout << "Enter number: ";
cin >> s.number;
if (!isDigit(s.number)){
strcpy(s.number, "");
throw runtime_error("You use string in number.");
}
}
void func() {
try {
if (strcmp(s.name, "") == 0)
enter_name();
if (strcmp(s.surname, "") == 0)
enter_surname();
if (strcmp(s.number, "") == 0)
enter_number();
}
catch (const exception &ex)
{
cout << ex.what() << "\n";
func();
}
}
int main()
{
init();
func();
cout << s.name << " " << s.surname << " " << s.number;
return 0;
}