-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcontact.cpp
88 lines (69 loc) · 2.41 KB
/
contact.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
#include <iostream>
#include <regex>
#include <vector>
class Contact {
protected:
std::string name;
std::string phone;
public:
Contact(const std::string& name, const std::string& phone)
: name(name), phone(phone) {}
virtual void display() const = 0;
virtual void share() const = 0;
virtual bool validate() const = 0;
const std::string& getName() const {
return name;
}
const std::string& getPhone() const {
return phone;
}
};
class PersonalContact : public Contact {
public:
PersonalContact(const std::string& name, const std::string& phone)
: Contact(name, phone) {}
void display() const override {
std::cout << "Personal Contact: Name - " << name << ", Phone - " << phone << std::endl;
}
void share() const override {
std::cout << "Sharing Personal Contact: " << name << " via email..." << std::endl;
}
bool validate() const override {
std::regex phoneRegex(R"(\d{10})");
return std::regex_match(phone, phoneRegex);
}
};
class BusinessContact : public Contact {
private:
std::string company;
public:
BusinessContact(const std::string& name, const std::string& phone, const std::string& company)
: Contact(name, phone), company(company) {}
void display() const override {
std::cout << "Business Contact: Name - " << name << ", Phone - " << phone << ", Company - " << company << std::endl;
}
void share() const override {
std::cout << "Sharing Business Contact: " << name << " via email..." << std::endl;
}
bool validate() const override {
std::regex phoneRegex(R"(\d{10})");
return (std::regex_match(phone, phoneRegex) && !company.empty());
}
};
class FamilyContact : public Contact {
private:
std::string relation;
public:
FamilyContact(const std::string& name, const std::string& phone, const std::string& relation)
: Contact(name, phone), relation(relation) {}
void display() const override {
std::cout << "Family Contact: Name - " << name << ", Phone - " << phone << ", Relation - " << relation << std::endl;
}
void share() const override {
std::cout << "Sharing Family Contact: " << name << " via text message..." << std::endl;
}
bool validate() const override {
std::regex phoneRegex(R"(\d{10})");
return (std::regex_match(phone, phoneRegex) && !relation.empty());
}
};