Topic: C++ Array Implementation of the Ordered List ADT
Blayne Bradley
unregistered
posted
Okay my teacher gave me a main.cpp and a header file orderedlist.h,
I comile the code and run it and my compile errors are unresolved externals, my assignments I believe is essentally fill-in-the-blanks and create the actual functions being called.
here's main;
code:
// Test of an array implementation of the OrderedList class
assert( ! list.Search( 1, info ) ); assert( list.Insert( 1, info ) ); assert( ! list.Search( 0, info ) ); assert( list.Search( 1, info ) ); assert( ! list.Search( 2, info ) ); assert( list.Insert( 3, info ) ); assert( ! list.Search( 0, info ) ); assert( list.Search( 1, info ) ); assert( ! list.Search( 2, info ) ); assert( list.Search( 3, info ) ); assert( ! list.Search( 4, info ) ); assert( list.Insert( 5, info ) ); assert( ! list.Search( 0, info ) ); assert( list.Search( 1, info ) ); assert( ! list.Search( 2, info ) ); assert( list.Search( 3, info ) ); assert( ! list.Search( 4, info ) ); assert( list.Search( 5, info ) ); assert( ! list.Search( 6, info ) );
{ OrderedList list; Info info = { "", 0, 0 };
for ( int i = 0; i < MAX_SIZE_ORDERED_LIST - 1; i++ ) { assert( list.Insert( i, info ) ); } assert( ! list.IsFull() ); assert( list.Insert( MAX_SIZE_ORDERED_LIST - 1, info ) ); assert ( list.IsFull() ); }
{ OrderedList list; Info info = { "", 0, 0 }; int key ;
assert( list.Insert( 20, info ) ); assert( list.Insert( 22, info ) ); assert( list.Insert( 24, info ) ); assert( list.Insert( 19, info ) ); assert( list.Insert( 21, info ) ); assert( list.Insert( 23, info ) ); assert( list.Insert( 25, info ) ); list.Reset(); for ( int i = 19; i < 26; i++ ) { list.Advance( key , info ); assert( key == i ); } }
cout << "Completed test Ordered List." << endl;
char dummy; cin >> dummy; }
and heres the header.
code:
#ifndef ORDERED_LIST_H #define ORDERED_LIST_H
const int MAX_SIZE_ORDERED_LIST = 20; const int MAX_LENGTH_NAME = 20;
struct Info { char lastname[MAX_LENGTH_NAME+1]; char firstname[MAX_LENGTH_NAME+1]; double salary; };
class OrderedList { public: OrderedList(); bool Search( /* in */ int key, /* out */ Info& info ); bool Insert( /* in */ int key, /* in */ Info info ); bool Delete( /* in */ int key ); int Size() const; void Reset(); void Advance( /* out */ int& key, /* out */ Info& info ); bool IsEmpty( void ) const; bool IsFull( void ) const; private: struct Item { int key; Info info; }; Item items[MAX_SIZE_ORDERED_LIST]; int size; int current; };
#endif
Now here's the thing I believe the assignment (which just says Implement the Ordered List ADT using a array implementation) is to make another .cpp file and fill in the functions there.
I'm not entirely sure how functions are called inbetween .cpp files (linking?) like if a function protype is made in the header and called in main.cpp do I simply finish the job and define the function in the separate .cpp file and if so how do I link files?
IP: Logged |
posted
Write the body of these functions either in orderedlist.cpp; or if it's short enough, make it inline, in orderedlist.h.
Whatever you were already doing to create an executable program, do it in this case as well, and it'll do the linking.
Posts: 1877 | Registered: Apr 2005
| IP: Logged |
posted
Lord I've never seen so many "assert" calls in my life.
Does the code inside of the "assert" get executed when you compile a RELEASE version? I use to remember that MFC's equivalent (DEBUG) would effectively null out the statement in release, which means that the code never gets compiled or executed.
Really bad practice, if you ask me.
Posts: 3486 | Registered: Sep 2002
| IP: Logged |
posted
Its an assignment. The asserts both indicate desired behavior of the API to the student and check his code's compliance with it.
Posts: 15770 | Registered: Dec 2001
| IP: Logged |