How to reach array's elements from map?

Here is my codes;
I have map and arrays like this;

1
2
3
  Array dayHours{0,0,0,0,0,0};
Array1 day{"Monday","Tuesday","Wednesday","Thursday","Friday"};
map<pair<string,int>,pair<Array1 ,Array> > matchMap;


And i have a function like this;

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
void Course::addCourse()
{
    string a;
    int b;
    int total;
    int courseAdd;
    cout<<"How many course you want to add?"<<endl;
    cin>>courseAdd;
    cout<<"Enter the name of course and number of hours"<<endl;
    for(int i=0;i<courseAdd;++i)
    {

        setCourseName(a);
        setHours(b);
        getCourseList().insert({a, b});
        total += getHours();
        matchMap.insert({make_pair(a,b),make_pair(day,dayHours)});
    }


Here is the print function for map:

1
2
3
4
5
6
7
8
9
10
11
12
13

void Course::seeMap()
{
    map<pair<string,int>,pair<Array1 ,Array> >::iterator it;
    for(it=matchMap.begin();it!=matchMap.end();++it)
    {
        for(int i=0;i<5;++i)
        {
            cout<<(it->first).first<<(it->first).second<<(it->second).first[i]<<endl;
        }
    }
}


Here is what i get at the end:

1
2
3
4
5
6
7
8
9
10

How many course you want to add?
1
Enter the name of course and number of hours
Enter the course name
Coursenam1
Enter the course hours
4
You added the courses succesfully!
Coursenam
Coursenam1--->4--->Tuesday
Coursenam1--->4--->Wednesday
Coursenam1--->4--->Thursday
Coursenam1--->4--->Friday


What i need is a template like this;


1
2
3

Coursename1
Coursename2 ---> Coursehour2 ---> Tuesday;
Coursename3 ---> Coursehour3 ----> wednesday;



How can i do a template like this?
Last edited on
> How to reach array's elements from map?
let's go back a little, you are asking for a (horrible) implementation detail.
go to the big picture, ¿what do you want to do?

I don't understand why your map holds an array when it seems that you only want one day.
map<pair<string,int>,pair<Array1 ,Array> > matchMap;
You should use more descriptive names than Array and Array1. It will make the code much easier to write.

I suspect there's an easier way to do whatever you're trying to do here. Can you post the assignment and the full code?
Topic archived. No new replies allowed.