check whether there is any error here because i do nt think there is any

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.

#ifndef TABLE_H
#define TABLE_H

#include "item.h"
#include "limits.h"
//using namespace std;

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
]

[//TABLEARR.H- TableAsArray Class Definition

#ifndef TABLEARR_H
#define TABLEARR_H

#include <iostream>
#include <iomanip.h>
#include <assert.h>
#include "table.h"

class TableAsArray : public Table{
public:
TableAsArray(unsigned tableSize);
virtual ~TableAsArray();
virtual void AddItem(Item * I);
virtual void Clear();
Virtual unsigned GetCount()const;
virtual Item * GetItemPtr( unsigned i) const;
virtual unsigned IndexOf( const Item * P) const;
virtual void Sort();
friend ostream & operator<<( ostream &, const TableAsArray &);

private:
Item ** data; //array of pointers to items
unsigned size; //allocation size
unsigned count; //number of items

private:
void swap(Item * & p1, Item * & p2);
};
inline TableAsArray::~TableAsArray()
{
Clear();
}
inline unsigned TableAsArray::GetCount() const
{
return count;
}
inline Item * TableAsArray::GetItemPtr( unsigned i) const
{
assert( i< count);
return data[i];
}
#endif


]


[//********************************************************
// ITEM.CPP- ITEM CLASS IMPLEMENTATION
//********************************************************
#include "item.h"
ostream & operator <<(ostream & os, const Item & I)
{I.printOn ( os );
return os;
}
istream & operator >> (istream & inp, Item & I)
{I.readFrom ( inp );
return inp;
}
]

[//********************************************************
// PACKAGE.CPP- PACKAGE CLASS IMPLEMENTATION
//********************************************************

#include "package.h"

Package::Package()
{
Init();
}
Package::Package(
long trackNumP,
long originP,
long destinP,
long dateP,
float costP,
float weightP )
{
SetTrackNum (trackNumP);
SetOrigin (originP);
SetDestination (destinP);
SetDate (dateP);
SetCost (costP);
SetWeight (weightP);
}
void Package::Init()
{
SetTrackNum (0);
SetOrigin (0);
SetDestination (0);
SetDate(0);
SetCost ( 0.0f );
SetWeight (0.0f );
}

long Package::GetDestination() const
{
return destin;
}

long Package::GetTrackingNumber() const
{
return trackNum;
}

float Package::GetWeight() const
{
return weight;
}

void Package::SetTrackNum (long trackNumP )
{
trackNum = trackNumP;
}
void Package::SetOrigin ( long originP )
{
origin = originP;
}

void Package::SetDestination ( long destinP )
{
destin = destinP;
}

void Package::SetDate ( long dateP )
{
date = dateP;
}

void Package::SetCost ( float costP )
{
cost = costP;
}

void Package::SetWeight ( float weightP )
{
weight = weightP;
}

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);

os << '['
<< trackNum << ','
<< origin << ','
<< destin << ','
<< date << ','
<< cost << ','
<< weight << "]" << endl;

// 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);

os << "............................\n"
<< "Tracking number : "
<< trackNum << '\n'
<< "Origination zip code : "
<< origin << '\n'
<< "Destination zip code : "
<< destin << '\n'
<< "Date Sent: "
<< date << '\n'
<< "Shipment cost: "
<< cost << '\n'
<< "Package weight "
<< weight << endl;

// Restore the previous flags and precision.
os.precision ( svprecision );
os.flags (svflags );

}

void Package::readFrom (istream & inp)
{
Init();
inp >> trackNum >> origin >> destin >> date >> cost >> weight;
inp.ignore ( 10, '\n' );
}

int Package::Compare (const Item & I2 ) const
{
if (trackNum < ((Package &)I2).trackNum )
return -1;
else if ( trackNum == ((Package &)I2).trackNum )
return 0;
else // if ( trackNum > ((Package &)I2).trackNum )
return 1;
}]



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

TableAsArray::TableAsArray (unsigned sz )
{
size = sz;
assert (size < UINT_MAX );
count = 0;
data = new Item *[size];
for(unsigned j = 0; j < size; j++)
data[j] = 0;
}

// Add an item to the table. P cannot be pointer to const
// because data[] does not contaion pointers to constants.

void TableAsArray::AddItem ( Item * P)
{
if(count < size )
data[count++] = P;
else
cout << "Error : Table full; item not added.\n";
}

// 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;

return UINT_MAX;
}

// Sort the table using Selectiion sort.

void TableAsArray::Sort()
{
for (unsigned curr = 0; curr < count-1; curr++)
{
unsigned minIndex = curr;

for (unsigned k = curr+1; k < count ; k++)
if ( data[k] -> Compare(*data[minIndex]) < 0)
minIndex = k;

if ( minIndex != curr )
swap ( data [curr], data[minIndex] );
}
}

void TableAsArray::swap ( Item * & p1, Item * & p2 )
{
Item * temp;
temp = p1;
p1 = p2;
p2 = temp;
}
]
[//************************************************
// SHIPPING.CPP - Package Shipping Program
//************************************************

#include <iostream>
#include <conio.h>
#include <fstream>
#include <cstring>
#include <cstdlib>
#include <iomanip>
#include <time.h>
#include <windows.h>
#include <sstream>
#include <fstream>
#include "package.h"
#include "tablearr.h"
using namespace std;

int main()
{
// Open input file, get number of Packages,
// open output file, create table.

ifstream input ("PACKAGES.TXT" );
if (!input) return 1;
ofstream outfile ("outfile.txt");

unsigned numRecords;
input >> numRecords;
input.ignore (1, '\n' );
if ( numRecords < 1)
{
cout << "Package file is empty. Ending program.\n";
return 0;
}

// Read all Packages from the input file,
// add them to the table, and display the table.

TableAsArray ptable ( numRecords );
Package * pkg;
unsigned 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";

// Sort and display the table.

ptable.Sort ();
outfile << "Packages sorted by tracking number......\n"
<< ptable << '\n';

// Search for a particular package by its tracking
// number. If found, retrieve and display the package.

pkg ->Init();
pkg->SetTrackNum (101400L );
unsigned n = ptable.IndexOf (pkg );

if (n != UINT_MAX )
{
pkg = (Package *)ptable.GetItemPtr( n );
outfile << "Package " << *pkg << "found at position " << n << '\n';
}
else
outfile << "Package not found. \n";

return 0;
}
]
Topic archived. No new replies allowed.