In: Computer Science
Declare and define a function named
getCurrentHours_OR_Month that accepts
one Boolean parameter. If the Boolean parameter is true, the
function returns
current hours; if the Boolean parameter is false, the function
returns current month.
o This function will obtain the current system time and extract the
hours or the
month value from the system time depending on the Boolean
being
received.
o This function will return the extracted value as an integer
value.
o Note that the system time displays the month in 3 character
format, for
example Jan for January. You need to return an integer so you need
to
convert the “string months” to “integer months” using suitable
mapping
between them.
o This function will be called by the functions dispGreeting and
dispWeather
later.
GIVEN IS THE FUNCTION:
int getCurrentHours_OR_Month(bool b)
{
time_t curr_time;
tm * curr_tm;
char month_string[100];
char hour_string[100];
curr_time=time(NULL);
curr_tm = localtime(&curr_time);
if(b==true){
strftime(hour_string, 50, "%H", curr_tm);
int h=atoi(hour_string);
}
else{
strftime(month_string, 50, "%m", curr_tm);
int m=atoi(month_string);
}
}
BELOW IS IMPLEMENTATION:
#include<bits/stdc++.h>
using namespace std;
int getCurrentHours_OR_Month(bool b)
{
time_t curr_time;
tm * curr_tm;
char month_string[100];
char hour_string[100];
curr_time=time(NULL);
curr_tm = localtime(&curr_time);
if(b==true){
strftime(hour_string, 50, "%H", curr_tm);
int h=atoi(hour_string);
}
else{
strftime(month_string, 50, "%m", curr_tm);
int m=atoi(month_string);
}
}
void dispGreeting()
{
}
void dispWeather()
{
}
int main()
{
cout<<getCurrentHours_OR_Month(true)<<" ";
cout<<getCurrentHours_OR_Month(false);
return 0;
}