// Elaine Torrez #10
#include <iostream>
#include <iomanip>
#include <string>
#include <algorithm>
using namespace std;
const int NUM_SPEAKERS = 10;
// ------------------------------------------------------------
// Structure for one speaker
// ------------------------------------------------------------
struct Speaker {
string name;
string phone;
string topic;
double fee;
};
// ------------------------------------------------------------
// Function prototypes
// ------------------------------------------------------------
void displayMenu();
void editSpeaker(Speaker[]);
void displayAll(const Speaker[]);
void searchTopic(const Speaker[]);
int main()
{
Speaker speakers[NUM_SPEAKERS] = {}; // initialize empty data
int choice;
do {
displayMenu();
cin >> choice;
cin.ignore(); // clear leftover newline
switch (choice) {
case 1:
editSpeaker(speakers);
break;
case 2:
displayAll(speakers);
break;
case 3:
searchTopic(speakers);
break;
case 4:
cout << "Exiting program.\n";
break;
default:
cout << "** ERROR: Invalid choice. Try again.\n";
}
} while (choice != 4);
return 0;
}
// ------------------------------------------------------------
// Displays the main menu
// ------------------------------------------------------------
void displayMenu()
{
cout << "\nSPEAKERS BUREAU MENU\n";
cout << "1. Enter or Edit a Speaker\n";
cout << "2. Display All Speakers\n";
cout << "3. Search by Topic\n";
cout << "4. Quit\n";
cout << "Enter your choice: ";
}
// ------------------------------------------------------------
// Add/Edit one speaker
// ------------------------------------------------------------
void editSpeaker(Speaker s[])
{
int index;
cout << "Enter speaker index (0–9): ";
cin >> index;
cin.ignore();
while (index < 0 || index >= NUM_SPEAKERS) {
cout << "**ERROR** Index must be 0–9: ";
cin >> index;
cin.ignore();
}
cout << "Enter name: ";
getline(cin, s[index].name);
cout << "Enter phone number: ";
getline(cin, s[index].phone);
cout << "Enter speaking topic: ";
getline(cin, s[index].topic);
cout << "Enter fee: ";
cin >> s[index].fee;
while (s[index].fee < 0) {
cout << "**ERROR** Fee cannot be negative. Enter again: ";
cin >> s[index].fee;
}
cout << "Speaker updated.\n";
}
// ------------------------------------------------------------
// Displays all speakers
// ------------------------------------------------------------
void displayAll(const Speaker s[])
{
cout << "\nALL SPEAKERS:\n";
cout << "---------------------------------------------\n";
for (int i = 0; i < NUM_SPEAKERS; i++) {
if (!s[i].name.empty()) {
cout << "Index : " << i << endl;
cout << "Name : " << s[i].name << endl;
cout << "Phone : " << s[i].phone << endl;
cout << "Topic : " << s[i].topic << endl;
cout << "Fee : $" << fixed << setprecision(2) << s[i].fee << endl;
cout << "---------------------------------------------\n";
}
}
}
// ------------------------------------------------------------
// SEARCH FUNCTION (Programming Challenge 10)
// Finds speakers by topic keyword (case-insensitive)
// ------------------------------------------------------------
void searchTopic(const Speaker s[])
{
string keyword;
bool found = false;
cout << "\nEnter a topic keyword to search for: ";
cin.ignore(numeric_limits<streamsize>::max(), '\n'); // ensure clean input
getline(cin, keyword);
// Convert keyword to lowercase for case-insensitive matching
string keyLower = keyword;
transform(keyLower.begin(), keyLower.end(), keyLower.begin(), ::tolower);
cout << "\nSEARCH RESULTS for \"" << keyword << "\":\n";
cout << "---------------------------------------------\n";
for (int i = 0; i < NUM_SPEAKERS; i++) {
if (!s[i].topic.empty()) {
string topicLower = s[i].topic;
transform(topicLower.begin(), topicLower.end(), topicLower.begin(), ::tolower);
// Check if the keyword exists inside the topic
if (topicLower.find(keyLower) != string::npos) {
found = true;
cout << "Index : " << i << endl;
cout << "Name : " << s[i].name << endl;
cout << "Phone : " << s[i].phone << endl;
cout << "Topic : " << s[i].topic << endl;
cout << "Fee : $" << s[i].fee << endl;
cout << "---------------------------------------------\n";
}
}
}
if (!found) {
cout << "No speakers found with that topic.\n";
}
}