Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

I can't create class Date object in the Accommodation class because the the Class Date constructor c++ #include #include using namespace std; class Date {

I can't create class Date object in the Accommodation class because the the Class Date constructor

c++

#include #include

using namespace std;

class Date {

private: int daysInMonth [12]={31,28,31,30,31,30,31,31,30,31,30,31}; short unsigned int day,month,year;

public: Date (int yy,int mm, int dd){

year=yy; month=mm; day=dd;

}

Date operator+(int n){ int newDay = day + n; int newMonth = month; int newYear = year;

while (newDay > daysInMonth[newMonth - 1]) { newDay -= daysInMonth[newMonth - 1]; newMonth++;

if (newMonth > 12) { newMonth = 1; newYear++; } }

return Date(newYear, newMonth, newDay); }

friend std::istream& operator>>(std::istream& is, Date& date) { char dash1, dash2; is >> date.year >> dash1 >> date.month >> dash2 >> date.day; return is; }

friend std::ostream &operator<<(std::ostream &os, const Date &d) { os << d.year << "-" << d.month << "-" << d.day; return os; }

};

enum struct Meals { no_meals, breakfast, half_board, all_inclusive };

std::ostream& operator<<(std::ostream& os, Meals meals) { switch (meals) { case Meals::no_meals: os << "no meals"; break; case Meals::breakfast: os << "breakfast"; break; case Meals::half_board: os << "half board"; break; case Meals::all_inclusive: os << "all inclusive"; break; } return os; }

double get_price(Meals meals) { switch (meals) { case Meals::no_meals: return 0; case Meals::breakfast: return 10; case Meals::half_board: return 20; case Meals::all_inclusive: return 50; } }

class Accomodation { private: std::string location; int nights; int singles; int doubles; double priceNightSingle; double priceNightDouble; double priceOneDayParking; Meals board; bool parking;

public: Accomodation(double priceNightSingle, double priceNightDouble, double priceOneDayParking) : priceNightSingle(priceNightSingle), priceNightDouble(priceNightDouble), priceOneDayParking(priceOneDayParking) { ask_data(); }

~Accomodation() { std::cout << "Accomodation successfully booked!" << std::endl; }

int get_guests() { return singles + doubles * 2; }

double get_price() { double price = (singles * priceNightSingle) + (doubles * priceNightDouble); if (parking) { price += (nights * priceOneDayParking); } return price + (get_guests() * get_price(board)); }

void ask_data() { std::cout << "Enter location of accomodation: "; std::cin >> location; std::cout << "Enter number of nights (max 28): "; std::cin >> nights; std::cout << "Enter number of single rooms: "; std::cin >> singles; std::cout << "Enter number of double rooms: "; std::cin >> doubles; std::cout << "Enter desired board (no_meals, breakfast, half_board, all_inclusive): "; std::cin >> board; std::cout << "Do you want to book a parking place? (y/n) "; char choice; std::cin >> choice; parking = (choice == 'y'); std::cout << "Total price: " << get_price() << " EUR" << std::endl; }

Note comment section is off.

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

PostgreSQL Up And Running A Practical Guide To The Advanced Open Source Database

Authors: Regina Obe, Leo Hsu

3rd Edition

1491963417, 978-1491963418

More Books

Students also viewed these Databases questions

Question

Describe the five-step decision-making process?

Answered: 1 week ago

Question

please dont use chat gpt AI 4 3 0 .

Answered: 1 week ago