Question

Write a program that keeps track of a speakers’ bureau. The program should use a structure...

Write a program that keeps track of a speakers’ bureau. The program should use a structure to store the following data about a speaker: (this is in C++)
Name
Telephone Number
Speaking Topic
Fee Required

The program should use a vector of structures. It should let the user enter data into the vector, change the contents of any element, and display all the data stored in the vector. The program should have a menu-driven user interface.

Input Validation: When the data for a new speaker is entered, be sure the user enters data for all the fields and No negative amounts should be entered for a speaker’s fee.

In addition: add a function to the program that allows the user to search for a speaker on a particular topic. It should accept a key word as an argument then search the vector for a structure with that key word in the Speaking Topic field. All structures that match should be displayed. If no structure matches, a message saying so should be displayed.

Hint: use the .find() string function to search the Speaking Topic field.

0 0
Add a comment Improve this question Transcribed image text
Answer #1

C++ Program:

#include <iostream>
#include <vector>
#include <string>

using namespace std;

//Structure representing Speaker
struct Speaker
{
string name;
string telphoneNumber;
string topic;
double fee;
};

//Array of struct objects
vector<struct Speaker> speakersArr;

//Variable to hold number of speakers
int speakerCnt=0;

//Menu
int menu()
{
int ch;

//Printing menu
cout << " 1 - Add Speaker 2 - Edit Speaker 3 - Search Speaker 4 - Print All 5 - Exit Your Option: ";
cin >> ch;

return ch;
}

//Adding speaker
void addSpeaker()
{
struct Speaker temp;

//Reading info from user
cout << " Enter speaker name: ";
cin >> temp.name;

cout << " Enter Telephone Number: ";
cin >> temp.telphoneNumber;

cout << " Enter speaking topic: ";
cin >> temp.topic;

//Avoiding negative values
do
{
cout << " Enter fee: ";
cin >> temp.fee;
}while(temp.fee < 0);

//Adding to list
speakersArr.push_back(temp);

//Incrementing speaker count
speakerCnt += 1;
}

//Editing speaker
void editSpeaker()
{
string name;
int i, index=-1;

//Reading info from user
cout << " Enter speaker name: ";
cin >> name;

//Searching for speaker
for(i=0; i<speakerCnt; i++)
{
//Comparing names
if(strcmp(speakersArr.at(i).name.c_str(), name.c_str()) == 0)
{
//Updating index
index = i;
}
}

if(index == -1)
{
cout << " Speaker not found... ";
}
else
{
//Updating data
cout << " Enter Telephone Number: ";

cin >> (speakersArr.at(index)).telphoneNumber;

cout << " Enter speaking topic: ";
cin >> speakersArr.at(index).topic;

//Avoiding negative values
do
{
cout << " Enter fee: ";
cin >> speakersArr.at(index).fee;
}while(speakersArr.at(index).fee < 0);

cout << " Updated Successfully.... ";
}
}

//Printing speaker
void searchSpeaker()
{
string topicS;
int i, index=-1;

//Reading info from user
cout << " Enter speaking topic: ";
cin >> topicS;

//Searching for speaker
for(i=0; i<speakerCnt; i++)
{
//Comparing names
if((speakersArr.at(i).topic).find(topicS) == 0)
{
//Printing data
cout << " Name: " << speakersArr.at(i).name;
cout << " Telephone Number: " << speakersArr.at(i).telphoneNumber;
cout << " Speaking topic: " << speakersArr.at(i).topic;
cout << " Fee: " << speakersArr.at(i).fee;
}
}
}

//Printing all speaker's
void printAll()
{
int i;

//Searching for speaker
for(i=0; i<speakerCnt; i++)
{
//Printing data
cout << " Speaker Name: " << speakersArr.at(i).name;
cout << " Telephone Number: " << speakersArr.at(i).telphoneNumber;
cout << " Speaking topic: " << speakersArr.at(i).topic;
cout << " Fee: " << speakersArr.at(i).fee << " ";
}
}

//Main function
int main()
{
int option;

while(1)
{
//Printing menu
option = menu();

//Calling appropriate function
switch(option)
{
case 1: addSpeaker(); break;
case 2: editSpeaker(); break;
case 3: searchSpeaker(); break;
case 4: printAll(); break;
case 5: exit(0);
default: cout << " Invalid option... "; break;
}
}

cout << " ";
return 0;
}

