GIDForums  

Go Back   GIDForums > Computer Programming Forums > C++ Forum
User Name
Password
Register FAQ Members List Calendar Search Today's Posts Mark Forums Read

 
 
Thread Tools Search this Thread Rate Thread
  #1  
Old 22-Jan-2007, 10:22
Mararia Mararia is offline
New Member
 
Join Date: Dec 2006
Location: Tenerife, Canary Islands, Spain
Posts: 25
Mararia is on a distinguished road

Trouble with a linked list...


Hi again! As the title says, I'm having trouble with a linked list. For some reason, the compilator shows two messages and I can't find out what the problems are.

This is the code:
CPP / C++ / C Code:
/* **********************Libro.h******************** */
#ifndef Libro_H
#define Libro_H
#include <iostream>
using namespace std;


const int TAM_ISBN = 11;
const int TAM_AUTOR = 40;
const int TAM_LIBRERIA = 20;
const int TAM_TITULO = 105;

class Typeisbn{
public:
 Typeisbn(const char* isbn);
 Typeisbn();
 ~Typeisbn();
 bool operator == (const Typeisbn isbn);
 friend istream &operator >>(istream &is, Typeisbn isbn);
 friend ostream &operator <<(ostream &os,const Typeisbn &isbn);
 friend class Libro;
private:
 char ISBN [TAM_ISBN];
};

class Libro{
public:
 Libro *next;
 Libro();
 ~Libro();
 bool Es_Vacia(Libro l);
 void Insertarlibro (Libro l);
 Libro EliminarLibro(Libro l,Typeisbn busc);
 friend istream &operator >>(istream &is, Libro &r);
 friend ostream &operator <<(ostream &os,const Libro &r);
 friend void Listar (Libro l);
 friend Libro* Buscar (Libro l, Typeisbn busc);
 void Listar (Libro l);
private:  
 char Titulo [TAM_TITULO];
 char Libreria [TAM_LIBRERIA];
 char Autor [TAM_AUTOR];
 Typeisbn isbn;
 unsigned fechaedicion;
};
#endif

/* *******************Libro.C**************** */
#include "Libro.h"


Libro::Libro(){
}

Libro::~Libro(){
}

bool Libro::Es_Vacia(Libro l){
 if (!l.Titulo)
   return true;
 else
   return false;
}

void Libro::Insertarlibro (Libro l){
 if (!Es_Vacia (l))
   *this->next = l;
 l = *this;
}

Libro EliminarLibro (Libro l,Typeisbn busc){
 Libro *aux,*ant;
 aux = Buscar(l,busc);
 *ant = l;
 do
   ant = ant->next;
 while (ant->next != aux);
 ant->next = aux->next;
 delete aux;
}

Libro* Buscar (Libro l, Typeisbn busc){
 Libro *aux,aux2;
 *aux = l;
 aux2 = *aux;
 bool salida = false;
 do{
   if(aux2.isbn == busc)
     break;
   if (aux -> next != NULL){
     aux = aux ->next;
     aux2 = *aux;
   };
   if ((aux -> next == NULL) && !(aux2.isbn == busc))
     salida = true;
 }while (!salida);
 return aux;
}

void Libro::Listar (Libro l){
 Libro *aux;
 *aux = l;
 bool salida = false;
 do{
   cout << aux;
   if (aux -> next == NULL)
     salida = true;
   else
     aux = aux -> next;
 }while (!salida);
}


istream &operator >>(istream &is, Libro& r){
 cout << "Escribe el titulo del libro ";
 is >> r.Titulo;
 cout <<endl<< "Dime el autor del libro ";
 is >> r.Autor;
 cout <<endl<<  "Libreria ";
 is >> r.Libreria;
 cout <<endl<< "Fecha de edicion ";
 is >> r.fechaedicion;
 cout <<endl<<  "Escribe el isbn del libro ";
 is >> r.isbn;
}


ostream &operator <<(ostream &os,const Libro &r){
 os << "Libreria: " << r.Libreria <<endl;
 os << "Titulo: " << r.Titulo <<endl;
 os << "Autor: " << r.Autor <<endl;
 os << "Fecha de edicion" << r.fechaedicion << endl;
 os << "ISBN: " << r.isbn << endl;
return os;
}

bool operator == (const Typeisbn isbn1,const Typeisbn isbn2){
 if (isbn1  == isbn2)
   return true;
 else
   return false;
}

istream &operator >>(istream &is, Typeisbn isbn){
 is >> isbn.ISBN;
 return is;
}

ostream &operator <<(ostream &os,const Typeisbn &isbn){
 os << isbn.ISBN;
 return os;
}

