rendered paste body#include <iostream>
#include <string>
using namespace std;
class Book
{
string m_title;
string m_author;
string m_isbn;
public:
Book(string title,
string author,
string isbn)
{
m_title = title;
m_author = author;
m_isbn = isbn;
}
string getTitle()
{
return m_title;
}
string getAuthor()
{
return m_author;
}
string getISBN()
{
return m_isbn;
}
void setTitle(string title)
{
m_title = title;
}
void setAuthor(string author)
{
m_author = author;
}
void setISBN(string isbn)
{
m_isbn = isbn;
}
};
class Student
{
// array der geliehenen Buecher
Book* m_book[8];
public:
Student()
{
for(int i=0; i<(sizeof(m_book)/sizeof(m_book[0])); i++)
{
m_book[i] = NULL;
}
}
~Student()
{
for(int i=0; i<(sizeof(m_book)/sizeof(m_book[0])); i++)
{
if(m_book[i] != NULL)
{
delete m_book[i];
m_book[i] = NULL;
}
}
}
void addBook(Book book)
{
int i=0;
while(m_book[i] != NULL)
{
i++;
}
m_book[i] = new Book(book);
}
void removeBook(Book book)
{
int i=0;
while(book.getISBN() != (m_book[i]).getISBN())
{
i++;
}
delete m_book[i];
m_book[i] = NULL;
}
void printBooks()
{
int i;
for(i=0; i<(sizeof(m_book)/sizeof(m_book[0])); i++)
{
if(m_book[i] != NULL)
{
cout << "[Buch " << i << "] " << "Titel: " << (*m_book[i]).getTitle() << endl;
cout << "Author: " << (*m_book[i]).getAuthor() << ", "
<< "ISBN: " <<(m_book[i]).getISBN() << endl;
}
}
}
};
/** This is the entry point of the program. */
int main(int argc, char* argv[])
{
cout << "----------------\n";;
Book book_1("Introduction to Algorithms",
"Th. Cormen, Ch. Leiserson, R. Rivest",
"0262531968");
Book book_2("The C++ Programming Language",
"Bjarne Stroustrup",
"0201700735");
Book book_3("Grundkurs Informatik",
"H. Ernst",
"3528257172");
Student student;
student.addBook(book_1);
student.addBook(book_2);
student.addBook(book_3);
student.printBooks();
cout << "----------------\n";;
student.removeBook(book_2);
student.printBooks();
cout << "----------------\n";;
//wieder weg machen
cin.get();
return 0;
}