Chinaunix首页 | 论坛 | 博客
  • 博客访问: 2342043
  • 博文数量: 816
  • 博客积分: 10000
  • 博客等级: 上将
  • 技术积分: 5010
  • 用 户 组: 普通用户
  • 注册时间: 2008-12-17 17:57
文章分类

全部博文(816)

文章存档

2011年(1)

2008年(815)

分类:

2008-12-17 18:02:32

我自己寫一個程式再編譯時有問題請各位高手幫忙
謝謝
1.cpp(55) : error C2065: 'phead' : undeclared identifier
1.cpp(80) : error C2040: 'phead' : 'Book *' differs in levels of indirection from ''unknown-type''

my code------------------

# include
using namespace std;


 enum euseroption_E
 {    
ADD_BOOK=1,
    DEL_BOOK,
SEARCH_BOOK,
LIST_ALL_BOOK,
EXIT_BOOK,
 };

 struct Book
 {
char seBookName[20];
int nISBN;
int nprice;
char szAuthorName [20];
Book *pNextbook;
 };




 
 void ulist()
{
     cout << "1.加書" << endl;
cout << "2.刪書" << endl;
cout << "3.找書" << endl;
cout << "4.列出書" << endl;
cout << "5.離開" << endl;

    }

void Addbook()
 {  
    Book *pNewBook =new Book;
pNewBook ->pNextbook=0;
cout << "請輸入書名----"  < cin  >> pNewBook->seBookName;
    cout << "請輸入作者----"  < cin  >> pNewBook->szAuthorName;
cout << "請輸入價格----"  < cin  >> pNewBook->nprice;
    cout << "請輸入ISBN----"  < cin  >> pNewBook->nISBN;

 }

  void listbook()
  {
    Book *pcurrentbook=0;
    pcurrentbook=phead;
    int ncounter=1;
    while (0 != pcurrentbook){
       
   cout << ncounter << "." <     << "書名" << pcurrentbook ->seBookName < << "作者" << pcurrentbook ->szAuthorName < << "價格" << pcurrentbook ->nprice < << "ISBN" << pcurrentbook ->nISBN <        pcurrentbook=pcurrentbook ->pNextbook;
}
  }

  void Delbook()
  {

  }
 

   void Searchbook()
  {

  }

   
   Book *phead;
void main()
{
     ulist();
cout <<"請輸入選項---"  < int ucheck=0 ;
cin >>ucheck;
switch (ucheck){
    

     case ADD_BOOK:
{ cout << "加書"  ;
  
   Book *pNewBook = new Book;
   pNewBook->pNextbook = phead;
  
    Addbook();
   break;
}

case DEL_BOOK:
{ cout << "刪書"  ;
    Delbook();
   break;
}
         
case SEARCH_BOOK:
{ cout << "找書"  ;
    Searchbook();
   break;
}

case LIST_ALL_BOOK:
{ cout << "列出"  ;
   listbook();
   break;
}

case EXIT_BOOK:
{ cout << "離開" << ucheck ;
   break;
}
       
default:
         { cout <<"選擇錯誤" <    break;
}
}



}

--------------------next---------------------

//我改了以后在Boland C++6.0编译通过。
# include
using namespace std;

///////////////////////////////////////////////////////////////////////
enum euseroption_E
  { ADD_BOOK=1,DEL_BOOK,SEARCH_BOOK,LIST_ALL_BOOK,EXIT_BOOK};
///////////////////////////////////////////////////////////////////////
struct Book
  {
    char seBookName[20];
    int nISBN;
    int nprice;
    char szAuthorName [20];
    Book *pNextbook;
  };
////////////////////////////////////////////////////////////////////////
//--------------------------------------------------------------------
Book *phead;
void ulist()
  {
    cout << "1.加書" << endl;
    cout << "2.刪書" << endl;
    cout << "3.找書" << endl;
    cout << "4.列出書" << endl;
    cout << "5.離開" << endl;
  }
//------------------------------------------------------------------------
void Addbook()
  {
    Book *pNewBook =new Book;
    pNewBook ->pNextbook=0;
    cout << "請輸入書名----"  <    cin >> pNewBook->seBookName;
    cout << "請輸入作者----"  <    cin  >> pNewBook->szAuthorName;
    cout << "請輸入價格----"  <    cin  >> pNewBook->nprice;
    cout << "請輸入ISBN----"  <    cin  >> pNewBook->nISBN;
  }
//------------------------------------------------------------------------
void listbook()
  {
    Book *pcurrentbook=0;
    pcurrentbook=phead;
    int ncounter=1;
    while (0 != pcurrentbook)
      {
        cout << ncounter << "." <        << "書名" << pcurrentbook ->seBookName <        << "作者" << pcurrentbook ->szAuthorName <        << "價格" << pcurrentbook ->nprice <        << "ISBN" << pcurrentbook ->nISBN <        pcurrentbook=pcurrentbook ->pNextbook;
      }
  }
//------------------------------------------------------------------------
void Delbook()
  {
    }
//-----------------------------------------------------------------------
void Searchbook()
  {

  }
//------------------------------------------------------------------------

void main()
  {
    ulist();
    cout <<"請輸入選項---"  <    int ucheck=0 ;
    cin >>ucheck;
    switch (ucheck)
      {
        case ADD_BOOK:{
                        cout << "加書"  ;Book *pNewBook = new Book;
                        pNewBook->pNextbook = phead;
                        Addbook();
                        break;
                     }

        case DEL_BOOK:{
                        cout << "刪書"  ;
                        Delbook();
                        break;
                      }

        case SEARCH_BOOK:{
                           cout << "找書"  ;
                           Searchbook();
                           break;
                         }

        case LIST_ALL_BOOK:{
                             cout << "列出"  ;
                             listbook();
                             break;
                           }
        case EXIT_BOOK:{
                          cout << "離開" << ucheck ;
                          break;
                       }

        default:{
                  cout <<"選擇錯誤" <                }
      }
  }

--------------------next---------------------

阅读(1056) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~