Question: please help fix this code so the HotelReservation and Reservation use the dates entered in the main, also so that the default date 0 1

please help fix this code so the HotelReservation and Reservation use the dates entered in the main, also so that the default date 01-01(january 1st) is zero days from january first when its printed
//date.cpp
#include "Date.h"
using namespace std;
#include
#include
const unsigned Date::daysInMonth[]={0,31,28,31,30,31,30,31,31,30,31,30,31};
Date::Date() : days_(1){}
unsigned Date::calculateDays(int month, int day) const{
unsigned totalDays =0;
for(int i =1; i < month; i++){
totalDays += getDaysInMonth(i);
}
if(!(month ==1 && day ==1)){
totalDays +=(day -1);
}
return totalDays;
}
unsigned Date::getDaysInMonth(int month) const{
return (month >=1 && month <=12)? daysInMonth[month] : 0;
}
void Date::getMonthDay(int& month, int& day) const{
unsigned totalDays = days_;
month =1;
while (totalDays > getDaysInMonth(month)){
totalDays -= getDaysInMonth(month);
++month;
}
day = totalDays;
}
ostream& operator<<(ostream& os, const Date& date){
int month, day;
date.getMonthDay(month, day);
os << setfill('0')<< setw(2)<< month <<'/'<< setw(2)<< day;
os <<"("<< date.days_<<" days from january 1)";
return os;
}
Date& Date::operator=(const string& dateStr){
size_t pos = dateStr.find('/');
int month = stoi(dateStr.substr(0, pos));
int day = stoi(dateStr.substr(pos +1));
int totalDays = day ;
for (int i =0; i < month; i++){
totalDays += Date::daysInMonth[i];
}
days_= totalDays;
return *this;
}
bool Date::operator>=(const string& dateStr) const{
Date otherDate;
otherDate = dateStr;
return days_>=otherDate.days_;
}
bool Date::operator<=(const string& dateStr) const{
Date otherDate;
otherDate = dateStr;
return days_<= otherDate.days_;
}
///date.h
#ifndef DATE_H
#define DATE_H
#include
#include
using namespace std;
class Date {
private:
unsigned days_;
static const unsigned daysInMonth[];
unsigned calculateDays(int month, int day) const;
unsigned getDaysInMonth(int month) const;
void getMonthDay(int& month, int& day) const;
public:
Date();
unsigned getDays() const{return days_;}
friend std::ostream& operator<<(std::ostream& os, const Date& date);
Date& operator=(const std::string& dateStr);
bool operator>=(const std::string& dateStr) const;
bool operator<=(const std::string& dateStr) const;
};
#endif
//Reservation.h
#ifndef RESERVATION_H
#define RESERVATION_H
#include "Date.h"
#include
class Reservation{
private:
std::string reservationName;
Date reservationDate;
float reservationFee;
protected:
bool is_high_season;
public:
Reservation(const string& reservationName, int day, int month, float fee =0);
string to_string() const;
double calculate_cost() const;
};
#endif
//Reservation.cpp
#include "Reservation.h"
#include "Date.h"
#include
#include
#include
Reservation::Reservation(const string& reservationName, int day, int month, float fee) : reservationName(reservationName),reservationFee(fee){
}
//string
string Reservation::to_string() const{
stringstream ss;
ss << reservationName <<" on "<< reservationDate <<"
Fee: $"<< fixed << setprecision(2)<< reservationFee;
return ss.str();
}
//calc cost
double Reservation::calculate_cost() const{
double cost = reservationFee;
if(is_high_season == true){
return reservationFee *2;
}else{
return reservationFee;
}
}
///HotelReservation.h
#ifndef HOTELRESERVATION_H
#define HOTELRESERVATION_H
#include "Date.h"
#include "Reservation.h"
#include
class HotelReservation : public Reservation{
private:
string hotelName;
double costPerNight;
int nights;
public:
HotelReservation(const string& reservationName, int day, int month, const string& hotelName, double costPerNight, int nights);
std::string to_string() const;
double calculate_cost() const;
};
#endif
///HotelReservation.cpp
#include "HotelReservation.h"
#include
#include "Reservation.h"
#include "Date.h"
#include
HotelReservation::HotelReservation(const string& reservationName, int day, int month, const string& hotelName, double costPerNight, int nights) : Reservation(reservationName, day, month), hotelName(hotelName), costPerNight(costPerNight), nights(nights){}
string HotelReservation::to_string() const{
string reservationDetails = "Hotel Reservation Details:
";
reservationDetails += Reservation::to_string();
reservationDetails +=" for "+ std::to_string(nights)+" nights at "+ hotelName;
double totalCost = calculate_cost();
return reservationDetails;
}
double HotelReservation::calculate_cost() const{
double totalCost = costPerNight * nights;
if(is_high_season ==true){totalCost *-1.5;}
return totalCost

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!