Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

the code shows me error in line 142 and 187 #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

the code shows me error in line 142 and 187

#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; }

class Request { private: const unsigned int no; static unsigned int lastNo; Accomodation* accomodation; Request* next;

public: Request(Accomodation* accomodation, Request* next = nullptr) : no(++lastNo), accomodation(accomodation), next(next) {}

~Request() { std::cout << "Request #" << no << " has been deleted." << std::endl; delete accomodation; }

unsigned int get_no() { return no; }

Request* get_next() { return next; }

void set_next(Request* next) { this->next = next; }

double get_price() { return accomodation->get_price(); }

void print() { std::cout << "Request #" << no << ": "; accomodation->print(); } };

unsigned int Request::lastNo = 0;

void print() { std::cout << "Location: " << location << std::endl; std::cout << "Guests: " << get_guests() << std::endl; std::cout << "Nights: " << nights << std::endl; std::cout << "Single rooms: " << singles << " (" << priceNightSingle << " EUR/night)" << std::endl; std::cout << "Double rooms: " << doubles << " (" << priceNightDouble << " EUR/night)" << std::endl; std::cout << "Board: " << board << " (" << get_price(board) << " EUR/person/day)" << std::endl; std::cout << "Parking: " << (parking ? "yes" : "no") << " (" << (parking ? priceOneDayParking : 0) << " EUR/day)" << std::endl; std::cout << "Total price: " << get_price() << " EUR" << std::endl; } };

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

Database Development For Dummies

Authors: Allen G. Taylor

1st Edition

978-0764507526

More Books

Students also viewed these Databases questions

Question

Aware of differences in the role of employees unions.

Answered: 1 week ago