C++ only Part 2 Write a program that reads time and date of birth in numeric for
ID: 3825047 • Letter: C
Question
C++ only Part 2 Write a program that reads time and date of birth in numeric form such as 8-27-1980 10:56:59 pm or 8-27-1980 22:56:59. If the time is in 12-hour notation and the date is in numeric form. The program then outputs the time in 24-hour notation and the date of birth in the form: August 27th, 1980 hh:mm:ss. If the time is in 24-hour notation and the date is in numeric form. The program then outputs the time in 12-hour notation and the date of birth in the form: August 27th, 1980 hh:mm:ss am or pm. Your program must contain at least 5 exception classes: InvalidHour, InvalidMinute, InvalidSec, InvalidDay, and InvalidMonth. If an invalid value for hour, minute, second, day or month was read, then the program should throw and catch the correct matching object. Don't worry about the Leap Year. An example may look like this: 8-27-1980 10:56:59 pm or 8-27-1980 22:56:59. You were born on August 27th, 1980 at 22:56:59 If invalid information was read, make sure you display a message stating that error, for example: 8-32-1980 15:61:00 am will result into: Invalid day: 32 Invalid hour: 15 Invalid minute: 61 Invalid timeperiod: am
Explanation / Answer
Answer :
C++ date of birth programe:
#include<iostream>
#include "dateTimeHeader.h"
using namespace std;
int main()
{
dateTime convert;
int hr,mn,sc=0;
cout<<"please input in 12 hr notation";
cin>>hr;
cout<<"please input minutes";
cin>>mn;
cout<<"please input seconds:";
cin>>sc;
convert.invalidHr(hr);
convert.invalidMin(mn);
convert.invalidSec(sc);
convert.printMilTime();
system("pause");
return 0;
}
#incluede<iostream>
#include "dataTimeHeader.h"
using namespace std;
int dateTime::invalideHr(int hour)
{
try{
if(hour <13&&hour>0)
{
hour=hour+12;
return hour;
}
else
{
cin.clear();
cin.ignore();
cout<<"Invalid input! Please input hour again in correct 12 hour farmat:";
cin>>hour;
invalidHr(hour);
throw 10;
}
}
catch(int c) {
cout<<"Invalid hour input! ";
}
}
int dateTime::invalidMin(int min)
{
try{
if(min<60&&min>0)
{
return min;
}
else{
cin.cleare();
cin.igonore();
cout<<"Invalid input! Please input minutes again in coorct 12 farmate:";
cin>>min;
invalidMin(min);
throw 20;
return 0;
}
}
catch(int e){ cout<<"Invalid minute input!"<<endl;}
}
int dataTime::invalidSec(int sec)
{
try{
if(sec<60&&sec>0)
{
return sec;
}
else {
cin.clear();
cin.ignore();
cout<<"Inavalid input! Please input secounds again in correct 12 hour format:";
cin>>sec;
invalidSec(sec);
throw 30;
return 0;
}
}
catch(int t)
{
cout<<"Invalid second input!"<<endl;
}
}
void dateTime::printMilTime()
{
cout<<"your time converted:"<<hour<<":"<<min<<":"<<sec;
}
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.