GIDForums  

Go Back   GIDForums > Computer Programming Forums > CPP / C++ Forum
User Name
Password
Register FAQ Members List Calendar Search Today's Posts Mark Forums Read

 
 
Thread Tools Search this Thread Rate Thread
  #1  
Old 01-Nov-2004, 15:41
wbsquared03 wbsquared03 is offline
New Member
 
Join Date: Oct 2004
Posts: 14
wbsquared03 is on a distinguished road
Angry

help with tele directory problem due tomorrow


this program you are implementing a C++ class to generate a new telephone directory using Sorted List in terms of last name.

i keep getting this error

c:\Documents and Settings\Sean Walsh\My Documents\Visual Studio Projects\sorted\teldir.cpp(83): error C2676: binary '<' : 'ItemType' does not define this operator or a conversion to a type acceptable to the predefined operator

it also doesn't take != and > operators. Can anyone figure what is going on with this and help me out a little becuase im stuck.

CPP / C++ / C Code:
#include <iostream>
#include <iomanip>
#include <string>
#include <iostream>
#include <fstream>




using namespace std;

const int MAX_LENGTH=100;

struct rectype
{
	string last;
	string first;
	char middle;
	string tel;
	string room;
	string month;
	string day;
	string year;

};

typedef rectype ItemType; //type of each component


class SortedList
{
public:
	SortedList();
	bool IsEmpty() const;
	bool IsFull() const;
	int LengthIs() const;
	void Insert(ItemType item);
	void Delete(ItemType item);
	bool IsPresent(ItemType item) const;
	void Print() const;
private:
	int length;
	ItemType data[MAX_LENGTH];
	void BinSearchbyName(ItemType item, bool& found, int& position) const;
	void BinSearchMonth(ItemType item, bool& found, int& position) const;
};

SortedList::SortedList()
{
	length=0;
}
bool SortedList::IsEmpty() const
{
	return(length==0);
}
bool SortedList::IsFull() const
{
	return(length==MAX_LENGTH);
}
/*void SortedList::MakeEmpty()
{
	length=0;
}*/
int SortedList::LengthIs() const
{
	return length;
}
void SortedList::Insert(ItemType item)
{
	
	
}

void SortedList::BinSearchbyName(ItemType item, bool& found, int& position) const
{
	int first=0;
	int last=length-1;
	int middle;
	found=false;
	while(last>=first&&!found)
	{
		middle=first+last/2;
		if(item<data[middle])
			last=middle-1;
		else if(item>data[middle])
			first=middle+1;
		else
			found=true;
	}
	if(found)
		position=middle;
}

void SortedList::Delete(ItemType item)
{
	bool found;
	int position;
	int index;
	BinSearchbyName(item,found,position);
	if(found)
	{
		for(index=position; index<length-1;index++)
			data[index]=data[index+1];
		length--;
		
	}

	
}
bool SortedList::IsPresent(ItemType item) const
{
	bool found;
	int position;
	BinSearchbyName(item,found,position);
	return found;	

}
void SortedList::Print() const
{
	

}


void main()
{
	ifstream inF;
	ofstream outF;
	SortedList	list;		//sorted list variable
	rectype info;			//rectype variable

	inF.open("a:/dir1.txt");
	if(!inF)
	{
		cout<<"Error! File not Found";
	}
	outF.open("a:/phonebook.txt");
	if(!outF)
	{
		cout<<"Error! File not Created";
	}

	

	int choice=0;
	while(choice!=999)
	{
        cout<<"Menu"<<endl;
        cout<<"1. Find the entry corresponding to a given last name"<<endl;
        cout<<"2. Display all the telephone directory information"<<endl;
		cout<<"3. Add a new entry to the directory"<<endl;
		cout<<"4. Delete an entry from the directory"<<endl;
		cout<<"5. Display all the persons name whose birthdays is in a               given month"<<endl;
		cout<<"6. Quit"<<endl;
		cout<<"Your selection is-->(1/2/3/4/5/6) "<<endl;
		cin>>choice;

	}
   
}

its not finished (the main and the whole program) because i can't fix that one mistake. If someone could gratiously help me out it would be appreciated, so confused.

--wb
  #2  
Old 01-Nov-2004, 16:03
dsmith's Avatar
dsmith dsmith is offline
Senior Member
 
Join Date: Jan 2004
Location: Utah, USA
Posts: 1,351
dsmith is a glorious beacon of lightdsmith is a glorious beacon of lightdsmith is a glorious beacon of lightdsmith is a glorious beacon of lightdsmith is a glorious beacon of light
Hi wbsquared03.

Please disregard if I am up in the night, but I don't believe that you can compare an entire structure with the standard comparison operators. Your program really doesn't know what you want to compare with what in this case.

CPP / C++ / C Code:


struct rectype
{
	string last;
	string first;
	char middle;
	string tel;
	string room;
	string month;
	string day;
	string year;

};


My solution would be to make a compare function (similar to strcmp) or do a class and try overload the comparison operators to work like you want.
  #3  
Old 01-Nov-2004, 17:02
wbsquared03 wbsquared03 is offline
New Member
 
Join Date: Oct 2004
Posts: 14
wbsquared03 is on a distinguished road
i think maybe i'll shoot myself instead of doing the program lol.........
  #4  
Old 01-Nov-2004, 17:18
dsmith's Avatar
dsmith dsmith is offline
Senior Member
 
Join Date: Jan 2004
Location: Utah, USA
Posts: 1,351
dsmith is a glorious beacon of lightdsmith is a glorious beacon of lightdsmith is a glorious beacon of lightdsmith is a glorious beacon of lightdsmith is a glorious beacon of light
Quote:
Originally Posted by wbsquared03
i think maybe i'll shoot myself instead of doing the program lol.........

No - Don't do that!

Really, the reccmp function should be very simple to write:

CPP / C++ / C Code:
int reccmp(ItemType record1, ItemType record2)
{
  //Program will compare the records
  //Return 0 if records are identical
  //Return 1 if record1 is greater than record2
  //Return -1 if record1 is less than record2
  //Currently written to compare by last name, first name and then middle initial

  if(record1.last > record2.last)
    return 1;
  if(record1.last < record2.last)
    return -1;
  //If the program got to here, then the last names are equal, start comparing first names.
  if(record1.first > record2.first)
    return 1;
  if(record1.first < record2.first)    
    return -1;
  //If the program got to here then the first names are equal, start comparing initials
  if(record1.middle > record2.middle)
    return 1;
  if(record1.middle < record2.middle)
    return -1;
  //If the program gets to here, the names are 100% identical!
  return 0;
}

That is thrown together very quickly, but it should give an idea how this works. It could probably be written more efficiently and with a single exit point (Waltp would hate it ), but it works.

Does that make sense?
  #5  
Old 01-Nov-2004, 21:42
wbsquared03 wbsquared03 is offline
New Member
 
Join Date: Oct 2004
Posts: 14
wbsquared03 is on a distinguished road
Quote:
Originally Posted by dsmith
No - Don't do that!

That is thrown together very quickly, but it should give an idea how this works. It could probably be written more efficiently and with a single exit point (Waltp would hate it ), but it works.

Does that make sense?

It makes sense but unfortunatly i will have to look at it later, i didn't get around to the boards again until what is now about 11:30 and i have an 8am class with required attendance. My prof should understand and hopefully give me more time to explore this program, and if not, i wrote most of the program just had trouble with the comparing, and when he sees that i should hopefully get a decent amount of credit ??: if not i pretty much have an average of about 90-95 in the class. So hopefully everything is chill

thanks for the help, much is appreciated as always.
  #6  
Old 01-Nov-2004, 23:10
WaltP's Avatar
WaltP WaltP is offline
Outstanding Member
 
Join Date: Feb 2004
Location: Midwest US
Posts: 3,234
WaltP is a name known to allWaltP is a name known to allWaltP is a name known to allWaltP is a name known to allWaltP is a name known to allWaltP is a name known to all
Quote:
Originally Posted by dsmith
It could probably be written more efficiently and with a single exit point (Waltp would hate it ), but it works.
I only hate things I feel strongly about -- I recommend one exit point, but I'm definitely not anal about it... I do it myself sometimes.

But making a function just to call a function...
__________________

Cow: You're a lawyer too?
Mooseblood (mosquito): Ma'am, I was already a bloodsucking parasite. All I needed was a briefcase!
 
 

Recent GIDBlogLast Week of IA Training by crystalattice

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
CD burner will not burn, new problem sdshaman Computer Hardware Forum 4 06-Feb-2008 23:17
Apache2 config issues monev Apache Web Server Forum 2 28-Jun-2004 06:19
Can't view pages from another machine on the Intranet aevans Apache Web Server Forum 9 14-May-2004 02:26
Another FX 5600 problem (but with details that might shed light on this) BobDaDuck Computer Hardware Forum 2 16-Apr-2004 07:53
problem with php5 cgi installation fab13 Apache Web Server Forum 3 19-Nov-2003 09:11

Network Sites: GIDNetwork · GIDWebHosts · GIDSearch · Learning Journal by J de Silva, The

All times are GMT -6. The time now is 00:53.


vBulletin, Copyright © 2000 - 2008, Jelsoft Enterprises Ltd.