i need i have this code but when i compile it... it give me some funny errors whis i do not think they are really problem... here is the code i put some errors to the place where it is reporting error... i put the error messages to help you too to trace whether they are really errors... your help will be highly appereciated
[//an item is the abstract base class for all objects
//that are inserted in a table (see table.h).
#ifndef ITEM_H
#define ITEM_H
#include <iostream>
#include <fstream>
using namespace std;
class Item {
public:
virtual ~Item(){}
virtual int Compare (const Item & I2) const = 0;
//compare this object to item I2; return -1 if
//this object is less than I2, 0 if equal, and 1 if
//greater than I2
friend ostream & operator <<( ostream & os, const Item & I);
friend istream & operator >>( istream & inp, const Item & I);
private:
virtual void printOn ( ostream & os ) const = 0;
virtual void readFrom ( istream & inp ) = 0;
};
#endif]
[//********************************************************
// ITEM.H PACKAGE CLASS DEFINITION
//*******************************************************
#ifndef PACKAGE_H
#define PACKAGE_H
#include <cstring.h>
#include <iostream>
#include <iomanip.h>
#include "item.h"
using namespace std;
class Package : public Item {
public:
Package();
Package (long tracknumP, long originP,
long destinP, long dateP,
float costP, float weightP);
long GetDestination () const;
long GetTrackingNumber () const;
float GetWeight() const;
void PrintLong(ostream & os) const;
int Compare( const Item & I2) const;
//compare this package I2,
//return -1 if *this is less than I2,
//return 0 if *this is equal to I2,
//return 1 if *this is greater than I2
//function that set data member values:
void SetTrackNum( long trackNumP );
void SetOrigin( long originP );
void SetDestination ( long destinP );
void SetDate( long dateP );
void SetCost( float costP );
void SetWeight( float weightP );
void Init();
private:
long trackNum; //tracking number
long origin; //originating zip code
long destin; //destination zip code
long date; //date sent (yymmdd)
float cost; //shipping cost
float weight; //weight in kilograms
virtual void printOn( ostream & os ) const;
virtual void readFrom( istream & is ) ;
};
#endif
]
[//********************************************************
// TABLE.H TABLE CLASS DEFINITION
//*******************************************************
//this abstract class defines the public interface
//for the table class. A table contains object whose
//classes are derived from Item.
class Table{
public:
virtual ~Table() {}
virtual void AddItem( Item * ) = 0;
//add new item to the table.
virtual void Clear () = 0;
//empty the table
virtual unsigned GetCount() const = 0;
//return the number of entries in the table.
virtual Item * GetItemPtr( unsigned i ) const = 0;
//retrieve pointer to item at position i.
virtual unsigned IndexOf( const Item * P) const = 0;
//search for a matching item in the table;
//if found, return its index position,
//otherwise return UINT_MAX.
virtual void Sort() = 0;
//sort the table in ascending order
};
#endif
]
void Package::printOn ( ostream & os ) const
{
// Save the current flags and precision before modifying them.
unsigned svflags = os.setf( ios::showpoint | ios::fixed );
int svprecision = os.precision (2);
// Restore the previous flags and precision.
os.precision (svprecision );
os.flags ( svflags );
}
void Package::PrintLong ( ostream & os ) const
{
// Save the current flags and precision before modifying them.
unsigned svflags = os.setf( ios::showpoint | ios::fixed);
int svprecision = os.precision (2);
the other part of the program is here...
[//***************************************************
// TABLEARR.CPP - TableAsArray Class Implementation
//***************************************************
#include "tablearr.h"
// Create a table of size sz. Make sure that
// sz is less than UINT.MAX
// Empty the table. Delete all objects pointed to
// by the array and delete array of pointers.
void TableAsArray::Clear()
{
for(unsigned i = 0; i < count ; i++)
delete data[i];
delete [] data;
count = 0;
size = 0;
}
ostream & operator << ( ostream & os, const TableAsArray & T)
{
for(unsigned i =0; i<T.count; i++)
os << setw(3) << i << ": " << *T.data[i] << endl;
return os;
}
// Attempt to locate item P in the table. If succesful,
// return its index position; otherwise, return UINT_MAX,
// a standard constant defined in limits.h
unsigned TableAsArray::IndexOf ( const Item * P ) const
{
for(unsigned i = 0; i < count; i++)
if (P->Compare (*data[i]) == 0) return i;
for (i = 0; i < numRecords; i++)
{
pkg = new Package;
input >> *pkg;
ptable.AddItem ( pkg );
if( input.eof() ) break;
}
outfile << ptable << endl; //output the table
// Get each Package from the table, add its
// weight to a total, and display the total
// weight of all packages.
Package * z;
float sum = 0.0;
for (i = 0; i < ptable.GetCount(); i++)
{
z = (Package *)ptable.GetItemPtr ( i );
sum + = z->GetWeight();
}
outfile << "Total weight of packages = " << sum << "\n\n";