Typeisbn::Typeisbn(const char* isbn){
 ISBN = *isbn;
}

Typeisbn::Typeisbn(){
}

Typeisbn::~Typeisbn(){
}


/* *****************Prac4.C (main)**************** */
#include "Libro.h"

void Menu (bool s,Libro Lista){
 cout << "Elija la accion a realizar"<< endl;
 cout << "0:Salir    1:Insertar libro  2: Borrar libro" << endl;
 cout << "3:Buscar libro  4:Listado de libros" << endl;
 int opt;
 cin >> opt;
 switch (opt){
   case 0:{
           s = true;
      break;
          };
   case 1:{
           Libro Lib;
           cin >>Lib;
           Lib.Insertarlibro (Lista);
      break;
          };
   case 2:{
           cout << "Escribe el ISBN del libro que quieres eliminar" <<endl;
           Typeisbn busc;
           cin >> busc;
           Lista = EliminarLibro(Lista,busc);
           break;
          };
   case 3:{
           cout << "Escribe el ISBN del libro que quieres buscar" <<endl;
           Typeisbn busc;
           cin >> busc;
           Libro* Lib = Buscar (Lista,busc);
           cout <<"El libro buscado es: "<< Lib;
      break;
          };
   case 4:{
           Listar (Lista);
           break;
          };
 };
}

int Main (){
 bool salida = false;
 Libro List;
 do
   Menu (salida,List);
 while (!salida);
 return (0);
}

And these are the compilator's messages:

Code:
pract04.C: In function ‘void Menu(bool, Libro)’: pract04.C:25: error: ‘EliminarLibro’ no se declaró en este ámbito //'EliminarLibro' wasn't declared in this field (context?) Libro.C: In constructor ‘Typeisbn::Typeisbn(const char*)’: Libro.C:107: error: tipos incompatible en la asignación de ‘const char’ a ‘char [11]’ //Incompatible types in assignation from const char to char [11]

I'm stuck. I don't know why it says that the function was't declared nor what to do to make the types compatible. Thanks
  #2  
Old 22-Jan-2007, 12:53
davekw7x davekw7x is offline
Outstanding Member
 
Join Date: Feb 2004
Location: Left Coast, USA
Posts: 4,649
davekw7x is a splendid one to beholddavekw7x is a splendid one to beholddavekw7x is a splendid one to beholddavekw7x is a splendid one to beholddavekw7x is a splendid one to beholddavekw7x is a splendid one to beholddavekw7x is a splendid one to behold

Re: Trouble with a linked list...


Quote:
Originally Posted by Mararia

Code:
pract04.C: In function ‘void Menu(bool, Libro)’: pract04.C:25: error: ‘EliminarLibro’ no se declaró en este ámbito //'EliminarLibro' wasn't declared in this field (context?)

Each file is a separate compilation unit. When the compiler encounters the function EliminarLibro in file pract04.C, it doesn't know what that function is. Everything that is #included in a given file is visible. Things from other *.C files are not.

You could put its prototype in Libro.h since you already include that header in pract04.C:

CPP / C++ / C Code:
// In Libro.h
Libro EliminarLibro(Libro l, Typeisbn busc);

Quote:
Originally Posted by Mararia
Libro.C: In constructor ‘Typeisbn::Typeisbn(const char*)’:
Libro.C:107: error: tipos incompatible en la asignación de ‘const char’ a ‘char [11]’ //Incompatible types in assignation from const char to char [11]
[/code]

Class member ISBN is what? (Answer an array of char)
The parameter isbn is a pointer to char. so *isbn is a char. The compiler is telling you that it won't let you make that assignment. You probably want to use strcpy() or strncpy() to copy something into the member array ISBN rather than just using an assignment anyhow.

Regards,

Dave
Last edited by davekw7x : 22-Jan-2007 at 14:07.
 
 

Recent GIDBlogFlickr uploads of IA pictures by crystalattice

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
[Include] Doubly-linked List dsmith C Programming Language 6 14-Apr-2006 13:12
Help in C Print is not working with LinkList batman3280 C Programming Language 3 09-Mar-2006 19:03
linked list error message Krandygrl00 C++ Forum 4 22-Jun-2005 14:13
search linked list itsmecathys C++ Forum 20 18-Apr-2005 01:34

Network Sites: GIDNetwork · GIDWebHosts · GIDSearch · Learning Journal by J de Silva, The

All times are GMT -6. The time now is 08:22.


vBulletin, Copyright © 2000 - 2008, Jelsoft Enterprises Ltd.