errors with operand "!=" ???

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • vtuning
    New Member
    • Jul 2010
    • 5

    errors with operand "!=" ???

    Hi, i'm doing a project in Visual C++....in Portuguese....i 'm hoping you can help figure out the problem eventhough it's not in english...

    here is the whole code....incompl ete in the int main and it's missing some functions but i wanted to solve this errors before i keep going

    Class.h
    Code:
    class CNoFila{
      public:
    	int evento;
    	int tempo;
    	int numcliente;
    	int numlugar;
    	int tempochegada;
    	CNoFila *Proximo;
    };
    
    
    
    class CFilaLavagem{
    	CNoFila *InicioLav;
        CNoFila *FimLav;
      public:
    	CFilaLavagem(void);                      //constructor por defeito
    	~CFilaLavagem(void);                 //Destructor
    	friend class CFilaEstacionamento;
    	void ApagaItemLav(int numcliente);
    	int lugareslavagem(void);
    	friend bool spot(int n1, int tempo, int evento, int &carrosout, int numcliente, int numlugar, int tempochegada);
    	void EstacParaLavagem(CNoFila &L);
    	void InsereItemLav(int evento, int tempo, int numcliente, int tempochegada);
    	int NumLugarLav(int n1);
    	friend void Simulacao(CNoFila &Actual, int &t, int n1, int &carrosout, int n2);
    };
    
    
    class CFilaEstacionamento{
    	
      public:
    	CNoFila *InicioEstac;
        CNoFila *FimEstac;
    	CFilaEstacionamento();                      //constructor por defeito
    	CFilaEstacionamento(const CNoFila & L);
    	~CFilaEstacionamento(void);                 //Destructor
    
    	void ApagaItemEstac(void);
    	int lugaresestacionamento(void);
    	friend bool spot(int n1, int tempo, int evento, int &carrosout, int numcliente, int numlugar, int tempochegada);
    	friend class CFilaLavagem;
    	void InsereItemEstac(int evento, int tempo, int numcliente, int tempochegada);
    	int NumLugarEstac(int n1);
    	friend void Simulacao(CNoFila &Actual, int &t, int n1, int &carrosout, int n2);
    };
    
    class CFilaPrincipal{
    	
    public:
    	CNoFila *Inicio;
        CNoFila *Fim;
    	void InsereNoPrincipal(int evento, int numcliente, int tempchegada);
    	friend void Simulacao(CNoFila &Actual, int &t, int n1, int &carrosout, int n2);
    
    
    };
    Class.cpp:

    Code:
    #include <iostream>
    #include "Class.h"
    
    //CFilaLavagem
    
    void CFilaLavagem::ApagaItemLav(int numcliente)
    {
    	CNoFila	*Actual = InicioLav;
    	CNoFila *Anterior;
    	if (InicioLav == NULL) return;
    
    	else{
    		while(Actual!=NULL){
    			if(Actual->numcliente == numcliente){
    				if(Anterior ==NULL){
    					InicioLav = Actual->Proximo;
    				}
    				else{
    					Anterior->Proximo = Actual->Proximo;
    				}
    				delete (Actual);
    				return;
    			}
    			Anterior = Actual;
    			Actual=Actual->Proximo;
    		}
    		if (InicioLav ==NULL) FimLav = NULL;
    	}
    
    }
    CFilaLavagem::CFilaLavagem(void)
    {
    
    	InicioLav = FimLav = NULL;
    
    }
    
    CFilaLavagem::~CFilaLavagem(void)
    {
    
    	delete this;
    
    }
    
    
    int CFilaLavagem::lugareslavagem(void)
    {
    	int lavagem = 0;
    	CNoFila *Actual = InicioLav;
    	
    	if (Actual==NULL) return 0;
    	else{
    		while(Actual!=NULL)
    		{
    			lavagem++;
    			Actual = Actual->Proximo;
    		}
    	}
    	return (lavagem);
    
    }
    
    
    
    
    void CFilaLavagem::EstacParaLavagem(CNoFila &L)
    {
    
    	CNoFila *Novo = new CNoFila;
    	
    	Novo->evento = L.evento;
    	Novo->tempo = L.tempo;
    	Novo->tempochegada = L.tempochegada;
    	Novo->numcliente = L.numcliente;
    
    	Novo->Proximo=NULL;
    	if( InicioLav == NULL ) InicioLav = Novo;  
    	else{
    		FimLav->Proximo = Novo; 
    	}
    	
    	FimLav = Novo;
    	
    
    }
    
    void CFilaLavagem::InsereItemLav(int evento, int tempo,int numcliente, int tempochegada)
    {
    
    	CNoFila *Novo = new CNoFila;
    	
    	Novo->evento =evento;
    	Novo->tempo = tempo;
    	Novo->tempochegada = tempochegada;
    	Novo->numcliente = numcliente;
    	Novo->Proximo=NULL;
    	if( InicioLav == NULL ) InicioLav = Novo;  
    	else{
    		FimLav->Proximo = Novo; 
    	}
    	
    	FimLav = Novo;
    }
    
    int NumLugarLav(int n1){
    int numlugar;
    
    return numlugar;
    }
    
    //CFilaEstacionamento
    
    CFilaEstacionamento::~CFilaEstacionamento()
    {
    
    	delete this;
    
    }
    
    CFilaEstacionamento::CFilaEstacionamento()
    {
    
    	InicioEstac = FimEstac = NULL;
    
    }
    
    int CFilaEstacionamento::lugaresestacionamento(void)
    {
    	int estac = 0;
    	CNoFila *Actual = InicioEstac;
    	
    	if (Actual==NULL) return 0;
    	else{
    		while(Actual!=NULL)
    		{
    			estac++;
    			Actual = Actual->Proximo;
    		}
    	}
    	return (estac);
    }
    
    
    
    void CFilaEstacionamento::InsereItemEstac(int evento, int tempo, int numcliente, int tempochegada) {
    	
    	CNoFila *Novo = new CNoFila;
    	
    	Novo->evento = evento;
    	Novo->tempo = tempo;
    	Novo->tempochegada = tempochegada;
    	Novo->numcliente = numcliente;
    	Novo->Proximo=NULL;
    	if( InicioEstac == NULL ) InicioEstac = Novo;  
    	else{
    		FimEstac->Proximo = Novo; 
    	}
    	
    	FimEstac = Novo;
    }
    
    void CFilaEstacionamento::ApagaItemEstac(void)
    {
    	CNoFila *Aux;
    
    	if (InicioEstac == NULL) return;
    
    	else{
    
    		Aux = InicioEstac;
    		InicioEstac = Aux->Proximo;
    		delete Aux;
    
    		if (InicioEstac ==NULL) FimEstac = NULL;
    	}
    
    }
    
    int NumLugarEstac(int n1){
    	int numlugar;
    
    return numlugar;
    }
    
    
    //CFilaPrincipal
    
    void CFilaPrincipal::InsereNoPrincipal(int evento, int numcliente, int tempochegada){
    
    
    	CNoFila *Novo = new CNoFila;
    	
    	Novo->evento = evento;
    	Novo->tempochegada = tempochegada;
    	Novo->numcliente = numcliente;
    	Novo->Proximo=NULL;
    
    	if( Inicio == NULL ) Inicio = Novo;  
    	else{
    		Fim->Proximo = Novo; 
    	}
    	
    	Fim = Novo;
    }


    main.cpp:

    Code:
    #include <iostream>
    #include "Class.h"
    #include <fstream>
    CFilaLavagem C1;
    CFilaEstacionamento C2;
    CFilaPrincipal C3;
    
    using namespace std;
    
    
    
    void Imprime(int numerocarro, int numlugar, int situacao, int tempo);
    
    
    void Simulacao(CNoFila &Actual, int &t, int n1, int &carrosout, int n2)
    {
    
    	while( (Actual != NULL) && (t < n2)){
    
    
    		CNoFila *Aux;
    		cout << "Chegada de um carro";
    		for (int i = 0; i < Actual.tempochegada; i++){
    
    		}
    
    		t = t + Actual.tempochegada;
    		//falta determinar lugar memo
    		bool lugar = spot(n1, Actual.tempo, Actual.evento, carrosout, Actual.numcliente, Actual.numlugar, Actual.tempochegada);
    
    		*Aux = Actual;
    
    		if (lugar == 1){
    			for (int j = 0; j < Aux->tempo; j++){
    				Actual = Actual.Proximo;
    
    				Simulacao(Actual, t, n1, carrosout, n2);
    
    				t +=Aux->tempo;
    			}
    		}
    	}
    }
    
    bool spot(int n1, int tempo, int evento, int &carrosout, int numcliente, int numlugar, int tempochegada)
    {
    
    	
    	CNoFila *Aux = C2.InicioEstac;
    
    	int lugaresestac= 2 * (8-n1);
    	int lavagemocupado = C1.lugareslavagem();
    	int estacocupado = C2.lugaresestacionamento();
    
    	if (lavagemocupado < n1){
    		if (estacocupado ==0){
    			C1.InsereItemLav(evento, tempo, numcliente, tempochegada);
    			Imprime(numcliente, numlugar, 0, tempo);
    			return 1;
    		}
    
    		else {
    			C1.EstacParaLavagem(*C2.InicioEstac);
    			Imprime(Aux->numcliente, Aux->numlugar, 3, Aux->tempo);
    			C2.InsereItemEstac(evento, tempo, numcliente, tempochegada);
    			Imprime(numcliente, numlugar, 1, tempo);
    			return 0;
    		}
    	}
    
    	if (lavagemocupado == n1){
    		if (estacocupado < lugaresestac){
    			C2.InsereItemEstac(evento, tempo, numcliente, tempochegada);
    			Imprime(numcliente, numlugar, 1, tempo);
    			return 0;
    		}
    		
    		else{
    			carrosout++;
    			Imprime(numcliente, numlugar, 2, tempo);
    			return 0;
    		}
    
    
    	}
    	return 0;
    
    }
    
    
    void Imprime(int numerocarro, int numlugar, int situacao, int tempo){
    
    	float hora = tempo/3600;
    	float minuto = (hora - (int)hora)*60;
    	float segundo = (minuto - (int)minuto)*60;
    
    	
    	
    	ofstream fout;
    	
    	fout.open("Registo.txt");
    	
    	switch (situacao){
    	case 0: fout << hora << ":" << minuto << ":" << segundo << " - Chegada de um novo cliente (#" << numerocarro << "). Ocupa o lugar de lavagem #" << numlugar << ". Executa a opcao escolhida." << endl; 
    	break;
    	case 1: fout << hora << ":" << minuto << ":" << segundo << " - Chegada de um novo cliente (#" << numerocarro << "). Ocupa o lugar de estacionamento #" << numlugar << ". Aguarda a sua vez." << endl;
    	break;
    	case 2: fout << hora << ":" << minuto << ":" << segundo << " - Chegada de um novo cliente (#" << numerocarro << "). Os lugares estao todos ocupados e o carro vai-se embora" << endl;
    	break;
    	case 3: fout << hora << ":" << minuto << ":" << segundo << " - O cliente #" << numerocarro << " que se encontrava no estacionamento desloca-se para o lugar de lavagem #" << numlugar << endl; 
    	}
    
    	fout.close();
    	
    }
    
    
    
    
    int TempoEvento(int evento, int n4, int m4, int n5, int m5, int n6, int m6){
    	
    	int tempototal;
    	
    	if (evento == 1){
    		tempototal = (rand()%(n4+m4+1)) + (n4-m4-2);
    	}
    
    	if (evento == 2){
    		tempototal = ((rand()%(n5+m5+1)) + (n5-m5-2))+((rand()%(n4+m4+1)) + (n4-m4-2));
    	}
    
    	if (evento == 3){
    		tempototal = ((rand()%(n6+m6+1)) + (n6-m6-2)) + ((rand()%(n5+m5+1)) + (n5-m5-2))+((rand()%(n4+m4+1)) + (n4-m4-2));
    	}
    
    	return tempototal;
    }
    
    int main()
    {
    	//DECLARAÇÃO
    
    	CNoFila *Actual;
    
    	int n3, m3, n4, m4, n5, m5, n6, m6;
    	int n1,n2, numtotalclientes, numcliente = 1;
    
    	//=======================================================
    
    	//VALORES PEDIDOS AO UTILIZADOR
    
    	do{
    	cout << "Introduza o numero de zonas de lavagem a simular(1 a 8): ";
    	cin >> n1;
    	}while(1 > n1 && n1 > 8);
    
    	do{
    	cout << "Introduza tempo TOTAL de simulacao: ";
    	cin >> n2;
    	}while(1 > n2);
    
    	do{
    	cout << "Introduza valores de n3 e m3 (INTERVALO-chegada de novo cliente): ";
    	cout<< "n3:"; cin >> n3;
    	cout<< "m3:"; cin >> m3;
    	}while(1 > n3 && m3 < 1);
    	
    	do{
    	cout << "Introduza valores de n4 e m4 (INTERVALO-lavagem do carro): ";
    	cout<< "n4:"; cin >> n4;
    	cout<< "m4:"; cin >> m4;
    	}while(1 > n4 && m4 < 1);
    	
    	do{
    	cout << "Introduza valores de n5 e m5 (INTERVALO-aspiração do carro): ";
    	cout<< "n5:"; cin >> n5;
    	cout<< "m5:"; cin >> m5;
    	}while(1 > n5 && m5 < 1);
    
    	do{
    	cout << "Introduza valores de n5 e m5 (INTERVALO-polimento do carro): ";
    	cout<< "n6:"; cin >> n6;
    	cout<< "m6:"; cin >> m6;
    	}while(1 > n6 && m6 < 1);
    
    	cout << "\nO numero total de lugares de estacionamento e': " << 2 * (8-n1) << endl;
    
    	cout << "Introduza o numero total de clientes do estabelecimento: ";
    	cin >> numtotalclientes;
    
    	//===========================================================
    
    	for( int i=0; i < numtotalclientes; i++){
    
    		int evento = rand()% 2;
    		evento++;
    		int tempchegada = (rand()%(n3+m3+1)) + (n3-m3-2);
    		C3.InsereNoPrincipal(evento, numcliente, tempchegada);
    
    
    		numcliente++;
    	}
    
    	//===========================================================
    
    	for(int j = 0; j < numtotalclientes; j++){
    
    		Actual = C3.Inicio;
    
    		int t2 = TempoEvento(Actual->evento, n4, m4, n5, m5, n6, m6);
    
    		Actual->tempo = t2;
    
    		Actual = Actual->Proximo;
    	}
    
    		
    	cout << "Comecando a Simulacao!" << endl;
    
    	int t = 0;// memo
    
    	return 0;
    }

    these are the errors:

    1>c:\users\tiag o\documents\vis ual studio 2008\projects\p rojectoeda\proj ectoeda\main.cp p(18) : error C2784: 'bool std::operator !=(const std::istreambuf _iterator<_Elem ,_Traits> &,const std::istreambuf _iterator<_Elem ,_Traits> &)' : could not deduce template argument for 'const std::istreambuf _iterator<_Elem ,_Traits> &' from 'CNoFila'
    1> c:\program files (x86)\microsoft visual studio 9.0\vc\include\ streambuf(557) : see declaration of 'std::operator !='
    1>c:\users\tiag o\documents\vis ual studio 2008\projects\p rojectoeda\proj ectoeda\main.cp p(18) : error C2784: 'bool std::operator !=(const std::allocator< _Ty> &,const std::allocator< _Other> &) throw()' : could not deduce template argument for 'const std::allocator< _Ty> &' from 'CNoFila'
    1> c:\program files (x86)\microsoft visual studio 9.0\vc\include\ xmemory(180) : see declaration of 'std::operator !='
    1>c:\users\tiag o\documents\vis ual studio 2008\projects\p rojectoeda\proj ectoeda\main.cp p(18) : error C2784: 'bool std::operator !=(const std::reverse_it erator<_RanIt> &,const std::reverse_it erator<_RanIt2> &)' : could not deduce template argument for 'const std::reverse_it erator<_RanIt> &' from 'CNoFila'
    1> c:\program files (x86)\microsoft visual studio 9.0\vc\include\ xutility(2254) : see declaration of 'std::operator !='
    1>c:\users\tiag o\documents\vis ual studio 2008\projects\p rojectoeda\proj ectoeda\main.cp p(18) : error C2784: 'bool std::operator !=(const std::_Revranit< _RanIt,_Base> &,const std::_Revranit< _RanIt2,_Base2> &)' : could not deduce template argument for 'const std::_Revranit< _RanIt,_Base> &' from 'CNoFila'
    1> c:\program files (x86)\microsoft visual studio 9.0\vc\include\ xutility(2061) : see declaration of 'std::operator !='
    1>c:\users\tiag o\documents\vis ual studio 2008\projects\p rojectoeda\proj ectoeda\main.cp p(18) : error C2784: 'bool std::operator !=(const std::pair<_Ty1, _Ty2> &,const std::pair<_Ty1, _Ty2> &)' : could not deduce template argument for 'const std::pair<_Ty1, _Ty2> &' from 'CNoFila'
    1> c:\program files (x86)\microsoft visual studio 9.0\vc\include\ utility(91) : see declaration of 'std::operator !='
    1>c:\users\tiag o\documents\vis ual studio 2008\projects\p rojectoeda\proj ectoeda\main.cp p(18) : error C2676: binary '!=' : 'CNoFila' does not define this operator or a conversion to a type acceptable to the predefined operator
    1>c:\users\tiag o\documents\vis ual studio 2008\projects\p rojectoeda\proj ectoeda\main.cp p(18) : fatal error C1903: unable to recover from previous error(s); stopping compilation


    Can anyone help me fix this errors??

    thanks for any help
  • Oralloy
    Recognized Expert Contributor
    • Jun 2010
    • 988

    #2
    Line 18 is failing to compile because you're passing Actual to the method by reference, and not by address.

    How do you intend the function Simulacao(...) to be used?

    Comment

    • vtuning
      New Member
      • Jul 2010
      • 5

      #3
      The function Simulation() should receive a pointer Actual to one member of a list and by recursion go through the entire list calling itself with Actual being the next member of the list using this line:
      Actual = Actual.Proximo;

      wich is like:
      Actual = Actual.Next;

      so when the function reaches the end of the list, it would stop, being the pointer Actual = NULL

      PS:sword117 o problema tambem acho que esta na variavel mas nao estou a ver bem como passa la a funcao, pois estou acostumado a passar assim os nos, e respondi em ingles para todos perceberem :)

      Comment

      • vtuning
        New Member
        • Jul 2010
        • 5

        #4
        i was able to fix some errors.....

        now there is only one and i don't get it.....

        function Simulacao():

        Code:
        void Simulacao(CNoFila &L, int &t, int n1, int &carrosout, int n2)
        {
        	CNoFila *Actual;
        	Actual = &L;
        
        	while( (Actual != NULL) && (t < n2)){
        
        
        		CNoFila *Aux;
        		cout << "Chegada de um carro";
        		for (int i = 0; i < Actual->tempochegada; i++){
        
        		}
        
        		t = t + Actual->tempochegada;
        		//falta determinar lugar memo
        		bool lugar = spot(n1, Actual->tempo, Actual->evento, carrosout, Actual->numcliente, Actual->numlugar, Actual->tempochegada);
        
        		*Aux = Actual;
        
        		if (lugar == 1){
        			for (int j = 0; j < Aux->tempo; j++){
        				Actual = Actual->Proximo;
        
        				Simulacao(*Actual, t, n1, carrosout, n2);
        
        				t +=Aux->tempo;
        			}
        		}
        	}
        }
        error:

        1>c:\users\tiag o\documents\vis ual studio 2008\projects\p rojectoeda\proj ectoeda\main.cp p(33) : error C2679: binary '=' : no operator found which takes a right-hand operand of type 'CNoFila *' (or there is no acceptable conversion)
        1> c:\users\tiago\ documents\visua l studio 2008\projects\p rojectoeda\proj ectoeda\class.h (9): could be 'CNoFila &CNoFila::opera tor =(const CNoFila &)'
        1> while trying to match the argument list '(CNoFila, CNoFila *)'

        Comment

        • Banfa
          Recognized Expert Expert
          • Feb 2006
          • 9067

          #5
          Line 19 of the posted listing. Aux and Actual have the same type, CNoFila * so there is no need to dereference Aux while assigning to it.

          Comment

          • vtuning
            New Member
            • Jul 2010
            • 5

            #6
            yeah that fixed it!!!

            well e continued the solution and came across this errors....but i cant see how to solve....i get the errors(:S) but i'm kind of stuck here

            Class.h:

            Code:
            class CNoFila{
              public:
            	int evento;
            	int tempo;
            	int numcliente;
            	int numlugar;
            	int tempochegada;
            	CNoFila *Proximo;
            };
            
            
            
            class CFilaLavagem{
            	
              public:
            	CNoFila *InicioLav;
                CNoFila *FimLav;
            	CFilaLavagem(void);                      //constructor por defeito
            	~CFilaLavagem(void);                 //Destructor
            	friend class CFilaEstacionamento;
            	void ApagaItemLav(int numcliente);
            	int lugareslavagem(void);
            	friend bool spot(int n1, int tempo, int evento, int &carrosout, int numcliente, int numlugar, int tempochegada);
            	void EstacParaLavagem(CNoFila &L);
            	void InsereItemLav(int evento, int tempo, int numcliente, int tempochegada, int numlugar);
            	int NumLugarLav(int n1, CNoFila &L);
            	friend void Simulacao(CNoFila &L, int &t, int n1, int &carrosout, int n2);
            };
            
            
            class CFilaEstacionamento{
            	
              public:
            	CNoFila *InicioEstac;
                CNoFila *FimEstac;
            	CFilaEstacionamento();                      //constructor por defeito
            	CFilaEstacionamento(const CNoFila & L);
            	~CFilaEstacionamento(void);                 //Destructor
            
            	void ApagaItemEstac(void);
            	int lugaresestacionamento(void);
            	friend bool spot(int n1, int tempo, int evento, int &carrosout, int numcliente, int numlugar, int tempochegada);
            	friend class CFilaLavagem;
            	void InsereItemEstac(int evento, int tempo, int numcliente, int tempochegada, int numlugar);
            	int NumLugarEstac(int n1, CNoFila *InicioEstac);
            	friend void Simulacao(CNoFila &L, int &t, int n1, int &carrosout, int n2);
            };
            
            class CFilaPrincipal{
            	
            public:
            	CNoFila *Inicio;
                CNoFila *Fim;
            	void InsereNoPrincipal(int evento, int numcliente, int tempchegada);
            	friend void Simulacao(CNoFila &Actual, int &t, int n1, int &carrosout, int n2);
            
            
            };
            Class.cpp:

            Code:
            #include <iostream>
            #include "Class.h"
            
            //CFilaLavagem
            
            void CFilaLavagem::ApagaItemLav(int numcliente)
            {
            	CNoFila	*Actual = InicioLav;
            	CNoFila *Anterior;
            	if (InicioLav == NULL) return;
            
            	else{
            		while(Actual!=NULL){
            			if(Actual->numcliente == numcliente){
            				if(Anterior ==NULL){
            					InicioLav = Actual->Proximo;
            				}
            				else{
            					Anterior->Proximo = Actual->Proximo;
            				}
            				delete (Actual);
            				return;
            			}
            			Anterior = Actual;
            			Actual=Actual->Proximo;
            		}
            		if (InicioLav ==NULL) FimLav = NULL;
            	}
            
            }
            CFilaLavagem::CFilaLavagem(void)
            {
            
            	InicioLav = FimLav = NULL;
            
            }
            
            CFilaLavagem::~CFilaLavagem(void)
            {
            
            	delete this;
            
            }
            
            
            int CFilaLavagem::lugareslavagem(void)
            {
            	int lavagem = 0;
            	CNoFila *Actual = InicioLav;
            	
            	if (Actual==NULL) return 0;
            	else{
            		while(Actual!=NULL)
            		{
            			lavagem++;
            			Actual = Actual->Proximo;
            		}
            	}
            	return (lavagem);
            
            }
            
            
            
            
            void CFilaLavagem::EstacParaLavagem(CNoFila &L)
            {
            
            	CNoFila *Novo = new CNoFila;
            	
            	Novo->evento = L.evento;
            	Novo->tempo = L.tempo;
            	Novo->tempochegada = L.tempochegada;
            	Novo->numcliente = L.numcliente;
            	Novo->numlugar = L.numlugar;
            
            	Novo->Proximo=NULL;
            	if( InicioLav == NULL ) InicioLav = Novo;  
            	else{
            		FimLav->Proximo = Novo; 
            	}
            	
            	FimLav = Novo;
            	
            
            }
            
            void CFilaLavagem::InsereItemLav(int evento, int tempo,int numcliente, int tempochegada, int numlugar)
            {
            
            	CNoFila *Novo = new CNoFila;
            	
            	Novo->evento =evento;
            	Novo->tempo = tempo;
            	Novo->tempochegada = tempochegada;
            	Novo->numcliente = numcliente;
            	Novo->numlugar = numlugar;
            	Novo->Proximo=NULL;
            	if( InicioLav == NULL ) InicioLav = Novo;  
            	else{
            		FimLav->Proximo = Novo; 
            	}
            	
            	FimLav = Novo;
            }
            
            int NumLugarLav(int n1, CNoFila &L){
            	
            	
            	int tabaux[8];
            	CNoFila *Actual;
            	Actual = &L;
            	int lugar;
            
            	for (int i = 0; i < n1; i++){
            
            		tabaux[i] = Actual->numlugar;
            		Actual = Actual->Proximo;
            	}
            	
            	for (int i = 0; i < n1; i++){
            		
            		if(tabaux[i]==1) continue;
            		else { 
            			lugar=1;
            			break;
            		} 
            		
            		if(tabaux[i]==2) continue;
            		else { 
            			lugar=2;
            			break;
            		}
            
            		if(tabaux[i]==3) continue;
            		else { 
            			lugar=3;
            			break;
            		}
            
            		if(tabaux[i]==4) continue;
            		else { 
            			lugar=4;
            			break;
            		}
            
            		if(tabaux[i]==5) continue;
            		else { 
            			lugar=5;
            			break;
            		}
            
            		if(tabaux[i]==6) continue;
            		else { 
            			lugar=6;
            			break;
            		}
            
            		if(tabaux[i]==7) continue;
            		else { 
            			lugar=7;
            			break;
            		}
            
            		if(tabaux[i]==8) continue;
            		else { 
            			lugar=8;
            			break;
            		}
            	}
            	return lugar;
            
            }
            
            //CFilaEstacionamento
            
            CFilaEstacionamento::~CFilaEstacionamento()
            {
            
            	delete this;
            
            }
            
            CFilaEstacionamento::CFilaEstacionamento()
            {
            
            	InicioEstac = FimEstac = NULL;
            
            }
            
            int CFilaEstacionamento::lugaresestacionamento(void)
            {
            	int estac = 0;
            	CNoFila *Actual = InicioEstac;
            	
            	if (Actual==NULL) return 0;
            	else{
            		while(Actual!=NULL)
            		{
            			estac++;
            			Actual = Actual->Proximo;
            		}
            	}
            	return (estac);
            }
            
            
            
            void CFilaEstacionamento::InsereItemEstac(int evento, int tempo, int numcliente, int tempochegada, int numlugar) {
            	
            	CNoFila *Novo = new CNoFila;
            	
            	Novo->evento = evento;
            	Novo->tempo = tempo;
            	Novo->tempochegada = tempochegada;
            	Novo->numcliente = numcliente;
            	Novo->numlugar = numlugar;
            	Novo->Proximo=NULL;
            	if( InicioEstac == NULL ) InicioEstac = Novo;  
            	else{
            		FimEstac->Proximo = Novo; 
            	}
            	
            	FimEstac = Novo;
            }
            
            void CFilaEstacionamento::ApagaItemEstac(void)
            {
            	CNoFila *Aux;
            
            	if (InicioEstac == NULL) return;
            
            	else{
            
            		Aux = InicioEstac;
            		InicioEstac = Aux->Proximo;
            		delete Aux;
            
            		if (InicioEstac ==NULL) FimEstac = NULL;
            	}
            
            }
            
            int NumLugarEstac(int n1,CNoFila *InicioEstac){
            	
            	int tabaux[14];
            	
            	
            	CNoFila *Actual;
            	Actual = InicioEstac;
            
            	for (int i = 0; i < 2 * (8-n1); i++){
            
            		tabaux[i] = Actual->numlugar;
            		Actual = Actual->Proximo;
            	}
            	
            	for (int i = 0; i < 2 * (8-n1); i++){
            		
            		if(tabaux[i]!=1) return 1;
            		else { 
            	
            			if(tabaux[i]!=2) return 2;
            			else { 
            		
            				if(tabaux[i]!=3) return 3;
            				else { 
            			
            
            					if(tabaux[i]!=4) return 4;
            					else { 
            			
            						if(tabaux[i]!=5) return 5;
            						else { 
            			
            
            							if(tabaux[i]!=6) return 6;
            							else { 
            							
            
            								if(tabaux[i]!=7) return 7;
            								else { 
            			
            
            									if(tabaux[i]!=8) return 8;
            									else { 
            										
            										if(tabaux[i]!=9) return 9;
            										else { 
            											
            											if(tabaux[i]!=10) return 10;
            											else { 
            												
            												if(tabaux[i]!=11) return 11;
            												else { 
            													
            													if(tabaux[i]!=12) return 12;
            													else { 
            															
            														if(tabaux[i]!=13) return 13;
            														else { 
            
            																if(tabaux[i]!=14) return 14;
            														}
            													}
            												}
            											}
            										}
            									}
            								}
            							}
            						}
            					}
            				}
            			}
            		}
            
            		
            	}
            	
            
            }
            
            //CFilaPrincipal
            
            void CFilaPrincipal::InsereNoPrincipal(int evento, int numcliente, int tempochegada){
            
            
            	CNoFila *Novo = new CNoFila;
            	
            	Novo->evento = evento;
            	Novo->tempochegada = tempochegada;
            	Novo->numcliente = numcliente;
            	Novo->Proximo=NULL;
            
            	if( Inicio == NULL ) Inicio = Novo;  
            	else{
            		Fim->Proximo = Novo; 
            	}
            	
            	Fim = Novo;
            }

            main.cpp:

            Code:
            #include <iostream>
            #include "Class.h"
            #include <fstream>
            CFilaLavagem C1;
            CFilaEstacionamento C2;
            CFilaPrincipal C3;
            
            using namespace std;
            
            
            
            void Imprime(int numerocarro, int numlugar, int situacao, int tempo);
            
            
            void Simulacao(CNoFila &L, int &t, int n1, int &carrosout, int n2)
            {
            	CNoFila *Actual;
            	Actual = &L;
            
            	while( (Actual != NULL) && (t < n2)){
            
            
            		CNoFila *Aux;
            		cout << "Chegada de um carro";
            		for (int i = 0; i < Actual->tempochegada; i++){
            
            		}
            
            		t = t + Actual->tempochegada;
            		//falta determinar lugar memo
            		bool lugar = spot(n1, Actual->tempo, Actual->evento, carrosout, Actual->numcliente, Actual->numlugar, Actual->tempochegada);
            
            		Aux = Actual;
            
            		if (lugar == 1){
            			for (int j = 0; j < Aux->tempo; j++){
            				Actual = Actual->Proximo;
            
            				Simulacao(*Actual, t, n1, carrosout, n2);
            
            				t +=Aux->tempo;
            			}
            		}
            	}
            }
            
            bool spot(int n1, int tempo, int evento, int &carrosout, int numcliente, int tempochegada)
            {
            
            	
            	CNoFila *Aux = C2.InicioEstac;
            	int numlugar1, numlugar2;
            	int lugaresestac= (2 * (8-n1));
            	int lavagemocupado = C1.lugareslavagem();
            	int estacocupado = C2.lugaresestacionamento();
            
            
            	if (lavagemocupado == 0){
            		numlugar1 = 1;
            		C1.InsereItemLav(evento, tempo, numcliente, tempochegada, numlugar1);
            	}
            	if ((lavagemocupado < n1) && (lavagemocupado > 0)){
            		if (estacocupado ==0){
            			numlugar1 = C1.NumLugarLav(n1,*C1.InicioLav);
            			C1.InsereItemLav(evento, tempo, numcliente, tempochegada, numlugar1);
            			
            			Imprime(numcliente, numlugar1, 0, tempo);
            			return 1;
            		}
            
            		else {
            			C1.EstacParaLavagem(*C2.InicioEstac);
            			numlugar2 = C2.NumLugarEstac(n1,*C2.InicioEstac);
            			numlugar1 = C1.NumLugarLav(n1,*C1.InicioLav);
            			Imprime(Aux->numcliente, Aux->numlugar, 3, Aux->tempo);
            			
            			C2.InsereItemEstac(evento, tempo, numcliente, tempochegada, numlugar2);
            			Imprime(numcliente, numlugar2, 1, tempo);
            			return 0;
            		}
            	}
            
            	if (lavagemocupado == n1){
            		if (estacocupado < lugaresestac){
            			numlugar2 = C2.NumLugarEstac(n1,*C2.InicioEstac);
            			C2.InsereItemEstac(evento, tempo, numcliente, tempochegada, numlugar2);
            			Imprime(numcliente, numlugar2, 1, tempo);
            			return 0;
            		}
            		
            		else{
            			carrosout++;
            			int numlugar = 0;
            			Imprime(numcliente, numlugar, 2, tempo);
            			return 0;
            		}
            
            
            	}
            	return 0;
            
            }
            
            
            void Imprime(int numerocarro, int numlugar, int situacao, int tempo){
            
            	float hora = tempo/3600;
            	float minuto = (hora - (int)hora)*60;
            	float segundo = (minuto - (int)minuto)*60;
            
            	
            	
            	ofstream fout;
            	
            	fout.open("Registo.txt");
            	
            	switch (situacao){
            	case 0: fout << hora << ":" << minuto << ":" << segundo << " - Chegada de um novo cliente (#" << numerocarro << "). Ocupa o lugar de lavagem #" << numlugar << ". Executa a opcao escolhida." << endl; 
            	break;
            	case 1: fout << hora << ":" << minuto << ":" << segundo << " - Chegada de um novo cliente (#" << numerocarro << "). Ocupa o lugar de estacionamento #" << numlugar << ". Aguarda a sua vez." << endl;
            	break;
            	case 2: fout << hora << ":" << minuto << ":" << segundo << " - Chegada de um novo cliente (#" << numerocarro << "). Os lugares estao todos ocupados e o carro vai-se embora" << endl;
            	break;
            	case 3: fout << hora << ":" << minuto << ":" << segundo << " - O cliente #" << numerocarro << " que se encontrava no estacionamento desloca-se para o lugar de lavagem #" << numlugar << endl; 
            	}
            
            	fout.close();
            	
            }
            
            
            
            
            int TempoEvento(int evento, int n4, int m4, int n5, int m5, int n6, int m6){
            	
            	int tempototal;
            	
            	if (evento == 1){
            		tempototal = (rand()%(n4+m4+1)) + (n4-m4-2);
            	}
            
            	if (evento == 2){
            		tempototal = ((rand()%(n5+m5+1)) + (n5-m5-2))+((rand()%(n4+m4+1)) + (n4-m4-2));
            	}
            
            	if (evento == 3){
            		tempototal = ((rand()%(n6+m6+1)) + (n6-m6-2)) + ((rand()%(n5+m5+1)) + (n5-m5-2))+((rand()%(n4+m4+1)) + (n4-m4-2));
            	}
            
            	return tempototal;
            }
            
            int main()
            {
            	//DECLARAÇÃO
            
            	CNoFila *Actual;
            
            	int n3, m3, n4, m4, n5, m5, n6, m6;
            	int n1,n2, numtotalclientes, numcliente = 1;
            
            	//=======================================================
            
            	//VALORES PEDIDOS AO UTILIZADOR
            
            	do{
            	cout << "Introduza o numero de zonas de lavagem a simular(1 a 8): ";
            	cin >> n1;
            	}while(1 > n1 && n1 > 8);
            
            	do{
            	cout << "Introduza tempo TOTAL de simulacao: ";
            	cin >> n2;
            	}while(1 > n2);
            
            	do{
            	cout << "Introduza valores de n3 e m3 (INTERVALO-chegada de novo cliente): ";
            	cout<< "n3:"; cin >> n3;
            	cout<< "m3:"; cin >> m3;
            	}while(1 > n3 && m3 < 1);
            	
            	do{
            	cout << "Introduza valores de n4 e m4 (INTERVALO-lavagem do carro): ";
            	cout<< "n4:"; cin >> n4;
            	cout<< "m4:"; cin >> m4;
            	}while(1 > n4 && m4 < 1);
            	
            	do{
            	cout << "Introduza valores de n5 e m5 (INTERVALO-aspiração do carro): ";
            	cout<< "n5:"; cin >> n5;
            	cout<< "m5:"; cin >> m5;
            	}while(1 > n5 && m5 < 1);
            
            	do{
            	cout << "Introduza valores de n5 e m5 (INTERVALO-polimento do carro): ";
            	cout<< "n6:"; cin >> n6;
            	cout<< "m6:"; cin >> m6;
            	}while(1 > n6 && m6 < 1);
            
            	cout << "\nO numero total de lugares de estacionamento e': " << 2 * (8-n1) << endl;
            
            	cout << "Introduza o numero total de clientes do estabelecimento: ";
            	cin >> numtotalclientes;
            
            	//===========================================================
            
            	for( int i=0; i < numtotalclientes; i++){
            
            		int evento = rand()% 2;
            		evento++;
            		int tempchegada = (rand()%(n3+m3+1)) + (n3-m3-2);
            		C3.InsereNoPrincipal(evento, numcliente, tempchegada);
            
            
            		numcliente++;
            	}
            
            	//===========================================================
            
            	for(int j = 0; j < numtotalclientes; j++){
            
            		Actual = C3.Inicio;
            
            		int t2 = TempoEvento(Actual->evento, n4, m4, n5, m5, n6, m6);
            
            		Actual->tempo = t2;
            
            		Actual = Actual->Proximo;
            	}
            
            		
            	cout << "Comecando a Simulacao!" << endl;
            
            	int t = 0;// memo
            	int carrosout;
            	Simulacao(*C3.Inicio, t, n1, carrosout, n2);
            
            	cout << "\nO numero de carros que abandonaram sem executar qualquer accao foi: " << carrosout << endl; 
            
            	
            
            	return 0;
            }

            errors:

            1>c:\users\tiag o\documents\vis ual studio 2008\projects\p rojectoeda\proj ectoeda\main.cp p(73) : error C2664: 'CFilaEstaciona mento::NumLugar Estac' : cannot convert parameter 2 from 'CNoFila' to 'CNoFila *'
            1> No user-defined-conversion operator available that can perform this conversion, or the operator cannot be called
            1>c:\users\tiag o\documents\vis ual studio 2008\projects\p rojectoeda\proj ectoeda\main.cp p(85) : error C2664: 'CFilaEstaciona mento::NumLugar Estac' : cannot convert parameter 2 from 'CNoFila' to 'CNoFila *'
            1> No user-defined-conversion operator available that can perform this conversion, or the operator cannot be called

            can you help me?

            Comment

            • newb16
              Contributor
              • Jul 2008
              • 687

              #7
              int NumLugarEstac(i nt n1, CNoFila *InicioEstac);
              The second parameter
              *C2.InicioEstac is dereferenced type CNoFila*
              that is CNoFila& . And there is no conversion from CNoFila& to CNoFila*.

              Comment

              • vtuning
                New Member
                • Jul 2010
                • 5

                #8
                ok that fixed that error but now its in the linking that there is an error not in compile:

                1>Linking...
                1>main.obj : error LNK2019: unresolved external symbol "bool __cdecl spot(int,int,in t,int &,int,int,in t)" (?spot@@YA_NHHH AAHHHH@Z) referenced in function "void __cdecl Simulacao(class CNoFila &,int &,int,int &,int)" (?Simulacao@@YA XAAVCNoFila@@AA HH1H@Z)
                1>main.obj : error LNK2019: unresolved external symbol "public: int __thiscall CFilaEstacionam ento::NumLugarE stac(int,class CNoFila &)" (?NumLugarEstac @CFilaEstaciona mento@@QAEHHAAV CNoFila@@@Z) referenced in function "bool __cdecl spot(int,int,in t,int &,int,int)" (?spot@@YA_NHHH AAHHH@Z)
                1>main.obj : error LNK2019: unresolved external symbol "public: int __thiscall CFilaLavagem::N umLugarLav(int, class CNoFila &)" (?NumLugarLav@C FilaLavagem@@QA EHHAAVCNoFila@@ @Z) referenced in function "bool __cdecl spot(int,int,in t,int &,int,int)" (?spot@@YA_NHHH AAHHH@Z)
                1>C:\Users\Tiag o\Documents\Vis ual Studio 2008\Projects\p rojectoeda\Debu g\projectoeda.e xe : fatal error LNK1120: 3 unresolved externals


                from the previous post i only changed funcionts NumLugarEstac and NumLugarLav

                NumLugarEstac:

                numlugar2 = C2.NumLugarEsta c(n1,*C2.Inicio Estac);//calling function

                Code:
                int NumLugarEstac(int n1,CNoFila &InicioEstac){
                	
                	int tabaux[14];
                	
                	
                	CNoFila *Actual;
                	Actual = &InicioEstac;
                
                	for (int i = 0; i < 2 * (8-n1); i++){
                
                		tabaux[i] = Actual->numlugar;
                		Actual = Actual->Proximo;
                	}
                (...)

                NumLugarLav:

                numlugar1 = C1.NumLugarLav( n1,*C1.InicioLa v);//calling function...

                Code:
                int NumLugarLav(int n1, CNoFila &L){
                	
                	
                	int tabaux[8];
                	CNoFila *Actual;
                	*Actual = L;
                	int lugar;
                
                	for (int i = 0; i < n1; i++){
                
                		tabaux[i] = Actual->numlugar;
                		Actual = Actual->Proximo;
                	}

                these errors are from different symbols...in both functions declaration and implementation are exactly the same!

                :S

                Comment

                • Oralloy
                  Recognized Expert Contributor
                  • Jun 2010
                  • 988

                  #9
                  Your first problem is between your declaration and definition of the function spot(...).

                  "spot()" is declared as bool spot(int,int,in t,int &,int,int,in t)

                  "spot()" is defined as bool spot(int,int,in t,int &,int,int)

                  After that, there's a problem, as method CFilaEstacionam ento::NumLugarE stac(int,class CNoFila &) is not defined in your source code.

                  Comment

                  Working...