// file DShelf004.cpp
// authors AOU
// date 2006.02.15
/*
New
CDShelf(void); //constructorDefault
void displayDetailed(void);
void test_constructorDefault(void);
*/
/*
for a book of width 5 and id 1:
15 CBook books[MAX_SHELF_WIDTH]
11111 int a[MAX_SHELF_WIDTH]
function | int a[MAX_SHELF_WIDTH] vs CBook books[MAX_SHELF_WIDTH]
------------------------------------------------------------------------------
constructorDefault | |
isValid | |better
constructorRandom | |better
constructorWidth | |
constructorFragmented| |better
insertAtLeft | |better
displayDetailed | |
displaySimple |better |
displayBrief | |
isEmpty | |
randomBook | |better
randomBookPointer | |better
search | |better
remove_byID | |better
remove_byPointer | |better
reclaimSpace |better |
reclaimableSpace | |better
------------------------------------------------------------------------------
*/
#include <iostream>
using namespace std;
// Constants
int const UNDEFINED = -9;
int const MIN_SHELF_WIDTH = 5;
int const MAX_SHELF_WIDTH = 20;//100;
int const MIN_BOOK_ID = 1;
int const MAX_BOOK_ID = 9;//100;
int const TEST_COUNT = 10;
class CBook
{
private:
int id;
int width;
public:
CBook(void)
{
id = 0;
width = 0;
};
friend class CDShelf;
};
class CDShelf
{
private:
int width; // width of the bookshelf
int count; // number of books on shelf
int widthOccupied; // total width of book on shelf
// should it include empty holes?
// should not include empty holes
// instead use spaceAvailable
CBook books[MAX_SHELF_WIDTH];
public:
CDShelf(void); //constructorDefault
void displayDetailed(void);
/*
isValid
constructorRandom
constructorWidth
constructorFragmented
insertAtLeft
displaySimple
displayBrief
isEmpty
randomBook
randomBookPointer
search
remove_byID
remove_byPointer
reclaimSpace
reclaimableSpace
*/
};
void test_constructorDefault(void);
// test_isValid
// test_constructorRandom
// test_constructorWidth
// test_constructorFragmented
// test_insertAtLeft
// test_displayDetailed
// test_displaySimple
// test_displayBrief
// test_isEmpty
// test_randomBook
// test_randomBookPointer
// test_search
// test_remove_byID
// test_remove_byPointer
// test_reclaimSpace
// test_reclaimableSpace
void main(void)
{
cout << "Hello\n";
test_constructorDefault();
}
void CDShelf::displayDetailed(void)
{
cout << "width = " << width << endl;
cout << "count = " << count << endl;
cout << "widthOccupied = " << widthOccupied << endl;
for (int i=0; i<MAX_SHELF_WIDTH; i++)
{
cout << books[i].id ;
cout << books[i].width << ' ';
}
cout << endl;
}
void test_constructorDefault(void)
{
CDShelf myShelf;
myShelf.displayDetailed();
}
CDShelf::CDShelf(void)
{
this->width = MIN_SHELF_WIDTH;
this->count = 0;
this->widthOccupied = 0;
for (int i=0; i<MAX_SHELF_WIDTH; i++)
{
books[i].id = 0;
books[i].width = 0;
}
}
|