هكذا يحل الفرع الأول والثاني.. يبقى عليك تفهم الفكرة وتحل الفرع الثالث
#include <iostream>
#include <string>
#include <regex>
using namespace std;
struct Phone {
string AreaCode;
string Exchange;
string Number;
};
int main() {
struct Phone origin = {"212", "767", "8900"};
struct Phone userInput;
string userPhone;
cout << "\nPlease enter phone number in format: (xxx) xxx-xxxx\n";
getline(cin, userPhone);
regex reg("[\\s()-]+");
userPhone = regex_replace(userPhone, reg, "");
userInput.AreaCode = userPhone.substr(0,3);
userInput.Exchange = userPhone.substr(3,3);
userInput.Number = userPhone.substr(6,4);
cout << "\nOrigin structure" << endl
<< "AreaCode: " << origin.AreaCode << endl
<< "Exchange: " << origin.Exchange << endl
<< "Number: " << origin.Number << endl;
cout << "\nUser Input structure" << endl
<< "AreaCode: " << userInput.AreaCode << endl
<< "Exchange: " << userInput.Exchange << endl
<< "Number: " << userInput.Number << endl;
return 0;
}