-
Notifications
You must be signed in to change notification settings - Fork 0
/
Source.cpp
57 lines (41 loc) · 1.09 KB
/
Source.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
// hasna ben jillali
//11/29/2022
// cis1202
#include<iostream>
using namespace std;
class invalidCharacterExeption{};
class invalidRangeExeption {};
class invalidConversionExeption{};
// function prototype
char character(char , int );
int main(){
cout << character ('a',-1) << endl;
//cout << character('Z', -1) << endl;
//cout << character('A', 32) << endl;
return 0;
}
char character(char start, int offset) {
int num;
int ascii = int(start);
num = ascii + offset;
try {
if ((ascii < 65 || ascii>90) && (ascii < 97 || ascii>122))
throw invalidCharacterExeption();
else if ((num < 65 || num>90) && (num < 97 || num>122))
throw invalidRangeExeption{};
else if ((num >= 65 || num >= 90) && (num <= 97 || num >= 1220))
throw invalidConversionExeption();
}
catch (invalidCharacterExeption a) {
cout << " Error!invalid character exeption" << endl;
}
catch(invalidRangeExeption b )
{
cout << " Error!invalid Range exeption" << endl;
}
catch (invalidConversionExeption c)
{
cout << " Error!invalid conversion exeption" << endl;
}
return static_cast<char>(num);
}