2016-04-23 5 views
1

この問題を解決するのを手伝ってください。 -.-これを理解できません! 。あなたがコーディングの学習を始めたばかりのときにはとてもイライラします。関数内で宣言構文エラーが発生しました

、ボイドの問題エラー:宣言構文エラー のボイド表示エラー:ポインタの不正使用

謝罪私の中で任意の愚行が見つかった場合。

#include <iostream.h> 
#include <conio.h> 
#include <stdio.h> 
#include <string.h> 


class book 
{ 
char bookname[20]; 
char isbn[20]; 
char author[20]; 
char category[20]; 
float price; 
int noc; 

public: 

void accept() 
{ 

cout<<"Enter book name :- \n"; 
gets(bookname); 
cout<<"Enter isbn no of the book:- \n"; 
gets(isbn); 
cout<<"Enter authour name:- \n"; 
gets(author); 
cout<<"Enter category of book:- \n"; 
gets(category); 
cout<<"Enter price of the book :- \n"; 
cin>>price; 
cout<<"Enter no of copies of book available in the library :- \n"; 
cin>>noc; 
} 

void display() 
{ 
puts(bookname)<<endl; 
puts(isbn)<<endl; 
puts(author)<<endl; 
puts(category)<<endl; 
cout<<price<<endl; 
cout<<noc<<endl; 
} 

}b[5]; 

int main() 
{ 
for(int i=0;i<5;++i) 
{ 
b[i].accept(); 
} 

void issue() 
{ 
int flag=0; 
char booksearch[20]; 
cout<<"Enter name of book member wants to issue :- \n" 
gets(booksearch); 
    for(i=0;i<5;++i) 
    { 
     flag=strcmp(booksearch,b[i].bookname) 
    } 

} 

if(flag==1) 
{ 
    b[i].display(); 
    b[i].issue(); 
} 
getch(); 
return 0; 
} 
+0

より具体的にすることができますし、コードのいくつかを投稿する – Pavan

+0

ようこそStackOverflow!時間をかけてhttp://stackoverflow.com/help/mcveをご覧ください。特に、あなたの質問に完全なコピー貼り付けエラーを含める必要があります。 –

+0

プレーンテキストエディタまたはワープロを使用していますか? –

答えて

1

を行います

  1. strcmpコールの後にセミコロンがありません:マッチ、ない1がある場合に
  2. strcmp 0を返し、ループの次の繰り返しでフラグを上書きする可能性があります。
  3. issueの定義はの真ん中ですあなたが混合されている
  4. 、スタイル演算子>> - - ひどく - あなたがCスタイル取得し、C++を混合している、
  5. Cスタイルのプットとオペレータ< <

ここでは、非作業バージョンですここで http://ideone.com/sGdXcm

で固定し、作業バージョン:あなたのコードの

#include <iostream> 
#include <string> 
#include <array> 
#include <limits> 

using namespace std; 

class book 
{ 
    std::string bookname; 
    std::string isbn; 
    std::string author; 
    std::string category; 
    float price; 
    int noc; 

public: 
    const std::string& getBookname() const { return bookname; } 
    const std::string& getISBN() const { return isbn; } 
    const std::string& getAuthor() const { return author; } 
    const std::string& getCategory() const { return category; } 
    float getPrice() const { return price; } 
    float getNoC() const { return noc; } 

    void accept() 
    { 
     cout<<"Enter book name :- \n"; 
     std::getline(std::cin, bookname); 
     cout<<"Enter isbn no of the book:- \n"; 
     std::getline(std::cin, isbn); 
     cout<<"Enter authour name:- \n"; 
     std::getline(std::cin, author); 
     cout<<"Enter category of book:- \n"; 
     std::getline(std::cin, category); 
     cout<<"Enter price of the book :- \n"; 
     std::cin>>price; 
     cout<<"Enter no of copies of book available in the library :- \n"; 
     std::cin>>noc; 
     std::cin.ignore(std::numeric_limits<streamsize>::max(), '\n'); 
    } 

    void display() 
    { 
     std::cout<<bookname<<std::endl; 
     std::cout<<isbn<<std::endl; 
     std::cout<<author<<std::endl; 
     std::cout<<category<<std::endl; 
     std::cout<<price<<std::endl; 
     std::cout<<noc<<std::endl; 
    } 

    void issue() 
    { 
    } 
}; 

int main() 
{ 
    std::array<book, 5> b; 
    for(int i=0;i<b.size();++i) 
    { 
     b[i].accept(); 
    } 

    std::string booksearch; 
    std::cout<<"Enter name of book member wants to issue :- \n"; 
    std::getline(cin, booksearch); 
    std::cout<<"Searching for: " << booksearch << "\n"; 
    for(int i=0;i<b.size();++i) 
    { 
     if (b[i].getBookname() == booksearch) 
     { 
      b[i].display(); 
      b[i].issue(); 
      break; 
     } 
    } 

    std::string dummy; 
    std::cout << "Hit return:"; 
    std::getline(std::cin, dummy); 

    return 0; 
} 

リーveデモ:http://ideone.com/p3Ygw3

注:私はこのコードにエラーチェックを追加しませんでした。ユーザーが本を入力している間にタイプミスが起こると間違っています。

1
  1. あなたflag=strcmp (searchbook, b [I]. bookname)行の後にセミコロンを追加します。
  2. flagsearchbookbがまだ宣言されていない場合は、これを宣言します。
  3. あなたのコードを持つ数多くのエラーがあります#include <string.h>
  4. あなたの関数の前
関連する問題