In: Computer Science
Create a program that will prompt me for each of the following items:
1. Date of Birth
2. Typical wake up time
3. Next Dentist Appointment. ( Date and Time)
Create a Date structure and a method to load and return the date structure. Create a Time-of-day structure and a method to load and return the Time-of-day structure. Create a DateTime structure that includes the Date and Time-Of-Day structure.
The Date structure should include year, month, day. The Time-of-day structure should include hour and minute.
Use these structures and apply them to the processing of the input of the 3 items listed above. Display the structured data for each of the 3 listed data items.
Avoid redundancy where possible ( In other words, avoid duplicated code and write method(s) as needed to avoid duplication). This primarily applies to the processing of item 3.
Code:-
#include<iostream>
using namespace std;
//Create structure of type date with year, month and day as
members.
typedef struct Date
{
   int year;
   char month[100];
   int day;
}date;
//Create structure of type time of day with hour and minute as
members.
typedef struct Time_Of_Day
{
   int hour;
   int minute;
}timeOfDay;
//Create structure datetime and data members are the objects of
date and timeOfDay structure because it has to store both.
typedef struct DateTime
{
   date dobj;
   timeOfDay tobj;
}dateTime;
//Create method to take input for date structure
date input_date()
{
   date date_obj;
   cout<<"Enter Year: ";
   cin>>date_obj.year;
   cout<<"Enter Month: ";
   cin>>date_obj.month;
   cout<<"Enter Day: ";
   cin>>date_obj.day;
   return date_obj;
}
//Create method to take input for timeOfDay structure
timeOfDay input_time()
{
   timeOfDay time_obj;
   cout<<"Enter Hour: ";
   cin>>time_obj.hour;
   cout<<"Enter Minute: ";
   cin>>time_obj.minute;
   return time_obj;
}
//Create method to print date structure. Here, pass by reference is
used
void output_date(date& d)
{
  
cout<<d.year<<"-"<<d.month<<"-"<<d.day;
}
//Create method to print timeOfDay structure. Here also, pass by
reference is used
void output_time(timeOfDay& td)
{
   cout<<td.hour<<":"<<td.minute;
}
//Driver code to test.
int main()
{
   //Create objects of all the structures.
   date date_obj;
   timeOfDay time_obj;
   DateTime dt_obj;
   //Input date of birth
   cout<<"Enter your date of birth:\n";
   date_obj=input_date();
   //input wake up time
   cout<<"Enter your typical wake up
time:\n";
   time_obj=input_time();
   //input appointment date and time
   cout<<"Enter your next dentist appointment date
and time:\n";
   dt_obj.dobj=input_date();
   dt_obj.tobj=input_time();
   cout<<endl<<endl;
   //display DOB
   cout<<"Your Date Of Birth is: ";
   output_date(date_obj);
   cout<<endl;
   //display wake up time
   cout<<"Your Typical Wake Up Time is: ";
   output_time(time_obj);
   cout<<endl;
   //display dentist's appointment date and time
   cout<<"Your Next Dentist Appointment is on:
";
   output_date(dt_obj.dobj);
   cout<<" ";
   output_time(dt_obj.tobj);
   cout<<endl;
   //END of driver code
   return 0;
}
Output:-

Please UPVOTE thank you...!!!