Hi all, I am a new member here and I am glad to be a part of this great community :)
I want to discuss with you some problems that I have with my course project.
We have:
1. Class CPlane with brand and flight hours.
2. Class CAirtravel with name of company, nationality and map <CPlane, unsigned> for planes and number of destinations.
I have to write a member function of class CAirtravel that returns list<CPlane> of planes with flight hours < 2000 and number of destinations > 10.
I didn't notice the type mismatch at all, many thanks :)
So the right syntax is: list <CPlane> returnList()
The loop code looks a little strange, but since there are many CAirtravel objects in the vector, I need to call returnLst() for every object in order to accumulate the static list of planes.
In the last cycle I get the full list, containing all planes that meet the conditions.
Maybe it isn't an effective approach, I will be happy if you can suggest some code optimizations :)
class CPlane {
public:
string brand; //I need to print this variables using
unsigned hours; //multimap <CAirtravel, unsigned> airtravel
//in class CAirport
};
class CAirtravel {
public:
string company, nation;
map <CPlane, unsigned> plane; //!
multimap <string, unsigned> destination;
void print() {
map <CPlane, unsigned>::iterator iter;
multimap <string, unsigned>::iterator iter2;
cout<<"\nName of the company: "<<company;
cout<<"\nNationality: "<<nation;
for(iter = plane.begin(); iter != plane.end(); iter++) {
cout<<"\n\nPlane's brand: "<<iter->first.brand;
cout<<"\nFlight hours: "<<iter->first.hours;
cout<<"\nFlight destinations: "<<iter->second;
}
for(iter2 = destination.begin(); iter2 != destination.end(); iter2++) {
cout<<"\n\nDestination: "<<iter2->first;
cout<<"\nFlights: "<<iter2->second;
}
}
};
class CAirport {
string name;
unsigned flight;
multimap <CAirtravel, unsigned> airtravel;
};
I need to write data output function member of CAirport, but I can't get out the contents of the maps in CAirtravel objects through multimap <CAirtravel, unsigned> airtravel:
1 2 3 4 5 6 7 8 9 10 11 12 13
void info() {
multimap <CAirtravel, unsigned>::iterator m;
cout<<"\nName of airport: "<<name;
cout<<"\n\nFlight number: "<<flight;
cout<<"\n\nData of companies:\n\n";
for(m = airtravel.begin(); m != airtravel.end(); m++) {
cout<<"\nCompany: "<<m->first.company;
cout<<"\nNationality: "<<m->first.nation;
cout<<"\nNumber of flights: "<<m->second;
//cout<<m->first.plane.size() works but i want to print the contents too.
}
I tried to call the CAirtravel member function print(): m = airtravel.begin(); m->first.print();
But the result is error:
" 'print' : cannot convert 'this' pointer from 'const class CAirtravel' to 'class CAirtravel &' "