Ir ao conteúdo
  • Cadastre-se

Davidgdf

Membro Júnior
  • Posts

    5
  • Cadastrado em

  • Última visita

Reputação

1
  1. problema resolvido, o erro estava no construtor de Rede social. perdão por não postar todo o código.
  2. Aqui está o restante, tem coisas q n vai usar aqui, mas td bem. @vangodp .h da Redesocial, .cpp está acima (não queria perguntar para meu professor, porque ele não responde nada que você pergunta) #ifndef REDESOCIAL_H #define REDESOCIAL_H #include "Perfil.h" class RedeSocial { public: RedeSocial (int numeroMaximoDePerfis); ~RedeSocial(); Perfil** getPerfis(); int getQuantidadeDePerfis(); bool adicionar(Perfil* perfil); void imprimir (); Perfil** perfis; int quantidadeDePerfis=0; int numeroMaximoDePerfis; }; #endif // REDESOCIAL_H #ifndef PERFIL_H #define PERFIL_H #include <string> #include <iostream> using namespace std; #define MAXIMO_PUBLICACOES 20 #define MAXIMO_SEGUIDORES 20 class Publicacao; class Perfil { public: // Construtor Perfil(int numeroUSP, string nome, string email); Perfil(string nome); // Destrutor ~Perfil(); // Atributos string nome; int numeroUSP; string email; // Getters e setters string getNome(); int getNumeroUSP(); string getEmail(); // /* Perfil* seguidor = NULL; Perfil* seguidores[MAXIMO_SEGUIDORES]; int quantidadeDeSeguidores = 0; int quantidadeDePublicacoesRecebidas=0; int quantidadeDePublicacoesFeitas=0;*/ // // Imprime o Perfil. void imprimir (); private: }; #endif // PERFIL_H #include "Perfil.h" Perfil::Perfil(int numeroUSP, string nome, string email) : numeroUSP(numeroUSP), nome(nome), email(email) { } Perfil::Perfil(string nome) : nome(nome) { } string Perfil::getNome() { return nome; } int Perfil::getNumeroUSP() { return numeroUSP; } string Perfil::getEmail() { return email; } /*Perfil::~Perfil() { cout << "Destrutor de perfil: " << nome << " - Quantidade de publicacoes feitas: " << quantidadeDePublicacoesFeitas << endl; // COMPLETE cout << "Perfil deletado" << endl; }*/ void Perfil::imprimir() { cout << endl << "Nome: " << nome << endl; } MAIN todo: #include <iostream> #include <string> #include "Perfil.h" #include "RedeSocial.h" using namespace std; void telaInicio(RedeSocial* r1){ int opcaoinicio=0; cout << r1->quantidadeDePerfis; cout << endl << "Escolha uma opcao: "; cout << endl << "1) Cadastar Perfil "; cout << endl << "2) Cadastrar Disciplina"; cout << endl << "3) Logar"; cout << endl << "0) Terminar " << endl; cin >> opcaoinicio; if (opcaoinicio==1){ int numerouspper=0; string nomeper=""; string emailper=""; string respprofessor=""; cout << endl << "Informe os dados do perfil " << endl; cout << "Numero: "; cin >> numerouspper; cout << "Nome: "; cin >> nomeper; cout << "Email: "; cin >> emailper; cout << "Professor (s/n): "; cin >> respprofessor; if (respprofessor=="n"){ Perfil* p1= new Perfil(numerouspper,nomeper,emailper); r1->adicionar(p1); r1->imprimir(); telaInicio(r1); }else{ cout << "Departamento: "; cin >> respprofessor; r1->imprimir(); telaInicio(r1); } } } int main() { int quantidademaxPerfis=0; cout << endl << "Tamanho da rede: " << endl; cin >> quantidademaxPerfis; RedeSocial* r1 = new RedeSocial(quantidademaxPerfis); telaInicio(r1); return 0; }
  3. Se eu crio perfil 1, perfil 2 assim: Da certo, porém, eu quero que seja possivel criar quantos perfils o usuario determinar. Perfil *p1=new Perfil(...) Perfil *p2=new Perfil(...) r1->adicionar(p1); r1->adicionar(p2); Meu problema está nessa parte Porque eu consigo criar o perfil 1, mas não o resto. Se eu uso delete p1, para liberar ele na memória o processo para, não sei porque. Ja tentei criar uma lista de perfis também. tipo ** perfis; (Estou me referindo a criar objeto Perfil) perfis[0]= new Perfil(...); ...[1]=...; r1->adicionar(perfis[contador]); uso esse contador para toda vez a função telaInicio for chamada, mas nao deu O main chama a função que está acima. Isso é tudo que to usando na função main, int main() { int quantidademaxPerfis=0; cout << endl << "Tamanho da rede: " << endl; cin >> quantidademaxPerfis; RedeSocial* r1 = new RedeSocial(quantidademaxPerfis); telaInicio(r1); return 0; } cpp #include "RedeSocial.h" RedeSocial::~RedeSocial() { cout << "Destrutor de RedeSocial: " << quantidadeDePerfis << " perfis" << endl; // COMPLETE cout << "RedeSocial deletada " << endl; } RedeSocial::RedeSocial(int numeroMaximoDePerfis) : numeroMaximoDePerfis(numeroMaximoDePerfis) { } Perfil** RedeSocial::getPerfis() { return perfis; } int RedeSocial::getQuantidadeDePerfis() { return quantidadeDePerfis; } bool RedeSocial::adicionar(Perfil* perfil) { if (quantidadeDePerfis<numeroMaximoDePerfis){ this->perfis[quantidadeDePerfis]= perfil; quantidadeDePerfis+= 1; return true; } return false; } void RedeSocial::imprimir () { cout << endl << "------------------------------ " << endl; cout << "RedeSocial: " << quantidadeDePerfis << " perfis" << endl; cout << "------------------------------ " << endl; if (quantidadeDePerfis == 0){ cout << "Sem perfis" << endl; cout << "------------------------------ " << endl; } else { for (int i = 0; i < quantidadeDePerfis; i++){ perfis[i]->imprimir(); cout << "------------------------------ " << endl; } } cout << endl; }
  4. void telaInicio(RedeSocial* r1){ int opcaoinicio=0; int numerouspper=0; string nomeper=""; string emailper=""; string respprofessor=""; Perfil** perfis; cout << endl << "Escolha uma opcao: "; cout << endl << "1) Cadastar Perfil "; cout << endl << "2) Cadastrar Disciplina"; cout << endl << "3) Logar"; cout << endl << "0) Terminar " << endl; cin >> opcaoinicio; if ( opcaoinicio==1){ cout << endl << "Informe os dados do perfil " << endl; cout << "Numero: "; cin >> numerouspper; cout << "Nome: "; cin >> nomeper; cout << "Email: "; cin >> emailper; cout << "Professor (s/n): "; cin >> respprofessor; if (respprofessor=="n"){ Perfil *p1= new Perfil(numerouspper,nomeper,emailper); r1->adicionar(p1); r1->imprimir(); telaInicio(r1); }else{ cout << "Departamento: "; cin >> respprofessor; Professor *p2= new Professor(numerouspper,nomeper,emailper,respprofessor); r1->adicionar(p2); r1->imprimir(); telaInicio(r1); } }else if(opcaoinicio==2){ string sigla; cout << endl << "Informe os dados da disciplina " << endl; cout << "Sigla: "; cin >> sigla; cout << "Nome: "; cin >> nomeper; cout << "Responsavel: " << endl; }else if(opcaoinicio==3){ }else if(opcaoinicio==0){ } } Eu tava mexendo, mas seria isso, porcaria. Tipo agora só está encerrando a aplicação, quando vou adicionar o perfil 2. tentei criar uma lista de perfils, eai continuo tentando. @vangodp Eai tenho as classes, RedeSocial, Perfil bool RedeSocial::adicionar(Perfil* perfil) { if (quantidadeDePerfis<numeroMaximoDePerfis){ this->perfis[quantidadeDePerfis]= perfil; quantidadeDePerfis+= 1; return true; } return false; } Perfil::~Perfil() { }
  5. Olá, eu tenho uma dúvida. Estou fazendo um programa, uma rede social, eu montei uma função tela inicial, na qual a aplicação retorna para ela depois de ser selecionada uma tarefa. Por exemplo, cadastrar perfil. a aplicação funciona quando eu cadastro 1 perfil, no cadastro do 2 perfil aparece esse erro: Se alguém puder ajudar agradeço. terminate called after throwing an instance of 'std::bad_alloc' what(): std::bad_alloc se eu escrevo para deletar p1, perfil, o programa para e não volta a tela inicial. Em " telaInicio(r1)" Esse é parte do código: void telaInicio(RedeSocial* r1){ int opcaoinicio=0; int numeroper=0; string nomeper=""; string emailper=""; string respprofessor=""; (...) Perfil* p1= new Perfil(numeroper,nomeper,emailper); r1->adicionar(p1); r1->imprimir(); telaInicio(r1);

Sobre o Clube do Hardware

No ar desde 1996, o Clube do Hardware é uma das maiores, mais antigas e mais respeitadas comunidades sobre tecnologia do Brasil. Leia mais

Direitos autorais

Não permitimos a cópia ou reprodução do conteúdo do nosso site, fórum, newsletters e redes sociais, mesmo citando-se a fonte. Leia mais

×
×
  • Criar novo...

 

GRÁTIS: ebook Redes Wi-Fi – 2ª Edição

EBOOK GRÁTIS!

CLIQUE AQUI E BAIXE AGORA MESMO!