Jump to content

C++ Beginner Help

BlueSpartan

I am dipping my toes into the C++ waters and have come onto this challenge, but I'm stuck trying to come up with the missing code on this one. Any help would be appreciated. I'm getting to where I can usually read and follow along with a simple program but doing the construction myself is still difficult. One day at a time.

#include <iostream>
#include <string>
#include <iomanip>
using namespace std;

// Constants for array size
const int NUM_SPEAKERS = 20;

// Declaration of the Speaker structure
struct Speaker
{
                  // Speaker's name (string)
                 // Speaker's telephone number (string)
                 // Speaker's speaking topic (string)
                 // Speaker's fee for speaking (double)
};

// Function prototypes
void getInfo(Speaker &);
void showInfo(Speaker);
void showSearch(Speaker [], string, int);

int main()
{
   int maxSpeaker = 0, choice, spk;
   int count;
   string search;
   Speaker list[NUM_SPEAKERS];

   do
   {
      cout << "\n1. Enter new speaker information\n";
      cout << "2. Change speaker information\n";
      cout << "3. Display all speaker information\n";
      cout << "4. Search for a speaker\n";
      cout << "5. Exit the program\n\n";
      cout << "Enter your choice: ";
      cin >> choice;


      // Validate the menu choice.
      while (choice < 1 || choice > 5)
      {
         //Fill in code for while loop if the choice is invalid
      }

      // Process the user's choice.
      switch (choice)
      {
         // Enter new speaker information
         case 1:  
            cin.get();
            getInfo(list[maxSpeaker]);
            cout << "You have entered information for speaker ";
            cout << "number " << maxSpeaker << endl;
            maxSpeaker++;
            break;

         // Change speaker information
         case 2:  
            cout << "Speaker number: ";
            cin >> spk;
            
            // Validate input
            while (spk < 0 || spk >= maxSpeaker)
            {
               cout << "ERROR: Invalid Speaker Number\n";
               cin >> spk;
            }

            cin.get();
                                 //Call to function showinfo
                                 //Call to function getInfo
            break;

         // Display speaker information
         case 3:  
            cin.get();
            for (count = 0; count < maxSpeaker; count++)
            {
              //Write code for for loop to display speaker info
            }

         // Search for a speaker
         case 4:
            cin.get();
            cout << "Enter part of the speaker name: ";
            getline(cin, search);
            showSearch(list, search, maxSpeaker);
      }
   } while (choice != 5);

   return 0;
}

//*******************************************************
// Function getInfo                                     *
// This function gets the speaker info from the user,   *
// validates it, and stores it in the reference         *
// parameter s.                                         *
//*******************************************************
void getInfo(Speaker &s)
{
   // Get the speaker's name.
   cout << "\nSpeaker name: ";   
   getline(cin, s.name);
   while (s.name.empty())
   {
      cout << "Please enter a name: ";
      getline(cin, s.name);
   }
   
   // Use the section to get the speaker's name as an example.
   //Get the speaker's telephone number.


    // Use the section to get the speaker's name as an example.
    // Get the speaker's speaking topic.


    // Use the section to get the speaker's name as an example.
   // Get the speaker's fee.


   cin.get();
}

//*******************************************************
// Function showInfo                                    *
// This function displays the data stored in the        *
// parameter s.                                         *
//*******************************************************
void showInfo(Speaker s)
{
   cout << fixed << showpoint << setprecision(2);
   cout << "Speaker name: " << s.name << endl;
                                                    //display the telephone #
                                                    //display the speaking topic
                                                    //display the required fee
}
//*******************************************************
// Function showSearch                                  *
// The parameter s is an array of Speaker structures to *
// be searched. The parameter lookUp contains the       *
// string to search for. The paramater max indicates the*
// number of elements to search. If the string is found *
// in any of the array's elements, the members of the   *
// element are displayed.                               *
//*******************************************************
void showSearch(Speaker s[], string lookUp, int max)
{
   bool found = false;

   //add for loop to run through the items up to the max
 
    {
      if (s[count].name.find(lookUp) != -1)            //test to determine if the name is found
      {
         found = true;                                //set found to true
         showInfo(s[count]);
      }
   }
   
   if (!found)
        cout << "\nRecord not found\n";

    cout << "Press enter to continue...";
    cin.get();
}

 

Edited by wkdpaul
included code tag
Link to comment
Share on other sites

Link to post
Share on other sites

Are you asking us to do it for you? If not, please be more specific.

Don't ask to ask, just ask... please 🤨

sudo chmod -R 000 /*

Link to comment
Share on other sites

Link to post
Share on other sites

@BlueSpartan

 

I have edited your thread so that your code is in a code tag, please read the announcement pinned at the top ;

 

Quote

Please use CODE tag

 

When asking for help with programming issues, please use the code tags to enclose your code so that it is formatted correctly.

It makes things much more easily readable for the people trying to help you, thus improving your chances of actually getting help.
 

To add code tags, click the <> button on the editor toolbar, then enter your code in the code editor that appears.

 

If you need help with your forum account, please use the Forum Support form !

Link to comment
Share on other sites

Link to post
Share on other sites

17 hours ago, wkdpaul said:

@BlueSpartan

 

I have edited your thread so that your code is in a code tag, please read the announcement pinned at the top ;

 

 

Thank you my apologies.

Link to comment
Share on other sites

Link to post
Share on other sites

What is it specifically you need to know how to do, it looks like the members of that speaker struct definition need to be filled in. the comments tell you what the type needs to be and the names of the members.

 

in case 3 of a switch statement it asks you to print out to console the data in your speaker struct it appears.

 

the best advice i would give would be to read the comments thourally, the comments at the start of the methods defining what it does, write down bullet points of the main details, and go through, find where the missing code is, visualize what you would do in your known language and google the alternative in c++

 

good luck mate

Link to comment
Share on other sites

Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

×