I am trying to solve the following C++ problem over structures. I am having trouble with the very last structure and I made a comment next to where I am confused. I included the assignment instructions and my current code. I would appreciate if anyone can help me explain what I need to do for the last structure. Thank you.
Assignment Instructions
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.
My Code:
#include
#include
#include
using namespace std;
struct date
{
int year;
int month;
int day;
};
struct timeOfDay
{
int hour;
int minute;
};
struct dateTime
{
date apptDate;
timeOfDay apptTime;
};
void getDate(date &);
void getTime(timeOfDay &);
void getDate(date &d)
{
cout << "Enter Month (Up to 2
digits):";
cin >> d.month;
cout << "Enter Day (Up to 2 digits):";
cin >> d.day;
cout << "Enter Year:";
cin >> d.year;
}
void getTime(timeOfDay &t)
{
cout << "Hour:";
cin >> t.hour;
cout << "Minute:";
cin >> t.minute;
}
void outputDate(date &d)
{
cout << "Your date of birth is ";
cout << d.year << "-" << d.month
<< "-" << d.day << endl;
}
void outputTime(timeOfDay &t)
{
cout << "Your typical wake up time is ";
cout << t.hour << ":" << t.minute
<< endl;
}
int main()
{
date d;
timeOfDay t;
dateTime apt;
cout << "Enter your date of birth" <<
endl;
getDate(d);
outputDate(d);
cout << "When is your typical wake up time?"
<< endl;
getTime(t);
outputTime(t);
cout << "When is your next dentist
appointment?";
cin >> // I am confused here
system("pause");
}
If you need any corrections kindly comment.
Please give a Thumps Up if you like the answer.
Program
#include<iostream>
#include<iomanip>
using namespace std;
struct date
{
int year;
int month;
int day;
};
struct timeOfDay
{
int hour;
int minute;
};
struct dateTime
{
date apptDate;
timeOfDay apptTime;
};
void getDate(date &);
void getTime(timeOfDay &);
void getDate(date &d)
{
cout << "Enter Month (Up to 2
digits):";
cin >> d.month;
cout << "Enter Day (Up to 2 digits):";
cin >> d.day;
cout << "Enter Year:";
cin >> d.year;
}
void getTime(timeOfDay &t)
{
cout << "Hour:";
cin >> t.hour;
cout << "Minute:";
cin >> t.minute;
}
void outputDate(date &d)
{
cout << d.year << "-" << d.month
<< "-" << d.day << endl;
}
void outputTime(timeOfDay &t)
{
cout << t.hour << ":" << t.minute
<< endl;
}
int main()
{
date d;
timeOfDay t;
dateTime apt;
cout << "Enter your date of birth" <<
endl;
getDate(d);
cout << "Your date of birth is ";
outputDate(d);
cout << "When is your typical wake up time?"
<< endl;
getTime(t);
cout << "Your typical wake up time is ";
outputTime(t);
cout << "When is your next dentist
appointment?";
getDate(apt.apptDate);
getTime(apt.apptTime);
cout<< "Your appointment date is :";
outputDate(apt.apptDate);
cout<< "Your appointment time is :";
outputTime(apt.apptTime);
}
Get Answers For Free
Most questions answered within 1 hours.