Jump to content
Maintenance
  • Scythe Gaming is currently in beta
  • Please be patient until we finish the website

Week 5 Testing Function 1.0.0

Sign in to follow this  

About This File

Week 5 Testing Function

Note that the names of functions begin with lower case

The following is the code that converts vectors into string:

 

 

 

struct Book {

public:
    std::string category;
    std::string title;
    std::string author;

    std::string toString() {
        return "\"" + this->title + "\" by " + this->author + " (" + this->category + ")";
    }

};

 

 

 

Paste the following into BookPile.cpp

std::string BookPile::toString() { // This function converts all of the data inside the array into a string so it can be compared with other arrays
    std::string Output = "";
    for (Book b : BookPile::Stack) {
        Output = Output + b.toString();
    }
    return Output;
}

 

 

replace BookPile.h with the following...

#pragma once
class BookPile {

public:
    virtual bool addBook(Book b); // Change 'virtual bool' to void if it breaks your code
    void removeBook();
    Book getNextBook();
    void listAllBooks();
    int getNumBooks();
    std::string toString();

protected:
    std::vector<Book> Stack;

};




×
×
  • Create New...