#include <iostream>
#include "Contact.h"
using namespace std;
using namespace sict;
int main()
{
cout << "----------------------------------------" << endl;
cout << "Testing the default constructor!" << endl;
cout << "----------------------------------------" << endl;
sict::Contact empty; // sict:: intentional
empty.display();
cout << "----------------------------------------" << endl << endl;
cout << "----------------------------------------" << endl;
cout << "Testing an invalid contact!" << endl;
cout << "----------------------------------------" << endl;
Contact bad(nullptr, nullptr, 0);
bad.display();
Contact alsoBad("", nullptr, 0);
alsoBad.display();
cout << "----------------------------------------" << endl << endl;
cout << "----------------------------------------" << endl;
cout << "Testing the constructor with parameters!" << endl;
cout << "----------------------------------------" << endl;
Contact temp("A very long name for contact!", nullptr, 0);
temp.display();
cout << "----------------------------------------" << endl << endl;
cout << "----------------------------------------" << endl;
cout << "Testing a valid contact!" << endl;
cout << "----------------------------------------" << endl;
long long phoneNumbers[] = { 1416123456LL, // invalid: no country code
14161234567LL,
1416234567890LL, // invalid: wrong country code
14162345678LL,
10162345678LL, // invalid: wrong area code
-1LL, // invalid: all components are wrong
124163456789LL,
14160345678LL, // invalid: wrong phone component
14161230002LL
};
Contact someContact("John Doe", phoneNumbers, 9);
someContact.display();
cout << "----------------------------------------" << endl << endl;
return 0;
}
已经给了我这段代码,我必须使用一个函数来检查“ long long phoneNumbers []”中的电话号码是否有效。
应满足以下要求以使电话号码有效:
有效的电话号码包含国家或地区代码的一两位数字(不能为零)
区号正好包含三位数(不能以零开头)
,并且数字的位数恰好是偶数(不能以零开头);
我很难将代码分为区号,国家/地区代码和主要电话号码,因此我无法验证电话号码。
感谢任何帮助!
答案 0 :(得分:1)
您可以使用2种方法:
将电话号码作为整数分隔为多个号码。例如,如果您想获取数字的最后两位数字,则可以执行以下操作:
last_2_digits = original_number % 100;
祝你好运〜