Using C++, Write a program that keeps track of a speakers\' bureau. Name the str
ID: 3864166 • Letter: U
Question
Using C++,
Write a program that keeps track of a speakers' bureau. Name the structure “SpeakerBureau”. The program should use a structure to store the following data about a speaker:
Name (string, not c-string, the name may contain a space to separate first name and last name)
Telephone number (string, with ‘-‘ inside. The format should be 3 digits dash 4 digits)
Speaking topic (string, the topic may contain space)
Fee required (double, the number should be more than 0)
Your program should create a structure and have the following organization and menu choices. Use an inside loop to display all names stored, and an outside loop to allow the user to repeatedly choose from the following menu choices:
1) enter a speaker [ask user for an index number and allow entry of all data]
2) view a speaker’s info [ask user for an index number and display all data on that speaker]
3) display a count of how many speakers are in the list
4) quit
Functions:
To start with, you need the following variables in main:
int choice;
int size = 20;
SpeakBureau * speakers;
speakers = new SpeakBureau[size]; // make sure to free the memory when finished
void initializeValue(SpeakBureau * speakers, int size)
This function will initialize all string member variables to be “-“ and numerical member variables to be 0
string getName()
This function will take user’s input as the speaker’s name. User’s name should contain a space in the middle (not the first character or last character), User’s name should also begin with an upper case letter
int getChoice()
This function will display the menu and ask user to enter a menu option 1-4. No numbers other than 1-4 should be accepted.
string getPhoneNumber()
This function will prompt user to enter a phone number in the format of “111-1111”, where there should be 3 digits and a dash and another four digits.
double getFee()
This function will prompt user to enter a fee that is more or equal to 0
void enterSpeaker(SpeakBureau * speakers)
This function will prompt user to enter an index value to the speakers’ array, and allow user to enter speakers’ information to that index. Notice, if there is already a speaker stored at the index, prompt user to enter the index again.
Once a correct index has been entered, prompt user to enter a speaker’s name, phone number, topic and fee. (call getPhoneNumber and getFee function mentioned above)
Hint! You need cin.ignore()in this function.
void viewSpeaker(SpeakBureau * speakers)
This function will prompt user to enter an index value to the speakers’ array, and display the speaker’s information stored on that index. Display an error message and prompt user to enter again if the index entered is out of range or does not have a speaker on that index.
int countSpeaker(SpeakBureau * speakers, int size)
This function will display the number of speakers in the array, (notice, name “-“ doesn’t count as a “real” speaker)
Feel free to add more functions if needed
Sample Output:
************************************************************
1) enter a speaker
2) view a speaker info
3) display a count of how many speakers are in the list
4) quit
Please enter a choice: 1
Please enter an index to add the speaker: -9
!!!Error. Index out of range
Please enter an index to add the speaker: 1
Please enter the speaker's information:
Speaker name: John Doe
Phone number: Phone number: 12345
!!!Error. Incorrect format! Enter again
Phone number: 123-4567
Topic: C++
Fee: 0
************************************************************
1) enter a speaker
2) view a speaker info
3) display a count of how many speakers are in the list
4) quit
Please enter a choice: 1
Please enter an index to add the speaker: 9
Please enter the speaker's information:
Speaker name: Jane Doe
Phone number: Phone number: 456
!!!Error. Incorrect format! Enter again
Phone number: 456-7890
Topic: Programming II
Fee: 100
************************************************************
1) enter a speaker
2) view a speaker info
3) display a count of how many speakers are in the list
4) quit
Please enter a choice: 2
Please enter an index to view the speaker 1
Name: John Doe
Number: 123-456
Topic: C++
Fee: 0
************************************************************
1) enter a speaker
2) view a speaker info
3) display a count of how many speakers are in the list
4) quit
Please enter a choice: 2
Please enter an index to view the speaker 0
!!!Error. There is no speaker at that index
Please enter an index to view the speaker 9
Name: Jane Doe
Number: 456-7890
Topic: Programming II
Fee: 100
************************************************************
1) enter a speaker
2) view a speaker info
3) display a count of how many speakers are in the list
4) quit
Please enter a choice: 3
There are 2 speakers
************************************************************
1) enter a speaker
2) view a speaker info
3) display a count of how many speakers are in the list
4) quit
Please enter a choice: 4
Over!
It is imperative that you follow the directions above and be sure your output matches the output above. Please include a screen cap of your output and make sure it is identical to the sample output above.
void initializeValue(SpeakBureau * speakers, int size)
This function will initialize all string member variables to be “-“ and numerical member variables to be 0
string getName()
This function will take user’s input as the speaker’s name. User’s name should contain a space in the middle (not the first character or last character), User’s name should also begin with an upper case letter
int getChoice()
This function will display the menu and ask user to enter a menu option 1-4. No numbers other than 1-4 should be accepted.
string getPhoneNumber()
This function will prompt user to enter a phone number in the format of “111-1111”, where there should be 3 digits and a dash and another four digits.
double getFee()
This function will prompt user to enter a fee that is more or equal to 0
void enterSpeaker(SpeakBureau * speakers)
This function will prompt user to enter an index value to the speakers’ array, and allow user to enter speakers’ information to that index. Notice, if there is already a speaker stored at the index, prompt user to enter the index again.
Once a correct index has been entered, prompt user to enter a speaker’s name, phone number, topic and fee. (call getPhoneNumber and getFee function mentioned above)
Hint! You need cin.ignore()in this function.
void viewSpeaker(SpeakBureau * speakers)
This function will prompt user to enter an index value to the speakers’ array, and display the speaker’s information stored on that index. Display an error message and prompt user to enter again if the index entered is out of range or does not have a speaker on that index.
int countSpeaker(SpeakBureau * speakers, int size)
This function will display the number of speakers in the array, (notice, name “-“ doesn’t count as a “real” speaker)
Feel free to add more functions if needed
Explanation / Answer
#include <iostream>
#include <string>
#include <iomanip>
using namespace std;
struct speaker
{
string name;
string TelephoneNumber;
string SpeakTopic;
int fee;
};
void getSpeaker(speaker *);
void printSpeaker(speaker *);
void editSpeaker(speaker *);
void searchSpeakTopic(speaker*);
int main()
{
int NUM_SPEAKERS = 10;
int index;
speaker info[10];
int menu;
const int enter = 1,
change = 2,
print = 3,
search = 4,
leave = 5;
do{
cout << "Please select a choice from the menu. "
<< "1) Enter Speaker Information. "
<< "2) Change Speaker Information. "
<< "3) Print Speaker Information. "
<< "4) Search for Topic. "
<< "5) Leave this menu. "
<< "Select: ";
cin >> menu;
switch (menu)
{
case enter:
{
getSpeaker(info);
}
break;
case change:
{
editSpeaker(info);
}
break;
case print:
{
printSpeaker(info);
}
break;
case search:
{
searchSpeakTopic(info);
}
}
} while (menu != leave);
system("pause");
return 0;
}
void getSpeaker(speaker *p) //array name = pointer
{
int i = 0;
int size = 10;
for (i = 0; i < size; i++)
{
cout << "Please enter the following information of speaker " << i << " : ";
cout << "Speaker Name:";
cin.ignore();
getline(cin, p[i].name);
cout << " Speaker Telephone Number:";
cin.ignore();
getline(cin, p[i].TelephoneNumber);
cout << " Speaker Topic:";
cin.ignore();
getline(cin, p[i].SpeakTopic);
cout << " Fee Required:";
cin >> p[i].fee;
}
}
void printSpeaker(speaker *p)
{
int i = 0;
int size = 10; // Array size
for (i = 0; i < size; i++)
{
cout << "The information entered for each speaker is: ";
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(speaker *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: ";
cout << "Speaker Name:";
cin.ignore();
getline(cin, p[i].name);
cout << " Speaker Telephone Number:";
getline(cin, p[i].TelephoneNumber);
cout << " Speaker Topic:";
getline(cin, p[i].SpeakTopic);
cout << " Fee Required:";
cin >> p[i].fee;
}
else
{
cout << "Please pick a number between 0-9" << endl;
}
}
void searchSpeakTopic(speaker*p)
{
int i = 0;
int topic;
cout << " Please type a topic in the program" << endl;
cin >> topic;
}
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.