Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include<iostream>
- #include<string.h>
- using namespace std;
- class Restaurant
- {
- char* name;
- int price;
- public:
- Restaurant()
- {
- name=new char[0];
- }
- Restaurant(char* n, int c)
- {
- name = new char[strlen(n)+1];
- strcpy(name,n);
- price=c;
- }
- Restaurant(const Restaurant &rhs)
- {
- name=new char[strlen(rhs.name)+1];
- strcpy(name,rhs.name);
- price=rhs.price;
- }
- int getPrice()
- {
- return price;
- }
- ~Restaurant()
- {
- delete[] name;
- }
- };
- class Hotel
- {
- char name[15];
- int prices[12];
- int stars;
- bool hasRestaurant;
- Restaurant* restaurant;
- public:
- Hotel(){}
- Hotel(char *n, int *p, int s)
- {
- hasRestaurant=false;
- strcpy(name,n);
- for(int i=0;i<12;i++)
- prices[i]=p[i];
- stars=s;
- }
- Hotel &operator++()
- {
- if(stars<5)
- ++stars;
- return *this;
- }
- friend ostream &operator<< (ostream &output, const Hotel &rhs)
- {
- output<<rhs.name<<" "<<rhs.stars;
- if(rhs.hasRestaurant)
- output<<" with restaurant";
- output<<endl;
- return output;
- }
- bool operator>=(int s)
- {
- return this->stars>=s;
- }
- int computeDailyPrice(int m)
- {
- if(m<1 || m>12)
- throw 0;
- if(hasRestaurant)
- return prices[m-1]+restaurant->getPrice();
- return prices[m-1];
- }
- void setRestoran(Restaurant &r)
- {
- hasRestaurant=true;
- restaurant=new Restaurant(r);
- }
- ~Hotel(){}
- };
- int main(){
- Hotel h; //creating object of class Hotel
- // in the following part the hotel info is read
- char imeHotel[15],imeRestoran[30];
- int ceni[12];
- int broj,cenaRestoran;
- bool daliRestoran;
- cin>>imeHotel;
- for (int i=0;i<12;i++) cin>>ceni[i];
- cin>>broj;
- cin>>daliRestoran;
- // if it is restaurant
- if (daliRestoran) {
- cin>>imeRestoran>>cenaRestoran;
- Hotel pom(imeHotel,ceni,broj);
- Restaurant r(imeRestoran,cenaRestoran);
- pom.setRestoran(r);
- h=pom;
- }
- else{
- Hotel *pok=new Hotel(imeHotel,ceni,broj);
- h=*pok;
- }
- // increment stars for 2
- ++h;
- ++h;
- int cena;
- int mesec;
- cin>>mesec;
- try{
- cena=h.computeDailyPrice(mesec); //here the function is called
- cout<<"Hotel info:"<<endl;
- cout<<h;
- if (h>=4)
- cout<<"The hotel has more than 4 stars.\n";
- cout<<"The price in month "<<mesec<<" is "<<cena; //се печати цената за дадениот месец
- }
- catch (int){
- cout<<"The index is out of bounds!";
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement