-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathISBN.cpp
More file actions
77 lines (71 loc) · 2.01 KB
/
Copy pathISBN.cpp
File metadata and controls
77 lines (71 loc) · 2.01 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
#include <iostream>
#include <cstring>
#include <fstream>
#include <string>
#include <vector>
#include <stdexcept>
#include "ISBN.hpp"
ISBN::ISBN(std::string isbn_num)
{
isbn = isbn_num;
}
std::string ISBN::getIsbn() const
{
return isbn;
}
bool ISBN::operator == (ISBN &isbn)
{
for (int i = 0; i < isbn.getIsbn().length(); i++)
{
if (this->getIsbn()[i] == isbn.getIsbn()[i])
{
return true;
}
else
{
return false;
}
}
}
bool ISBN::isValid(std::string& isbn)
{
if (isbn.length() == 8)
{
if (isdigit(isbn[0]) && isdigit(isbn[1]) && isdigit(isbn[2]) && isbn[3] == '-' &&
isupper(isbn[4]) && isupper(isbn[5]) && isbn[6] == '-' &&
(isbn[7] - '0') % 2 == 0)
{
return true;
}
}
else if (isbn.length() == 9)
{
if (isdigit(isbn[0]) && isdigit(isbn[1]) && isdigit(isbn[2]) && isbn[3] == '-' &&
isupper(isbn[4]) && isupper(isbn[5]) && isupper(isbn[6]) && isbn[7] == '-' &&
(isbn[8] - '0') % 2 != 0)
{
return true;
}
}
else
{
return false;
}
}
/*
bool ISBN::isValid(std::string &isbn)
{
if (isdigit(isbn[0]) && isdigit(isbn[1]) && isdigit(isbn[2]) && isbn[3] == '-' && (isbn[4] >= '65' && isbn[4] <= '90') && (isbn[5] >= '65' && isbn[5] <= '90') && isbn[6] == '-' && (isbn[7] % 2 == 0))
{
return true;
}
else if (isdigit(isbn[0]) && isdigit(isbn[1]) && isdigit(isbn[2]) && isbn[3] == '-' && (isbn[4] >= '65' && isbn[4] <= '90') && (isbn[5] >= '65' && isbn[5] <= '90') && (isbn[6] >= '65' && isbn[6] <= '90') && isbn[7] == '-' && (isbn[8] % 2 != 0))
{
return true;
}
else
{
return false;
}
}
*/