Answer to Question #189013 in C++ for Dunga

Question #189013
  1. Create a class named DogCare. Include fields for a dog’s data (using Dog class from question 1), the date (using Date class from question 4), the time (using Time class from question 3) and the duration of the appointment in minutes. Also include a field that contains the ending time of the appointment; this field will be calculated based on the start and the duration using Time class function that adds minutes to a Time object. The DogCare constructor requires dog name, a month, day, year, hour and minute for the appointment. Allow DogCare to be constructed with or without an additional argument for appointment duration, and force the duration to 30 minutes when no argument is supplied. The constructor does not allow any appointment over 240 minutes. The constructor calculates the appointment ending time based on the start time and the duration. Also include a display function for the DogCare class. Write a main() function that loops at least 5 times, prompting the user for DogCare data and displaying all the info
1
Expert's answer
2021-05-09T10:40:10-0400
#include <iostream>
#include <string>
#include <iomanip>


using namespace std;


class Dog
{
private:
	double licenseFee;
	string name;
	string breed;
	int age;
public:
	Dog(){
		licenseFee = 13.45;
	}


	Dog(string name, string breed, int age) {
		this->licenseFee = 13.45;
		this->name = name;
		this->breed = breed;
		this->age = age;
	}


	void setName(string name)
	{
		this->name = name;
	}
	void displayName()
	{
		cout << name;
	}




	void setBreed(string breed)
	{
		this->breed = breed;
	}
	void displayBreed()
	{
		cout << breed;
	}




	void setAge(int age)
	{
		this->age = age;
	}
	void displayAge()
	{
		cout << age;
	}


	void Display() {
		cout << "Dog's name: " << this->name<< endl;
		cout << "Dog's Breed: " << this->breed<< endl;
		cout << "Dog's age: " << this->age<< endl;
		cout << "Dog's license fee: $" << this->licenseFee << endl;
	}
};


class Date{
private:
	int month;
	int day;
	int year;
public:
	Date() { 
		this->day = 0;
		this->month = 0; 
		this->year = 0; 
	}
	Date(int day, int month, int year)
	{
		this->month = month;
		this->day = day; 
		this->year = year; 
	}
	void Display()
	{
		cout  << this->day << "." <<this->month<< "." <<this->year<< endl;
	}
};




class Time
{
private:
	int h;
	int m;
public:
	Time() { h = 0, m = 0; }


	Time(int hours, int minutes)
	{
		if (hours < 0) h = 0;
		else h = hours % 24;
		if (minutes < 0) m = 0;
		else m = minutes % 60;
	}


	void AddMinutes(int minutes)
	{
		if (m + minutes < 60){
			m += minutes;
		}else
		{
			m = (m + minutes) % 60;
			h = (h + 1) % 24;
		}
	} 


	void Display()
	{
		cout << h / 10 << h % 10 << ":" << m / 10 << m % 10 << endl;
	}
};


class DogCare{
private:
	Dog dog;
	Date dateAppointment;
	Time startTimeAppointment;
	//duration of the appointment in minutes
	int duration;
	//include a field that contains the ending time of the appointment; 
	//this field will be calculated based on the start and the duration 
	//using Time class function that adds minutes to a Time object. 
	Time endTimeAppointment;
public:
	DogCare(){}
	//The DogCare constructor requires dog name, a month, day, year, hour and minute for the appointment.
	DogCare(string name, string breed, int age,int month,int day,int year,int hour,int minute,int duration){
		// The constructor does not allow any appointment over 240 minutes. 
		if(duration<=240){
			this->dog=Dog(name,breed,age);
			this->dateAppointment=Date(day,month,year);
			this->startTimeAppointment=Time(hour,minute);
			this->endTimeAppointment=Time(hour,minute);
			//The constructor calculates the appointment ending time based on the start time and the duration.
			this->endTimeAppointment.AddMinutes(duration);
			this->duration=duration;
		}else{
			cout<<"\nAppointment over 240 minutes.\n";
		}
	}
	//Also include a display function for the DogCare class. 
	void Display()
	{
		if(duration<=240){
			this->dog.Display();
			cout<<"Date appointment: ";
			this->dateAppointment.Display();
			cout<<"Start time appointment: ";
			this->startTimeAppointment.Display();
			cout<<"End time appointment: ";
			this->endTimeAppointment.Display();
			cout<<"Duration of the appointment: "<<duration<<" minutes.";
		}else{
			cout<<"\nAppointment over 240 minutes.\n";
		}
	}
};


int main(){


	//Write a main() function that loops at least 5 times, 
	//prompting the user for DogCare data and displaying all the info
	DogCare dogCare[5];
	for(int i=0;i<5;i++){
		cout << "Enter details information for a dog "<<(i+1)<<"\n";
		string name;
		cout << "Enter a dog name: ";
		getline(cin, name);


		string breed;
		cout << "Enter a dogbreed: ";
		getline(cin, breed);




		int age;
		cout << "Enter a dog age: ";
		cin >> age;


		int day;
		cout << "Enter a day of appointment: ";
		cin >> day;


		int month;
		cout << "Enter a month of appointment: ";
		cin >> month;


		int year;
		cout << "Enter a year of appointment: ";
		cin >> year;


		int hour;
		cout << "Enter a hour of appointment: ";
		cin >> hour;


		int minute;
		cout << "Enter a minute of appointment: ";
		cin >> minute;


		int duration;
		cout << "Enter a duration of appointment: ";
		cin >> duration;
		cin.ignore();
		dogCare[i]=DogCare(name, breed, age,month,day, year, hour, minute, duration);
		cout<<"\n";
	}
	for(int i=0;i<5;i++){
		dogCare[i].Display();
		cout<<"\n\n";
	}
	system("pause");
	return 0;
}

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be the first!

Leave a comment

LATEST TUTORIALS
New on Blog
APPROVED BY CLIENTS