Question

In: Computer Science

Starting out with Control Structures: Program challenges in C++ by Tony Gaddis This problem was adapted...

Starting out with Control Structures: Program challenges in C++ by Tony Gaddis

This problem was adapted from questions 9 and 10 on page 661

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 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. 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.

Solutions

Expert Solution

#include <iostream>
#include<vector>
using namespace std;

struct Speaker{
   string name;
   string phone;
   string topic;
   double fee;

   //constructor
   Speaker(string n, string p , string t, double f){
       name = n;
       phone = p;
       topic = t;
       fee = f;
   }
};

void print(Speaker s){
    cout << "Name : " << s.name << endl;
    cout << "Telephone Number : " << s.phone << endl;
    cout << "Speaking Topic : " << s.topic << endl;
    cout << "Speaking fee : " << s.fee << endl;
    cout << endl;
}

int main() {
    vector<Speaker> v;
   while(true){
       char ch;
       cout << "Press c to continue or any other key to exit" << endl;
       cin >> ch;
       if(ch != 'c'){
           return 0;
       }
       cout << "Enter 1 to add a speaker or 2 to search the list of all speakers" << endl;
       int choice;
       cin >> choice;

       while(choice != 1 && choice != 2){
           cout << "Please enter the correct choice" << endl;
           cout << "Enter 1 to add speaker or 2 to view the list of all speakers" << endl;
           cin >> choice;
       }
       if(choice == 1){

           cout << "Enter name of speaker" << endl;
           string name = "";
           cin >> name;
           while(name == ""){
               cout << "please enter a valid name" << endl;
               cin >> name;
           }

           cout << "Enter telephone number of speaker" << endl;
           string phone = "";
           cin >> phone;
           while(phone == ""){
               cout << "please enter a valid telephone number" << endl;
               cin >> phone;
           }

           cout << "Enter the speaking topic of speaker" << endl;
           string topic = "";
           cin >> topic;
           while(topic == ""){
               cout << "please enter a valid topic" << endl;
               cin >> topic;
           }

           cout << "Enter speaking fee of speaker" << endl;
           double fee;
           cin >> fee;
           while(fee < 0){
               cout << "please enter a non negative fee" << endl;
               cin >> fee;
           }

           Speaker newEntry(name,phone,topic,fee);
           v.push_back(newEntry);
       }
       else{
            cout << "Enter topic to search" << endl;
            string query;
            cin >> query;
            cout << "Speakers that match are : " << endl;
            bool flag = false; // to check if any matches or not
            for(int i = 0 ; i < v.size() ; i++){
                Speaker s = v[i];
                if(s.topic == query){
                    flag = true;
                    print(s);
                }
            }
            if(!flag)
                cout << "None" << endl;

       }
   }

   return 0;
}


Out


Related Solutions

Tony Gaddis C++ Tic-Tac-Toe Write a program that allows two players (player X and player O)...
Tony Gaddis C++ Tic-Tac-Toe Write a program that allows two players (player X and player O) to play a game of tic-tac-toe. Use a two- dimensional char array with three rows and three columns as the game board. Each element of the array should be initialized with an asterisk (*). The players take turns making moves and the program keeps track of whose turn it is. Player X moves first. The program should run a loop that: Displays the contents...
Tony Gaddis C++ Conference Sessions An upcoming conference about C/C++ programming has three sessions planned: -...
Tony Gaddis C++ Conference Sessions An upcoming conference about C/C++ programming has three sessions planned: - A session on the new features of C++ 17 - A session on functional programming in C/C++ - A session on lamda functions Attendees can subscribe for any session. The organizers want to keep track of which attendees are attending which session. Write a program that stores this information in a two-dimensional array of Booleans, where each row represents an attendee and each column...
Tony Gaddis C++ Monkey Business A local zoo wants to keep track of how many pounds...
Tony Gaddis C++ Monkey Business A local zoo wants to keep track of how many pounds of food each of its three monkeys eats each day during a typical week. Write a program that stores this information in a two-dimensional 3 × 7 array, where each row represents a different monkey and each column represents a different day of the week. The monkeys are represented by integers 1, 2, and 3; the weekdays are "Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday",...
C++ Tony Gaddis 8.11: Using Files-- String Selection Sort Modification Modify the selectionSort function presented in...
C++ Tony Gaddis 8.11: Using Files-- String Selection Sort Modification Modify the selectionSort function presented in this chapter so it sorts an array of strings instead of an array of ints. Test the function with a driver program that reads an integer, N, from standard input and then reads the first N strings from a file called href="asfunction:_root.doTutor,7,CPP">names. (Assume that N is less than or equal to 20.) Input Validation. If N read in from standard input is greater than...
(Gaddis) Programming Challenges 8. Search Function for Customer Accounts Program Program pág. 653, Cap. 11 Instruction:...
(Gaddis) Programming Challenges 8. Search Function for Customer Accounts Program Program pág. 653, Cap. 11 Instruction: Add the exercise 1 to the program provided. .1. Search Function for Customer Accounts Program Add a function to Programming Challenge 7 that allows the user to search the structure array for a particular customer’s account. It should accept part of the customer’s name as an argument and then search for an account with a name that matches it. All accounts that match should...
Module/Week 3 ASSIGNMENT (CONTROL STRUCTURES . IF ..ELSE) Write a C++ program that computes a student’s...
Module/Week 3 ASSIGNMENT (CONTROL STRUCTURES . IF ..ELSE) Write a C++ program that computes a student’s grade for an assignment as a percentage given the student’s score and total points. The final score must be rounded up to the nearest whole value using the ceil function in the <cmath> header file. You must also display the floating-point result up to 5 decimal places. The input to the program must come from a file containing a single line with the score...
1.Write a C++ program using control structures, arrays, functions to calculate the number of dollars, quarters,...
1.Write a C++ program using control structures, arrays, functions to calculate the number of dollars, quarters, dimes, nickels, and pennies in a given amount of money. The input should be a floating-point value representing a decimal value. Example: 63.87 à 63 [dollars and 87 cents] should output 63 dollars, 3 quarters, 1 dime, 0 nickels, and 2 pennies. 2. In trigonometry the cosine function can be calculated using cos(x) = 1 – x 2 /2! + x 4 /4!- x...
Objectives: Practice using selection structures within a complete C++ program to solve a problem. Be able...
Objectives: Practice using selection structures within a complete C++ program to solve a problem. Be able to understand and use linear interpolation in a program. Modify/Extend an existing program. Problem Description: Linear Interpolation There are two credit levels for this assignment. Completing the “B” level correctly is worth 16/20 points, completing the “A” level is worth 20/20. You are encouraged to get the code for the “B” level working first and then complete the “A” level if you have time/interest....
Develop and write a program in c/c++ that will find the first 100 primes (starting at...
Develop and write a program in c/c++ that will find the first 100 primes (starting at 1) and write them to a file named "primes.dat".
C Program and pseudocode for this problem. Write a C program that plays the game of...
C Program and pseudocode for this problem. Write a C program that plays the game of "Guess the number" as the following: Your program choose the number to be guessed by selecting an integer at random in the rang of 1 to 1000. The program then asks the use to guess the number. If the player's guess is incorrect, your program should loop until the player finally gets the number right. Your program keeps telling the player "Too High" or...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT