I'm working on this program for homework an here is the problem:
Write a program that keeps track of a speakers bureau. The program should use a structure to store the following data about a speaker.
Name
Telephone Number
Speaking Topic
Fee required
The program should use an array of at least 10 structures.It should let the user enter data into the array, change the contents of any element, and display all the data stored in the array. The program should have a menu-driven user interface.
So I did the program which is below but now it is asking this:
Add a function that allows the user to search for a speaker on a particular topic. It should accept a key word as an argument and then search the array for a structure with that key word in the searching topic field. All structures that match should be displayed. If no structure matches, a message saying so should be displayed.
Now this where I get stuck, I'm having trouble figuring out how to write down the search function in this program. A function that can work and how to get it to match the topics listed by each speaker.
int i = 0;
int size = 10;
for (i = 0; i < size; i++)
{
cout << "Please enter the following information of speaker " << i << " : \n";
cout << "Speaker Name:";
cin.ignore();
getline(cin, p[i].name);
cout << "\nSpeaker Telephone Number:";
cin.ignore();
getline(cin, p[i].TelephoneNumber);
cout << "\nSpeaker Topic:";
cin.ignore();
getline(cin, p[i].SpeakTopic);
cout << "\nFee Required:";
cin >> p[i].fee;
}
}
void printSpeaker(speakerBureau *p)
{
int i = 0;
int size = 10; // Array size
for (i = 0; i < size; i++)
{
cout << "The information entered for each speaker is: \n";
cout << "Speaker " << i << endl;
cout << "Speaker Name: " << p[i].name << endl;
cout << "Speaker Telephone Number: " << p[i].TelephoneNumber << endl;
cout << "Speaker Topic: " << p[i].SpeakTopic << endl;
cout << "Speaker Fee Required: " << p[i].fee << endl;
}
}
void editSpeaker(speakerBureau *p)
{
int i;
cout << "Please enter the number of the speaker you would like to edit."
<< endl;
cin >> i;
if (i <= 9)
{
cout << endl;
cout << "Please enter the updated information of the speaker: \n";
cout << "Speaker Name:";
cin.ignore();
getline(cin, p[i].name);
cout << "\nSpeaker Telephone Number:";
getline(cin, p[i].TelephoneNumber);
cout << "\nSpeaker Topic:";
getline(cin, p[i].SpeakTopic);
cout << "\nFee Required:";
cin >> p[i].fee;
}
else
{
cout << "Please pick a number between 0-9" << endl;
}
}
void searchSpeakTopic(speakerBureau*p)
{
int i = 0;
int topic;
cout << " Please type a topic in the program" << endl;
void searchSpeakTopic(speakerBureau p[]) // original is okay, just want to emphasize that p is an array
{
string topic;
cout << " Please type a topic (case sensitive) in the program" << endl;
cin >> topic;
bool speakerFound = false;
for (int i = 0; i < sizeof(p) / sizeof(p[0]); ++i)
{
if (p[i].SpeakTopic.find(topic) != string::npos)
{
speakerFound = true;
printSpeaker(&(p[i]));
}
}
if (!speakerFound)
{
cout << "No speakers spoke about " << topic << endl;
}
}
In main, you'd call it like searchSpeakTopic(info);
I didn't compile this, so don't know if I made any mistakes, it's just to give a rough idea.
it appears that it can run through fine in he program but when i type in a topic it said's no one spoke about it but one of the speakers did so it still won't read it.