27/03/2023

Hotel Prices Hackerrank Solution in C++ | Debugging

Hotel Prices Hackerrank Solution in C++. In this challenge, the task is to debug the existing code to successfully execute all provided test files. The given code defines two classes HotelRoom and HotelApartment denoting respectively a standard hotel room and a hotel apartment. An instance of any of these classes has two parameters: bedrooms and bathrooms denoting respectively the number of bedrooms and the number of bathrooms in the room.

The prices of a standard hotel room and hotel apartment are given as:

Hotel Room: 50. bedrooms + 100. bedrooms.
Hotel Apartment: The price of a standard room with the same number of bedrooms and bathrooms plus 100.

Hotel Prices Hackerrank Solution in C++

For example, if a standard room costs 200, then an apartment with the same number of bedrooms and bathrooms costs 300.

In the hotel's codebase, there is a piece of code reading the list of rooms booked for today and calculating the total profit for the hotel. However, sometimes calculated profits are lower than they should be.

Debug the existing HotelRoom and HotelApartment classes' implementations so that the existing code computing the total profit returns a correct profit.

Your function will be tested against several cases by the locked template code.

Input Format

The input is read by the provided locked code template.
In the first line, there is a single integer n denoting the number of rooms booked for today.
After that n lines follow. Each of these lines begins with a room_type which is either standard or apartment and is followed by the number of bedrooms and the number of bathrooms in this room.

Constraints

1 <= n <= 100
There is at least 1 and at most 5 bedrooms in a room
There are at least 1 and at most 5 bathrooms in a room

Output Format

The output is produced by the provided and locked code template. It calculates the total profit by iterating through the vector of all rooms read from the input.

Sample Input 0

2
standard 3 1
apartment 1 1

Sample Output 0

500

Submit your solution here: Click here

Hotel Prices Hackerrank Solution in C++


#include <cmath>
#include <cstdio>
#include <vector>
#include <iostream>
#include <algorithm>
#include <string>
using namespace std;

int main()
{
	int a;
	int cost = 0;
	int bedroom, bathroom;
	cin >> a;
	string room_type = "";
	for (int i = 0; i < a; i++)
	{
		cin >> room_type;
		cin >> bedroom;
		cin >> bathroom;
		if (room_type == "standard")
		{
			cost += 50 *bedroom + 100 * bathroom;
		}

		if (room_type == "apartment")
		{
			cost += 50 *bedroom + 100 *bathroom + 100;
		}
	}

	cout << cost;

	return 0;
}

The Output of Hotel Prices Hackerrank Solution


The Output of Hotel Prices Hackerrank Solution

Similar to Hotel Prices


Previous Post
Next Post

post written by:

Hi, I’m Ghanendra Yadav, SEO Expert, Professional Blogger, Programmer, and UI Developer. Get a Solution of More Than 500+ Programming Problems, and Practice All Programs in C, C++, and Java Languages. Get a Competitive Website Solution also Ie. Hackerrank Solutions and Geeksforgeeks Solutions. If You Are Interested to Learn a C Programming Language and You Don't Have Experience in Any Programming, You Should Start with a C Programming Language, Read: List of Format Specifiers in C.
Follow Me

0 Comments: