Run Code
|
API
|
Code Wall
|
Misc
|
Feedback
|
Login
|
Theme
|
Privacy
|
Patreon
VecHotel2
//g++ 7.4.0 ///////////////////////////////////////////////////////////////////////////// //VecHotel2: example of vector of class object //this code is created by Rezaul Hoque on August 15,2022; //contact:jewelmrh@yahoo.com;Dhaka,Bangladesh;https://rezaulhoque.wordpress.com,https://hoquestake.blogspot.com //note: codes shared by Rezaul Hoque on rextester are not for sale; they are created and shared to facilitate the algorithm learning process; many like Hoque use this platform to practice programming ;Rezaul hopes his contribution helps others to fine tune their learning; ////////////////////////////////////////////////////////////////////////////// #include <iostream> #include <queue> #include <string> #include <vector> using namespace std; class Hotel{ std::string star; int rent; public: Hotel(std::string s,int r); std::string getS() const; int getR() const; }; Hotel::Hotel(std::string s,int r) { this->star=s; this->rent=r; } std::string Hotel::getS() const { return this->star; } int Hotel:: getR() const { return this->rent; } int main() { Hotel a("***",900); Hotel b("****",3000); Hotel c("****",2500); Hotel d("**",1000); vector<Hotel> QS; QS.push_back(a); QS.push_back(b); QS.push_back(c); QS.push_back(d); std::cout<<"Hotels listed on stars:\nStars Rent\n"; vector<Hotel>::iterator it; for(it=QS.begin();it!=QS.end();it++){ std::cout<<it->getS()<<" "<<it->getR()<<" \n"; } std::cout<<"\n"; return 0; }
run
|
edit
|
history
|
help
0
stlsizeof.cc
CirclQ
Split in C++ (Simple)
Web Browser History
Let's Go!
Search a 2D Matrix
2015(M2)Mod.
Inherit
My Pratice
FuktExam.cpp