window added, vector size = 1 window added, vector size = 2 door added, vector size = 1 door added, vector size = 2 square window height = 8.99945e-039 Backdoor height = 2.13405e+033
using namespace std; #include <iostream> #include <vector> class Window{ private: float height; float width; public: void setH(float h) {height = h;} void setW(float w) {width = w;} float getH() {return height;} float getW() {return width;} }; class Door{ private: float height; float width; public: void setH(float h) {height = h;} void setW(float w) {width = w;} float getH() {return height;} float getW() {return width;} }; class Room{ private: float height; float width; float length; public: void setH(float h) {height = h;} void setW(float w) {width = w;} void setL(float l) {length = l;} float getH() {return height;} float getW() {return width;} float getL() {return length;} void addWindow(Window langas1); void addDoor(Door durys1); float getWallArea(); vector<Window> windowsVec; vector<Door> doorsVec; }; void Room::addWindow(Window window1){ windowsVec.push_back(window1); cout << "window added, vector size = " << windowsVec.size() << endl; } void Room::addDoor(Door door1){ doorsVec.push_back(door1); cout << "door added, vector size = " << doorsVec.size() << endl; } int main(){ Room LivingRoom; Window Square; Window Rectangular; Door Frontdoor; Door Backdoor; LivingRoom.addWindow(Square); LivingRoom.addWindow(Rectangular); LivingRoom.addDoor(Frontdoor); LivingRoom.addDoor(Backdoor); LivingRoom.setH(300); LivingRoom.setL(8000); LivingRoom.setW(6000); Square.setH(50); Square.setW(50); Rectangular.setH(60); Rectangular.setH(40); Frontdoor.setH(200); Frontdoor.setW(90); Backdoor.setH(180); Backdoor.setW(70); cout << "square window height = " << LivingRoom.windowsVec.at(0).getH() << endl; cout << "frontdoor height = " << LivingRoom.doorsVec.at(1).getH() << endl; return 0; }
push_back
Room::AddWindow()
vector::push_back()
var
This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)