Então , preciso ler e mostrar o telefone cadastrado por máscara. Ex: (DDD) XXXX-XXXX. Porém não achei nenhum exemplo em c++ , somente em java. E o email também deve ser válido, ou seja, deve conter um "@" e um "." (ponto final) após o "@".
#include <iostream>
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
using namespace std;
static int id = 0;
class pessoa {
private:
int idPessoa, alt_codigo, cod_busca;
char nome[30], email[50], telefone[10], rg[11], nome_busca[30], alt_nome[30];
char novo_nome[30], novo_email[50], novo_telefone[10], novo_rg[11];
public:
void cadastrar();
void listar();
void alterar(int y);
void busca(int y);
};
pessoa **p;
int getId() {
id++;
return id;
}
void pessoa :: cadastrar() {
idPessoa = getId();
cout << "Digite o Nome: ";
cin >> nome;
cout << "Digite o Email: ";
cin >> email;
cout << "Digite o Telefone (com DDD): ";
cin >> telefone;
cout << "Digite o RG: ";
cin >> rg;
};
void pessoa :: listar() {
cout << "Codigo: " << idPessoa;
cout << " Nome: " << nome;
cout << " Email: " << email;
cout << " Telefone: " << telefone;
cout << " RG: " << rg << endl << endl;
};
void pessoa :: alterar(int y) {
int achou=0;
int x;
int busca_alterar;
int alt_cad;
cout << "1- Pesquisar por Nome\n2- Pesquisar por Codigo\nDigite a opcao desejada: ";
cin >> busca_alterar;
if(busca_alterar==1){
system("cls");
cout << "Digite o Nome do Cliente: ";
cin >> alt_nome;
for ( int i=0; i<y; i++ ){
if(strcmp(p[i]->nome,alt_nome)==0){
achou=1;
x=i;
break;
}
}if (achou==1){
cout << "\nCodigo: " << p[x]->idPessoa;
cout << " Nome: " << p[x]->nome;
cout << " Email: " << p[x]->email;
cout << " Telefone: " << p[x]->telefone;
cout << " RG: " << p[x]->rg << endl << endl;
cout << "\n1- Alterar Nome\n2- Alterar Email\n3- Alterar Telefone\n4- Alterar RG\nDigite a opcao desejada: ";
cin >> alt_cad;
system("cls");
if(alt_cad==1){
cout << "Digite o novo Nome: ";
cin >> novo_nome;
strcpy(p[x]->nome,novo_nome);
}
if(alt_cad==2){
cout << "Digite o novo Email: ";
cin >> novo_email;
strcpy(p[x]->email,novo_email);
}
if(alt_cad==3){
cout << "Digite o novo Telefone:";
cin >> novo_telefone;
strcpy(p[x]->telefone,novo_telefone);
}
if(alt_cad==4){
cout << "Digite o novo Rg: ";
cin >> novo_rg;
strcpy(p[x]->rg,novo_rg);
}
system("cls");
}else{
system("cls");
system("color 74");
cout << "O Nome Digitado não Existe !!!" << endl;
system("pause");
system("cls");
system("color 07");
}
}
if(busca_alterar==2){
system("cls");
cout << "Digite o Codigo do Cliente: ";
cin >> alt_codigo;
for ( int i=0; i<y; i++ ){
if(p[i]->idPessoa==alt_codigo){
achou=1;
x=i;
break;
}
}if (achou==1){
cout << "\nCodigo: " << p[x]->idPessoa;
cout << " Nome: " << p[x]->nome;
cout << " Email: " << p[x]->email;
cout << " Telefone: " << p[x]->telefone;
cout << " RG: " << p[x]->rg << endl << endl;
cout << "\n1- Alterar Nome\n2- Alterar Email\n3- Alterar Telefone\n4- Alterar RG\nDigite a opcao desejada: ";
cin >> alt_cad;
system("cls");
if(alt_cad==1){
cout << "Digite o novo Nome: ";
cin >> novo_nome;
strcpy(p[x]->nome,novo_nome);
}
if(alt_cad==2){
cout << "Digite o novo Email: ";
cin >> novo_email;
strcpy(p[x]->email,novo_email);
}
if(alt_cad==3){
cout << "Digite o novo Telefone:";
cin >> novo_telefone;
strcpy(p[x]->telefone,novo_telefone);
}
if(alt_cad==4){
cout << "Digite o novo Rg: ";
cin >> novo_rg;
strcpy(p[x]->rg,novo_rg);
}
system("cls");
}else{
system("cls");
system("color 74");
cout << "O Codigo Digitado não Existe !!!" << endl;
system("pause");
system("cls");
system("color 07");
}
}
};
void pessoa :: busca(int y){
int achou=0;
int x;
int tipo_busca;
cout << "1- Busca por Codigo\n2- Busca por nome\nDigite a opcao desejada: ";
cin >> tipo_busca;
if(tipo_busca==1){
system("cls");
cout << "Digite o Codigo Que Sera Buscado: ";
cin >> cod_busca;
for ( int i=0; i<y; i++ ){
if(p[i]->idPessoa==cod_busca){
achou=1;
x=i;
break;
}
}if (achou==1){
system("cls");
cout << "Codigo: " << p[x]->idPessoa;
cout << " Nome: " << p[x]->nome;
cout << " Email: " << p[x]->email;
cout << " Telefone: " << p[x]->telefone;
cout << " RG: " << p[x]->rg << endl << endl;
}else {
system("cls");
system("color 7D");
cout << "O Codigo Digitado não Existe !!!" << endl;
system("pause");
system("cls");
system("color 07");
}
}
if(tipo_busca==2){
system("cls");
cout << "Digite o Nome Que Sera Buscado: ";
cin >> nome_busca;
for ( int i=0; i<y; i++ ){
if(strcmp(p[i]->nome,nome_busca)==0){
achou=1;
x=i;
break;
}
}if (achou==1){
system("cls");
cout << "Codigo: " << p[x]->idPessoa;
cout << " Nome: " << p[x]->nome;
cout << " Email: " << p[x]->email;
cout << " Telefone: " << p[x]->telefone;
cout << " RG: " << p[x]->rg << endl << endl;
}else {
system("cls");
system("color 7D");
cout << "O Nome Digitado não Existe !!!" << endl;
system("pause");
system("cls");
system("color 07");
}
}
};
int main() {
int y = 0, opc, new_opc;
p = (pessoa **)malloc(sizeof(pessoa**));
do {
cout << "\n----- MENU -----" << endl;
cout << "1- Cadastrar" << endl;
cout << "2- Listar" << endl;
cout << "3- Alterar" << endl;
cout << "4- Buscar" << endl;
cout << "5- Reiniciar " << endl;
cout << "0- Sair" << endl;
cout << "----------------" << endl;
cout << "Informe a Opcao: ";
cin >> opc;
switch ( opc ) {
case 1:
system ( "cls" );
do {
p[y] = new pessoa;
p[y]->cadastrar();
new_opc = 0;
cout << "Deseja continuar cadastrando? 1-Sim / 2-não " << endl;
cin >> new_opc;
y++;
} while ( new_opc == 1 );
system ( "cls" );
break;
case 2:
system ( "cls" );
if (y>=1){
for ( int i = 0; i < y; i++ ) {
p[i]->listar();
}
}else{
cout << "não existem cadastros" <<endl ;
break;
}
break;
case 3:
system ( "cls" );
if (y>=1){
p[0]->alterar(y);
}else{
cout << "não existem cadastros" <<endl ;
break;
}
break;
case 4:
if (y>=1){
system ( "cls" );
p[0]->busca(y);
}else{
system ( "cls" );
cout << "não existem cadastros" <<endl ;
break;
}
break;
case 5:
system ( "cls" );
y=0;
break;
default:
exit ( 0 );
}
} while ( opc != 0 );
delete[] p;
return 0;
}
Se alguém conseguir ajudar :)