MigaMG93 Posted January 7, 2016 at 07:16 PM Report Share #591600 Posted January 7, 2016 at 07:16 PM (edited) Tenho uma classe jogador onde são escritos o nome dos jogadores cada vez que alguem quer jogar. Queria criar um vetor de 10 lugares que consoante alguem jogasse o seu nome fosse guardado no vetor...como faço? uma classe vetor ou faço uma classe onde crio o vetor la dentro? Jogador.h #pragma once #include <string.h> #include <iostream> #include "Tabuleiro.h" #include <ctype.h> #include "Pessoa.h" using namespace std; class Jogador : public Pessoa { private: char simbolo; int id; int JogosT; int vitorias; int vitorias2; int EXP; float MinutosJogo; public: Jogador(); friend ostream & operator <<(ostream &os, Jogador J); friend istream & operator >>(istream &is, Jogador &J); void SetSimbolo(char); char GetSimbolo() { return simbolo; } void Setid(int d) { id = d; } int Getid() { return id; } virtual void SetEXP(int y) { EXP = y; } virtual int GetEXP() { return EXP; } void Setjt(int s) { JogosT = s; } int Getjt() { return JogosT; } void SetMin(float r) { MinutosJogo = r; } float GetMin() { return MinutosJogo; } void Setvic(int a) { vitorias = a; } int Getvic() { return vitorias; } void Setvic2(int h) { vitorias2 = h; } int Getvic2() { return vitorias2; } void Random_Simbolo(); void Testar(); virtual bool Jogada(Tabuleiro *T); virtual void JogadaPC(Tabuleiro *T); ~Jogador(); }; Jogador.cpp #include "stdafx.h" #include "Jogador.h" #include "Ponto.h" #include "Tabuleiro.h" #include <sstream> Jogador::Jogador() { id = 0; JogosT = 0; vitorias = 0; vitorias2 = 0; MinutosJogo = 0; EXP = 0; } ostream & operator << (ostream &os, Jogador J) { cout << endl << "-Nome: " << J.GetNome() << endl; cout << "-Simbolo: " << J.GetSimbolo() << endl; return os; } istream & operator >> (istream &is, Jogador &J) { string aux; cout << endl << "Nome do jogador: "; getline(cin, aux); J.SetNome(aux); return is; } void Jogador::SetSimbolo(char a) { simbolo = a; } void Jogador::Testar(){ string g; cout << endl << "Nome do jogador: "; getline(cin, g); SetNome(g); } Edited January 7, 2016 at 07:19 PM by apocsantos Link to comment Share on other sites More sharing options...
HappyHippyHippo Posted January 7, 2016 at 07:19 PM Report Share #591601 Posted January 7, 2016 at 07:19 PM se tens uma classe jogador, essa classe será para guardar a informação de um único jogador se queres uma classe que guarda os jogadores, ao menos chama-a de "jogadores" se queres criar um vector com 10 lugares, cria um vector ... IRC : sim, é algo que ainda existe >> #p@p Portugol Plus Link to comment Share on other sites More sharing options...
MigaMG93 Posted January 7, 2016 at 07:22 PM Author Report Share #591602 Posted January 7, 2016 at 07:22 PM a minha ideia era criar uma classe vetor<string>jogadores e para cada nome inserido cada vez que alguem jogue guarde o nome dessa pessoa nesse tal vetor Link to comment Share on other sites More sharing options...
HappyHippyHippo Posted January 7, 2016 at 07:28 PM Report Share #591605 Posted January 7, 2016 at 07:28 PM para que criar uma classe para guardar um único vector ? IRC : sim, é algo que ainda existe >> #p@p Portugol Plus Link to comment Share on other sites More sharing options...
MigaMG93 Posted January 7, 2016 at 07:41 PM Author Report Share #591607 Posted January 7, 2016 at 07:41 PM era mais por uma questão de organização. aconselhas então a criar um vetor dentro da classe jogadores? istream & operator >> (istream &is, Jogador &J) { string aux; string jogadores; cout << endl << "Nome do jogador: "; getline(cin, aux); J.SetNome(aux); for (i=0, i<=9,i++) jogadores=aux return is ; } Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now