0% found this document useful (0 votes)
36 views4 pages

CPP Building Class

The document defines two classes: Room and Building. Room represents a room with attributes like ID, capacity, used seats. Building represents a building with an array of rooms and methods to build from room data, assign rooms for events, and calculate utilization. The main function creates an array of rooms, builds a building from it, assigns a room for an event, and prints the utilization.

Uploaded by

Mohammad saif
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
36 views4 pages

CPP Building Class

The document defines two classes: Room and Building. Room represents a room with attributes like ID, capacity, used seats. Building represents a building with an array of rooms and methods to build from room data, assign rooms for events, and calculate utilization. The main function creates an array of rooms, builds a building from it, assigns a room for an event, and prints the utilization.

Uploaded by

Mohammad saif
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 4

#include "room.

h"
class Building{
private:
Room *room;
int numberOfRooms;
public:
//constructor
Building();
/************************************************************/
void Build(Room data[],int n);
string AssignRoomForEven(string event_name,int needed_seats);
float Utilization();
};

#include <iostream>
using namespace std;
class Room{
private:
string id;
string event_name;
int capacity;
int used_seats;
public:
//constructor
Room();
Room(string,int,int);
//setters
void setCapacity(int);
void setUsedSeats(int);
void setID(string);
void setEvent(string);
//getters
int getCapacity();
int getUsedSeats();
string getID();
string getEvent();
};

#include "Building.h"

#include<string>
int main(){
Room RoomSet1[20];
string id;
int capacity;
for(int i=0; i<20 ;i++){
cout<<"please enter the id of room "<<i<<" : ";
cin>>id;
cout<<"please enter the capacity of room "<<i<<" : ";
std::cin>>capacity;
cout<<endl;
RoomSet1[i].setCapacity(capacity);
RoomSet1[i].setID(id);
RoomSet1[i].setUsedSeats(0);
}
Building ITBuilding;
ITBuilding.Build(RoomSet1,20);
cout<<ITBuilding.AssignRoomForEven("Orcale Trining",15)<<endl;
cout<<"Utilization : "<<ITBuilding.Utilization()<<endl;
}

#include"Building.h"
Building::Building(){

numberOfRooms = 0;
room = NULL;
}
void Building::Build(Room data[],int n){
if(room!=NULL)
delete [] room;
room = new Room[n];
numberOfRooms = n;
for(int i=0 ; i<n ; i++)
room[i]=data[i];
}
string Building::AssignRoomForEven(string event_name,int needed_seats){
for(int i=0; i<numberOfRooms ; i++){
if(room[i].getCapacity() >= needed_seats ){
room[i].setUsedSeats(needed_seats);
room[i].setEvent(event_name);
return room[i].getID();
}
}
return "N/A";

}
float Building::Utilization(){
float numberOfUsedSeats=0,numberOfTotalSeats=0;
for(int i=0; i<numberOfRooms ; i++){
numberOfTotalSeats += room[i].getCapacity();
numberOfUsedSeats += room[i].getUsedSeats();
}
return numberOfUsedSeats/numberOfTotalSeats;
}

#include "room.h"
Room::Room(){event_name = "no event for this room";}
Room::Room(string _id,int _capacity,int _used_seats){

id = _id;
capacity = _capacity;
used_seats = _used_seats;
event_name = "no event for this room";
}
/*****************************************************/
void Room::setID(string _id){id = _id;}
void Room::setEvent(string _event){event_name = _event;}
void Room::setCapacity(int _capacity){capacity = _capacity;}
void Room::setUsedSeats(int _used_seats){used_seats = _used_seats;}
/*****************************************************/
string Room::getID(){return id;}
string Room::getEvent(){return event_name;}
int Room::getCapacity(){return capacity;}
int Room::getUsedSeats(){return used_seats;}

You might also like