Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Create a new function called InvalidSpeakerNumber with the information that\'s i

ID: 2247235 • Letter: C

Question

Create a new function called InvalidSpeakerNumber with the information that's in the copy constructor. Build code in main to test this new InvalidSpeakerNumber function and call the display() function to shows the user the information he entered.

/* * * * * *SPEAKERS.H * * * * * * * * * * * * */

#ifndef Speakers_hpp
#define Speakers_hpp
#include <iostream>
#include <string>
using namespace std;

template<class T>
class SpeakersBureau
{
private:
    T id, i, s;
    T name, sp;
    T sTopic;
    T fee;
    T telNo;
public:
    SpeakersBureau(){}                          //default constructor
    SpeakersBureau(T id,T n, T ph, T f, T to); //copy constructor
    ~SpeakersBureau();
    void display();                             //print info
    T getId();
    T getName();
    T getTelNo();
    T getTopic();
    T getFee();
};
#endif

/* * * * * *SPEAKERS.CPP * * * * * * * * * * * * */
template <class T>
SpeakersBureau<T>::SpeakersBureau(T id, T n, T ph, T f, T to)
{
    if((i<=999) && (i>=0))
    {
        id = i;
        name = n;
        telNo = ph;
        fee = f;
        sTopic = to;
    }
    else
        cout<<" Error: Invalid ID Number ";
}

template <class T>
SpeakersBureau<T>::~SpeakersBureau()
{
    delete [] this-> array;
}
template <class T>
void SpeakersBureau<T>::display()
{
    for(int i=0; i<s;i++) {
        cout << "Custumer's ID: " << sp[i].Id << endl;
        cout << "Custumer's Name: " << sp[i].name << endl;
        cout << "Telephone Number: " << sp[i].telNo << endl;
        cout << "Speaker’s Topic: " << sp[i].sTopic << endl;
        cout << "Fee Required: " << sp[i].fee << endl;
    }
}
template <class T>
T SpeakersBureau<T>::getId()
{
    return id;
}
      
template <class T>
T SpeakersBureau<T>::getName()
{
    return name;
}
      
template <class T>
T SpeakersBureau<T>::getTelNo()
{
    return telNo;
}

template <class T>
T SpeakersBureau<T>::getTopic()
{
    return sTopic;
}

template <class T>
T SpeakersBureau<T>::getFee()
{
    return fee;
}

/* * * * * * MAIN.CPP * * * * * * * * * * * * */

#include <iostream>
#include "Speakers.hpp"
using namespace std;

int main()
{
    // Create a Speakers object.
    SpeakersBureau<int> mySpeaker;
  
    // Get the ID
    cout << "Enter the speaker's ID: ";
    //cin

    cout << "End of the program. ";
    system("pause");
    return 0;
}

       

Explanation / Answer

/* * * * * *SPEAKERS.H * * * * * * * * * * * * */

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

template<class T>
class SpeakersBureau
{
private:
    T id, i, s;
    T name, sp;
    T sTopic;
    T fee;
    T telNo;
public:
    SpeakersBureau(){}                          //default constructor
    SpeakersBureau(T id,T n, T ph, T f, T to); //copy constructor
    ~SpeakersBureau();
    void display();                             //print info
    T getId();
    T getName();
    T getTelNo();
    T getTopic();
    T getFee();
    void InvalidSpeakerNumber(int i);
};

/* * * * * *SPEAKERS.CPP * * * * * * * * * * * * */
template <class T>
SpeakersBureau<T>::SpeakersBureau(T id, T n, T ph, T f, T to)
{
    if((i<=999) && (i>=0))
    {
        id = i;
        name = n;
        telNo = ph;
        fee = f;
        sTopic = to;
    }
    else
        InvalidSpeakerNumber(i);
}


template <class T>
void SpeakersBureau<T>::InvalidSpeakerNumber(int i) {
        cout<<" Error: Invalid ID Number: " << i << " ";
}

template <class T>
SpeakersBureau<T>::~SpeakersBureau()
{
    // delete [] this-> array; //there is no array in your code
}
template <class T>
void SpeakersBureau<T>::display()
{
    for(int i=0; i<s;i++) {
        cout << "Custumer's ID: " << sp[i].Id << endl;
        cout << "Custumer's Name: " << sp[i].name << endl;
        cout << "Telephone Number: " << sp[i].telNo << endl;
        cout << "Speaker’s Topic: " << sp[i].sTopic << endl;
        cout << "Fee Required: " << sp[i].fee << endl;
    }
}
template <class T>
T SpeakersBureau<T>::getId()
{
    return id;
}
      
template <class T>
T SpeakersBureau<T>::getName()
{
    return name;
}
      
template <class T>
T SpeakersBureau<T>::getTelNo()
{
    return telNo;
}

template <class T>
T SpeakersBureau<T>::getTopic()
{
    return sTopic;
}

template <class T>
T SpeakersBureau<T>::getFee()
{
    return fee;
}

/* * * * * * MAIN.CPP * * * * * * * * * * * * */

#include <iostream>

using namespace std;

int main()
{
    // Create a Speakers object.
    SpeakersBureau<int> mySpeaker;
    int id, n, ph, f, to;
    // Get the ID
    cout << "Enter the speaker's ID: ";
    cin >>id;
    cout << "Enter the speaker's n: ";
    cin >>n;
    cout << "Enter the speaker's ph: ";
    cin >> ph;
    cout << "Enter the speaker's f: ";
    cin>> f;
    cout << "Enter the speaker's to: ";
    cin >>to;

    SpeakersBureau<int> spk(id,n,ph,f,to);
    spk.display();

    cout << "End of the program. ";
    //system("pause"); //cygwin does not support this
    return 0;
}

NOTE: YOUR code contains error. sp is not an array. Please re check the code

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote