错误C2601:' Library :: ShowList' :本地函数定义是非法的

时间:2017-04-13 20:04:23

标签: c++

我无法在功能或额外支撑中看到功能!

error C1075: end of file found before the left brace '{' at 'c:\users\...  
 was matched    c:\users\.....
error C2601: 'Library::Search' : local function definitions are illegal 
error C2601: 'Library::DeleteBook' : local function definitions are illegal

C2601有3个错误。

#include "stdafx.h";
#include <iostream>
#include <fstream>

using namespace std;

class Book
{
public:
    char* title;
    char* author;
    char* publisher;
    char* present;
    int year;

    Book()
    {
    }

    Book(char* title, char* author, char* publisher, char* present, int year)
    {
        this->title = title;
        this->author = author;
        this->publisher = publisher;
        this->present = present;
        this->year = year;
    }
};

class Library
{
    Book *books;

public:
    Library()
    {
        //books = new Book("The evil zombie is back", "Gal4eto", "Monster and zombie books LTD", "Yes", 2020);
    }

    void AddBook(Book *booklist)
    {
        this->books = booklist;
    }

    void Add(int newbook);
    void ChangeName();
    void Search();
    void DeleteBook();
    void ShowList();
};

int main()
{
    do
    {
        int n = 0, bookscount = 0;
        char *yourzombie;

        cout << "Enter your terrible book list....";
        cin >> yourzombie;

        fstream zombiefile;
        zombiefile.open(yourzombie, ios::in | ios::out | ios::app);
        if (!zombiefile)
        {
            cout << "This file doesn't exit...";
            continue;
        }

        Book zombiearr[100];
        Library onezombie;
        if (zombiefile.is_open())
        {
            for (int i = 0; i < 100; i++)
            {
                zombiefile >> zombiearr[i].title;
                if (!zombiearr[0].title)
                {
                    cout << "Here hasn't a list!";
                    break;
                }

                zombiefile >> zombiearr[i].author;
                zombiefile >> zombiearr[i].year;
                zombiefile >> zombiearr[i].publisher;
                zombiefile >> zombiearr[i].present;
                bookscount = i + 1;

                if (!zombiefile.eof())
                    break;
            }

            onezombie.AddBook(zombiearr);
        }
        else
        {
            cout << "Can't open the file!";
            continue;
        }

        if (zombiefile.is_open())
        {
            do
            {
                cout << "If you wanna \n";
                cout << "add zombie book - press 1,\n";
                cout << "change zombie book name - press 2,\n";
                cout << "delete zombie book - press 3 \n";
                cout << "view all books - press 4\n";
                cout << "search zombie book - press 5 \n";
                cout << "Exit - 6 ";
                cin >> n;

                if (zombiearr != NULL)
                {
                    switch (n)
                    {
                        case 1:
                            onezombie.Add(bookscount);
                            break;
                        case 2:
                            onezombie.ChangeName();
                            break;
                        case 3:
                            onezombie.DeleteBook();
                            break;
                        case 4:
                            onezombie.ShowList();
                            break;
                        case 5:
                            onezombie.Search();
                            break;
                        case 6:
                            exit(1);
                            break;
                        default:
                            cout << "This doesn's do anything, just repeats the menu :-( . You should choose number of the menu. \n";
                            break;
                    }
                }
            }
            while (1);
        }
    }
    while (1);

    return 0;
}

void Library::Add(int newbook)
{
    cout << "Insert book's name\n";
    cin >> this->books[newbook].title;
    cout << "Insert book's author\n";
    cin >> this->books[newbook].author;
    cout << "Insert book's year\n";
    cin >> this->books[newbook].year;
    cout << "Insert book's publisher\n";
    cin >> this->books[newbook].publisher;
    cout << "Insert \"yes\" if book is present or \"no\" if it isn't \n ";
    cin >> this->books[newbook].present;
}

void Library::ChangeName()
{
    char *oldname, *newname;
    cout << "Enter the name of book you want to rename and then its new name. ";
    cin >> oldname >> newname;
    int sizeofbooks = (sizeof(this->books) / sizeof(this->books[0]));
    for (int i = 0; i < sizeofbooks; i++)
    {
        if (this->books[i].title == oldname)
        {
            this->books[i].title = newname;
            cout << "The name is changed. ";
        }
    }
}

void Library::Search()
{
    char* bookname;
    cout << "Enter the name of book which you search: ";
    cin >> bookname;
    int sizeofbooks = (sizeof(this->books) / sizeof(this->books[0]));
    for (int i = 0; i < sizeofbooks; i++)
    {
        if (this->books[i].title == bookname)
        {
            cout << this->books[i].title << " ";
            cout << this->books[i].author << " ";
            cout << this->books[i].publisher << " ";
            cout << this->books[i].year << " ";
            cout << this->books[i].present << " ";
            cout << endl;
        }    
    }
}

void Library::DeleteBook()
{
    char* bookname;
    cout << "Enter name of the book you want to delete";
    cin >> bookname;
    int sizeofbooks = (sizeof(this->books) / sizeof(this->books[0]));
    for (int i = 0; i < sizeofbooks; i++)
    {
        if (this->books[i].title == bookname)
        {
            for (int j = i; j < sizeofbooks - 1; i++)
                this->books[j] = this->books[j + 1];
        }
    }
}

void Library::ShowList()
{
    int sizeofbooks = (sizeof(this->books) / sizeof(this->books[0]));
    for (int i = 0; i < sizeofbooks; i++)
    {
        cout << this->books[i].title << " ";
        cout << this->books[i].author << " ";
        cout << this->books[i].publisher << " ";
        cout << this->books[i].year << " ";
        cout << this->books[i].present << " ";
        cout << endl;
    }
}

0 个答案:

没有答案