Answer:
See explaination
Explanation:
#include <iostream>
#include <stdio.h>
#include <string>
#include <cctype>
#include <stdlib.h>
#include <sstream>
using namespace std;
string itoa(int num)
{
stringstream converter;
converter << num;
return converter.str();
}
string convert(string str){
size_t pos = str.find_first_of(':');
string hour = str.substr(0,pos);
string min = str.substr(pos+1,2);
string ampm = str.substr(pos+4,2);
int h = atoi(hour.c_str())%12;
if(ampm == "pm" || ampm == "Pm" || ampm == "PM" || ampm == "pM")
hour = itoa(h+12);
else if(h == 0)
hour = "00";
else if(h<10)
hour = "0" + hour;
string mtime = hour + min;
return mtime;
}
int main() {
string ntime;
cout<<"Enter time: ";
getline(cin,ntime);
cout<<"Corresponding military time is "<<convert(ntime)<<" hours";
return 0;
}