Другие языки программирования и технологии

Разработать Класс Person описывающий человека C++

1 Имеет рост больше 200см
2 живет ли в Россие

3 правильно ли задал эл. почту

(содержится ровно 1 знак @ после @ и адрес не начинается и не кончается на точку или @ и не содержит пробелов )
#include <iostream>
#include <string>
#include <regex>
#include <vector>
using namespace std;
void utf8();
bool check_email(string);
class person {
public:
person() : fio(L""), country(L""), email(""), growth(0) { }
person(wstring _fio, wstring _country, string _email, unsigned short _growth) : fio(_fio), country(_country), email(_email), growth(_growth) { }
void set_fio(wstring _fio) { fio = _fio; }
void set_country(wstring _country) { country = _country; }
void set_email(string _email) { email = _email; }
void set_growth(unsigned short _growth) { growth = _growth; }
wstring get_fio() { return fio == L"" ? L"Неизвестный" : fio; }
wstring get_country() { return country == L"" ? L"Не задана" : country; }
string get_email() { return email == "" ? "Не задан" : email; }
unsigned short get_growth() { return growth; }
bool check_email() {
const regex pattern("^([a-z0-9_-]+\\.)*[a-z0-9_-]+@[a-z0-9_-]+(\\.[a-z0-9_-]+)*\\.[a-z]{2,6}$");
return regex_match(email, pattern);
}
bool is_country(wstring _country) { return country == _country; }
bool if_above(unsigned short _growth) { return growth > _growth; }
private:
wstring fio;
wstring country;
string email;
unsigned short growth;
};
int main() {
utf8();
const size_t size = 1;
vector<person> persons;
wstring fio;
wstring country;
string email;
unsigned short growth;
wcout << L" Введите персональные данные для " << size << L" человек: \n";
for (size_t i = 0; i < size; ++i) {
wcin.sync();
wcout << L"\n Введите ФИО: "; getline(wcin, fio);
wcout << L" Введите страну: "; getline(wcin, country);
wcout << L" Введите E-mail: "; getline(cin, email);
wcout << L" Введите рост: "; cin >> growth;
person p(fio, country, email, growth);
persons.push_back(p);
}
bool flag = false;
wstring no = L" Нет данных! \n";
wstring russia = L"Россия";
wcout << L"\n\tГраждане России: \n";
for (size_t i = 0; i < size; ++i) {
if (persons.at(i).is_country(russia)) {
wcout << L' ' << persons.at(i).get_fio() << L"\n";
flag = true;
}
}
if (!flag) wcout << no;
else flag = false;
growth = 200;
wcout << L"\n\tВыше 200 см: \n";
for (size_t i = 0; i < size; ++i) {
if (persons.at(i).if_above(growth)) {
wcout << L' ' << persons.at(i).get_fio() << L" = " << persons.at(i).get_growth() << L"\n";
flag = true;
}
}
if (!flag) wcout << no;
else flag = false;
wcout << L"\n\tНеверно написаны адреса электронной почты: \n";
for (size_t i = 0; i < size; ++i) {
if (!persons.at(i).check_email()) {
wcout << L' ' << persons.at(i).get_fio() << L" = ";
cout << persons.at(i).get_email() << "\n";
flag = true;
}
}
if (!flag) wcout << no;
else flag = false;
cin.sync();
cin.get();
return 0;
}
void utf8() {
wcin.imbue(locale(".866"));
wcout.imbue(locale(".866"));
}
ИБ
Игорь Базыльчук
91 492
Лучший ответ
class man {
private:
double height;
bool liveInRussia;
string mail;
public:
man() {}
man(double h, bool b, string s) {
height = h;
liveInRussia = b;
mail = s;
}
~man();
void setHeight(double h) {
height = h;
}
double getHeight() {
return height;
}
void setLiveInRussia(bool b) {
liveInRussia = b;
}
bool getLiveInRussia() {
return liveInRussia;
}
void setMail(string m) {
mail = m;
}
string getMail() {
return mail;
}
bool correctMail() {
bool correct = true;
int counter = 0;
for(int i = 0; i < mail.size(); ++i) {
if(mail[i] == ' ') correct = false;
if((i == 0 || i == mail.size()-1) && (mail[i]=='.' || mail[i]=='@')) correct = false;
if(mail[i]=='@') ++counter;
if (counter > 1) correct = false;
}
if(counter!=1) correct = false;
return correct;

}
}
VM
Vitaly M...(Schindler)
1 659