Interview question practice

error
question:A well renowned hotel has three branches in miami. Namely x,y and z (Actually they gave names). Each has two types of customers. Regular and Rewardee. Also each branch has its own ratings x is given a 3 star rating while y has 5 star rating and z has 4 star rating. Each hotel has specific rates for weekend and weekdays. x charges $100 for regular customers on weekdays and $120 on weekends While it is $90 for rewardee on weekdays and $60 on weekends. Similarly y charges $130 for regular customers on weekdays and $150
on weekends. While its $100 for rewardee on weekdays and $95 on weekends. While z charges $195 for regular customers on weekdays and $150 on weekends. While its $120 for rewardee on weekdays and $90 on weekends.
Now when the customer requests for a particular detail you need to find which hotel would yield the customer profit.

Hey @nmaurya760
What is the issue?

Error is coming where i am using value of enum data type in the main

Hey @nmaurya760
Here updated ur code to remove compilation erros : https://ide.codingblocks.com/s/360247
Mentioned the changes in comments :slight_smile:

1 Like

I have tried to implement abstract factory design pattern in this ques… Is the method fine?

Hey @nmaurya760
Yes its good :slight_smile:

1 Like

If the input is in this format
regular:16Mar2010(sun),19Mar2010(wed),21Mar2010(Fri)
Please modify my code

Hey @nmaurya760
I will have to write many lines of code for that.
The basic idea is just iterate over the dates and find if its a weekday or a weekend and calculate the cost accordingly .

Try to do this urself and I will help u debug ur code :slight_smile: if required

Rather than iterating cant we just use conditional statements in order to find out whether the day is weekend or week day coz we are din days as well along with the date

Can we make pirs in enum data type??

Yes in that case u can

1 Like

I am not sure about this ,never used enums before.
Please google this :slight_smile:

1 Like

I am getting really very confused while using singleton design pattern… In that v can make only one class and make various methods in it. This is what i understood , am i correct?

Hey @nmaurya760
Yes one class with only one object

1 more ques if i want user to enter string rather than the index in input variable how can we do that

U can use hashmaps then ,enter string and map it to enum inter index.

Enum me elements kese access krte h
I have done this but it is throwing error
customers customer;
unordered_map<string,int>m;
for(int i=0;i<customer.size();i++){
m[customer] = i;
}
cout<<“ENTER THE TYPE OF CUSTOMER”<<endl;
cin>>input;
customer = (customers)m[input];
x.c = customer;
y.c = customer;

You cant access enum like that ,enum is also a mapping.
You have to manually map string to indexes
m[“regular”]=0;
…

But lets say we have 1000 elements in enum then are v supposed to map them manually?

How u add entries to enum, manually right :slight_smile: