所以这个程序的目的是让书和作者类使用displayBooks方法显示标题,作者,每本书中的页数以及每本书的价格。有一个问题,弄清楚这应该如何工作。请问有什么建议吗?
class Book
{
private:
string title;
int pages;
double price;
public:
Book();
Book(string title, int pages, double price);
};
#include "stdafx.h"
#include "Book.h"
#include "Author.h"
Author::Author()
{
}
Book::Book()
{
}
Book::Book(string title, int pages, double price)
{
}
class Author
{
private:
string name;
string address;
public:
Author();
Author(string name, string address);
int getName();
int getAddress();
};
#include "stdafx.h"
#include "Author.h"
Author::Author()
{
}
Author::Author(string name, string address)
{
}
int Author::getName()
{
return name;
}
int Author::getAddress()
{
return address;
}
#include <iostream>
#include <string>
#include <vector>
#include "Book.h"
#include "Author.h"
using namespace std;
// The displayBooks function
// Purpose: Display all of the data about a book
// Parameters: A vector of Book objects
// Returns: none
void displayBooks(const vector<Book>&);
int main()
{
// create a vector for storing the account objects
vector<Book> myBooks;
// create three Author objects
Author p1("J.K.Rowling", "Edinburgh, Scotland");
Author p2("Suzanne Collins", "Connecticut, USA");
Author p3("J.R.R. Tolkien", "Bournmouth, England");
// Create three Book objects
Book b1(p1, "Harry Potter and the Sorcerer's Stone", 256, 24.95);
Book b2(p2, "Mockingjay", 400, 12.99);
Book b3(p3, "The Hobbit", 322, 14.29);
// add the books to the vector
myBooks.push_back(b1 );
myBooks.push_back(b2);
myBooks.push_back(b3);
// call the displayBooks function to display the books
displayBooks(myBooks);
cout << "\n\n";
system("PAUSE");
return 0;
}
void displayBooks(const vector<Book>& books)
{
cout << " " << mybooks << endl;
}