_______________________________________________________________________________________________________

Sample Run:

Add a comment
Know the answer?
Add Answer to:
Write a program that keeps track of a speakers’ bureau. The program should use a structure...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • Write a program (C++) that shows Game sales. The program should use a structure to store...

    Write a program (C++) that shows Game sales. The program should use a structure to store the following data about the Game sale: Game company Type of Game (Action, Adventure, Sports etc.) Year of Sale Sale Price The program should use an array of at least 3 structures (3 variables of the same structure). It should let the user enter data into the array, change the contents of any element and display the data stored in the array. The program...

  • Write a program that uses a structure to store the following data about a customer account: Name Address City, sta...

    Write a program that uses a structure to store the following data about a customer account: Name Address City, state, and ZIP Telephone number Account Balance Date of last payment The program should use an vector of at least 20 structures. It should let the user enter data into the vector, change the contents of any element, and display all the data stored in the array. The program should have a menu-driven user interface. Input Validation: When the data for...

  • Write a complete C++ program that will: Declare a vector of integers Use a pointer to...

    Write a complete C++ program that will: Declare a vector of integers Use a pointer to dynamically allocate an array of 10 elements Ask the user how many values they would like to have in the data structures Read in the user’s response and make sure that it is greater than 20 (error loop) Generate the number of integers that the user asked for and store them into both data structures. The integer values should be unique unordered values (no...

  • Customer Accounts This program should be designed and written by a team of students. Here are...

    Customer Accounts This program should be designed and written by a team of students. Here are some suggestions: Write a program that uses a structure to store the following information about a customer account: • Name • Address • City, state, and ZIP • Telephone number • Account balance • Date of last payment The structure should be used to store customer account records in a file. The program should have a menu that lets the user perform the following...

  • Written in C++ language Write a program that keeps track of a telephone directory. The program...

    Written in C++ language Write a program that keeps track of a telephone directory. The program should create a structure, Person, with the following data: struct Person { string firstName; string lastName; string phoneNumber; }; The program should then create a vector of Person structs, called directory. Your program should have functions to: - Read the vector data from a data file “telephoneData.txt” into the vector directory. - Print the details of all Persons in the vector. You may use...

  • Write a Python program that keeps reading in names from the user, until the user enters...

    Write a Python program that keeps reading in names from the user, until the user enters 0. Once the user enters 0, you should print out all the information that was entered by the user. Use this case to test your program: Input: John Marcel Daisy Samantha Nelson Deborah 0 ================ Output: John Marcel Daisy 25 Samantha Nelson Deborah Hints: Create an array Names to hold the input names. Use the Names.append(x) function to add a new name to the...

  • In C++ 1. Write a program that allows a user to enter 10 integer values from...

    In C++ 1. Write a program that allows a user to enter 10 integer values from the keyboard. The values should be stored in an array. 2. The program should then ask the user for a number to search for in the array: The program should use a binary search to determine if the number exists in a list of values that are stored in an array (from Step #1). If the user enters a number that is in the...

  • C++ ONLY The question is - The US Census Bureau gathers population information and aggregates it...

    C++ ONLY The question is - The US Census Bureau gathers population information and aggregates it at the city, county and state level. A research project on population distribution in the Southeast US has acquired a data file from the Census Bureau that contains the populations of each county in Mississippi (MS) and Florida (FL). For this research project write a program that calculates the average county population for these two states. Each line in the Census Bureau data file...

  • please use C++ write a program to read a textfile containing a list of books. each...

    please use C++ write a program to read a textfile containing a list of books. each line in the file has tile, ... Question: Write a program to read a textfile containing a list of books. each line in the file has tile, ..... write a program to read a textfile containing a list of books. each line in the file has tile, ... Question: Write a program to read a textfile containing a list of books. Each line in...

  • C++ and Using Microsoft Visual Studio. Write 2 programs: One program will use a structure to...

    C++ and Using Microsoft Visual Studio. Write 2 programs: One program will use a structure to store the following data on a company division: Division Name (East, West, North, and South) Quarter (1, 2, 3, or 4) Quarterly Sales The user should be asked for the four quarters' sales figures for the East, West, North, and South divisions. The data for each quarter for each division should be written to a file. The second program will read the data written...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT