Sno Kart
December 15th, 2002, 11:05 AM
I have included a rough example for purposes of illistration.
I want to look up an item based on the key in the map and search through the linked list.....help...there is a problem with the declaration.
Thank you for your time and effort.
#include <iostream>
#include <map>
#include <list>
#include <string>
using namespace std;
class book
{
public:
string author;
long ISBN;
float price;
};
using namespace std;
void main() {
book bk;
list<book> record;
list<book>::const_iterator iter1;
//here is the problem.............................
map<book,record> track;//why doesn't this work????
//I wnat a map of linked lists....HELP!
for(int j = 0; j < 3; j++)
{
cout<<"Enter author,isbn,and price"<<endl;
cin>>bk.author;
cin>>bk.ISBN;
cin>>bk.price;
record.push_back(bk);
}
float search;
cout<<"Enter Price to search for"<<endl;
cin>>search;
for(iter1 = record.begin();iter1 != record.end(); iter1++)
{
if((*iter1).price == search )
{
cout<<bk.author<<" "<<bk.ISBN<<" "<<bk.price<<endl;
}
}
//this is a working portion of map example
map<string, int> freq;
string word;
for(int i = 0; i < 3; i++)
{cout<<"enter words for mapping"<<endl;
cin >> word;
freq[word]++;
}
cout << "Number of words = " << freq.size() << endl;
map<string, int>::const_iterator iter;
for (iter=freq.begin(); iter != freq.end(); iter++)
{
cout << iter->second << " " << iter->first << endl;
if(iter->second == 4)
{
freq[word]--;
cout << iter->second << " " << iter->first << endl;
}
}
}//end main
I want to look up an item based on the key in the map and search through the linked list.....help...there is a problem with the declaration.
Thank you for your time and effort.
#include <iostream>
#include <map>
#include <list>
#include <string>
using namespace std;
class book
{
public:
string author;
long ISBN;
float price;
};
using namespace std;
void main() {
book bk;
list<book> record;
list<book>::const_iterator iter1;
//here is the problem.............................
map<book,record> track;//why doesn't this work????
//I wnat a map of linked lists....HELP!
for(int j = 0; j < 3; j++)
{
cout<<"Enter author,isbn,and price"<<endl;
cin>>bk.author;
cin>>bk.ISBN;
cin>>bk.price;
record.push_back(bk);
}
float search;
cout<<"Enter Price to search for"<<endl;
cin>>search;
for(iter1 = record.begin();iter1 != record.end(); iter1++)
{
if((*iter1).price == search )
{
cout<<bk.author<<" "<<bk.ISBN<<" "<<bk.price<<endl;
}
}
//this is a working portion of map example
map<string, int> freq;
string word;
for(int i = 0; i < 3; i++)
{cout<<"enter words for mapping"<<endl;
cin >> word;
freq[word]++;
}
cout << "Number of words = " << freq.size() << endl;
map<string, int>::const_iterator iter;
for (iter=freq.begin(); iter != freq.end(); iter++)
{
cout << iter->second << " " << iter->first << endl;
if(iter->second == 4)
{
freq[word]--;
cout << iter->second << " " << iter->first << endl;
}
}
}//end main