[HELP] array of structures code help

Design and implement the following program.
1. You have been hired to keep track of the available speaker’s for the local
Computer Tech Club.
2. Create a structure type that can store:
a. the name of a potential speaker
b. his/her telephone number (including the area code)
c. his/her speaking topic (topic of expertise)
d. the fee required by the speaker
3. Your program should create an array of 10 speakers – supply the data by initializing
the array of structures (see the examples in your textbook). DO NOT have the user
enter all of this data.
4. At this point in time (or sooner) – watch/take notes on the video, Solving the
Weather Statistics Problem, it’s found on our class BB website. It will help you see how
to deal with an array of structures and how to interface with functions. The
Weather_Statistics.cpp which I also included in this folder is the resulting program.
5. The program should be menu-driven which is considered a very user friendly
interface. If you do not remember how to create/implement a menu – look in the
textbook.
6. The menu should at least have the following options that allow the user to:
a. Display option, which displays (as a nicely formatted report with
columns/headings) all speakers, their topics and fee charged.
b. Search option, which lets the user search for a speaker on a particular topic –
the user need only type in a keyword. Your code will search the array of
structures looking at the “topic’s field”, and display all speakers who match
the topic. Otherwise – a message should be displayed stating that no
speakers are available.
i. a “search” is nothing more than looking at each array entry to see if the
keyword is available
ii. you’ll need to use one of the functions discussed in Chapter #10 to see if
the phrase is present
iii. this item takes some work – use the Discussion Board if you want to “discuss”
a strategy with your classmates.
c. Exit option, which terminates the program.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
#include <iostream>
#include <cstring>

using namespace std;

void displaySpeakers();
void searchSpeakers();
void menu();

struct speakerInfo{
    string name; //name of person who will be speaking
    char phoneNum[15]; //phone number of speaker inclusing area code
    string topic;   //topic or expertise of speaker
    double fee; //price or fee which will be attached
};

int main(){

    speakerInfo speakerOne =
    {
    "Speaker1",
    "555-555-5555",
    "topicX",
    7.50
    };

    cout << "Testing parts of structure: name, phone, topic, and fee::\n"
         << speakerOne.name <<" "<< speakerOne.phoneNum <<" "<< speakerOne.topic <<" "<<"$"<< speakerOne.fee <<" "<< endl;

    const int numSpeakers = 10;
    int selection;

    menu();
    do{
        cin >> selection;

        if(selection == 1)
            displaySpeakers(); //function call for displaying Speakers
        else if(selection == 2)
            searchSpeakers(); //function call to search for Speakers
        else if(selection == 5){
            menu();
        }
        else if(selection == 9){
            cout << "Thank you! Good Bye.";
        }
        else
            cout << "Invalid Menu Selection!\n\n";
      }while (selection != 9);



return 0;
}
//displays all 10 speakers and their name, phone, topic and fees
void displaySpeakers()
{
    cout << "We chose to display speakers\n";
    //array of 10 Speakers/ array of structures
    return;
}
//need to code for searching within the arrays for names or parts
void searchSpeakers(){
    cout << "We chose to search for speakers.\n";
    return;
}

void menu(){
    cout << "Please choose an option from the following:\n\n";
    cout << "1. Display current available Speakers.\n\n";
    cout << "2. Search for Speaker.\n\n";
    cout << "5. View menu.\n\n";
    cout << "Enter 9 to close the Program.\n\n";
    return;
}
Need help creating array of 10 speakers (number 3) for a start.
speakerInfo speakerOne[10];
can you explain a little on your reply? Not sure..

I figured id need a for loop in:
it would look somethign liek this, but i get a bunch of errors.
1
2
3
4
5
6
7
8
9
void displaySpeakers(speakerNum)
{
    //array of 10 Speakers/ array of structures
    for(int i=0; i<10; i++){
    cout << speakerNum[i]; 
    }

    return;
}
Last edited on
So I do not know if i quite good understand your instructions at point 3 but ...
you need an array of spekerInfo structure so you do somthing like this

speakerInfo speakerArray[10];

once you have this you can get each element of array by using [] and if you wish some data from object you just add a dot (.) and a name of element in structrure your function for displaying Speakers would be somthing like this
1
2
3
4
5
6
7
8
9
10
11
12
13
14
void displaySpeakers(speakerNum)
{
    //array of 10 Speakers/ array of structures
    for(int i=0; i<10; i++){
cout << "Speaker num "<< i+1<< endl;
cout << speakerNum[i].name<<endl; 
cout << speakerNum[i].phoneNum<<endl;
cout << speakerNum[i].topic<<endl
cout << speakerNum[i].fee<<endl
cout << "================================"<< endl;
    }

    return;
}

And you can determining specific object in array:
1
2
speakerArray[4].name="5. element";
  speakerArray[4].phoneNum="55554445";


hope it helps
Last edited on
Topic archived. No new replies allowed.