BookArray Code Flashcards

1
Q

BookArray ();

A

BookArray::BookArray(){
books = new Book*[MAX_ARR];
size = 0;
}

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

~ BookArray ();

A

BookArray::~BookArray(){
delete [] books;
}

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

bool add ( Book *);

A

bool BookArray::add(Book* book){
if (isFull()) return false;
int index = 0;
while (index < size){
if (book->getTitle() < books[index]->getTitle()){
break;
}
++index;
}
for (int i = size; i > index; –i){
books[i] = books[i-1];
}
books[index] = book;
++size;
return true;
}

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

bool get ( const string & title , Book **);

A

bool BookArray::get(const string& title, Book** book){
for (int i = 0; i < size; ++i){
if(books[i]->getTitle() == title){
*book = books[i];
return true;
}
}
*book = NULL;
return false;
}

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q

bool get ( int index , Book **);

A

bool BookArray::get(int index, Book** book){
if (index < 0 || index >= size){
*book = NULL;
return false;
}
*book = books[index];
return true;
}

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
6
Q

bool getMinPrice ( Book **);

A

bool BookArray::getMinPrice(Book** book){
if (size == 0){
*book = NULL;
return false;
}
book = books[0];
for (int i = 1; i < size; ++i){
if (books[i]->getPrice() < (
book)->getPrice()){
*book = books[i];
}
}
return true;
}

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
7
Q

void getAllFiction ( BookArray &);

A

void BookArray::getAllFiction(BookArray& bookArray){
for (int i = 0; i < size; ++i){
if (books[i]->isFiction()){
bookArray.add(books[i]);
}
}
}

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
8
Q

bool remove ( const string & title , Book **);

A

bool BookArray::remove(const string & title, Book ** book){
int index = 0;
while (index < size){
if (books[index]->getTitle() == title){ break; }
++index;
}

if (index >= size) return false;
*book = books[index];

while (index < size-1){
	books[index] = books[index+1];
	\++index;
}
--size;
return true; }
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
9
Q

bool remove ( int index , Book **);

A

bool BookArray::remove(int index, Book** book){
if (index < 0 || index >= size) return false;
return remove(books[index]->getTitle(), book);
}

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
10
Q

void print () const ;

A

void BookArray::print() const {
for (int i = 0; i < size; ++i){
books[i]->print();
}
}

How well did you know this?
1
Not at all
2
3
4
5
Perfectly