In c++ and given the following classes Class home { protected: Int data; String
ID: 3767270 • Letter: I
Question
In c++ and given the following classesClass home { protected: Int data; String city; Public: Int get_data ( ); Void set_data ( int d); String get_city( ); Void set_city( string c); Virtual void find( ); }; Class hotel { protected: Int cost; String location; public: Int get_cost ( ); Void set_cost (int d); String get_location( ); Void set_location( string d); Virtual void find( ); };
Class motel : public Hotel { Protected: Int miles; vector < home * > list; Public: Int get_miles (); Void set_miles( int m); Virtual void find( ); };
How do you initialize the vector list and then print all its values using a function in the motel class?
In c++ and given the following classes
Class home { protected: Int data; String city; Public: Int get_data ( ); Void set_data ( int d); String get_city( ); Void set_city( string c); Virtual void find( ); }; Class hotel { protected: Int cost; String location; public: Int get_cost ( ); Void set_cost (int d); String get_location( ); Void set_location( string d); Virtual void find( ); };
Class motel : public Hotel { Protected: Int miles; vector < home * > list; Public: Int get_miles (); Void set_miles( int m); Virtual void find( ); };
How do you initialize the vector list and then print all its values using a function in the motel class?
Class home { protected: Int data; String city; Public: Int get_data ( ); Void set_data ( int d); String get_city( ); Void set_city( string c); Virtual void find( ); }; Class hotel { protected: Int cost; String location; public: Int get_cost ( ); Void set_cost (int d); String get_location( ); Void set_location( string d); Virtual void find( ); Int get_cost ( ); Void set_cost (int d); String get_location( ); Void set_location( string d); Virtual void find( ); };
Class motel : public Hotel { Protected: Int miles; vector < home * > list; Public: Int get_miles (); Void set_miles( int m); Virtual void find( ); }; Virtual void find( ); };
How do you initialize the vector list and then print all its values using a function in the motel class?
Explanation / Answer
#include<vector>//include vector to source file
using namespace std;
Class home
{ protected:
Int data;
String city;
Public:
Int get_data ( );
Void set_data ( int d);
String get_city( );
Void set_city( string c);
Virtual void find( );
};
Class hotel
{ protected:
Int cost;
String location;
public:
Int get_cost ( );
Void set_cost (int d);
String get_location( );
Void set_location( string d);
Virtual void find( );
};
Class motel : public Hotel
{
Protected:
Int miles;
static const int list[]={1,2,3,4,5};
std::vector <int> list(array,array+sizeof(array)); //declares and initialises the list of vector elements
Public:
Int get_miles ();
Void set_miles( int m);
Virtual void find( );
//The following printlist function is used to print elements of the vector named list
void printlist(){
for(int i=list.begin();i!=list.end();i++)
std::cout<<*i<<std::endl;
}
};
For any furthur queries contact me.thank you.
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.