Question

In: Computer Science

Declare and define a function named getCurrentHours_OR_Month that accepts one Boolean parameter. If the Boolean parameter...

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.

Solutions

Expert Solution

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;
}






Related Solutions

C++ Please Define a function named "isAscending" that accepts a string as an input parameter and...
C++ Please Define a function named "isAscending" that accepts a string as an input parameter and returns "true" if all the characters included in the string are ordered in ascending order of their ASCII codes or the input string is a null string, and returns "false" otherwise. For example, if the string "ABXab" is passed to the function, it returns "true" because the ASCII code of 'B' is greater than 'A', 'X' is greater than 'B', 'a' is greater than...
ALL IN PYTHON PLEASE Problem 3: Define a VALUE-RETURNING function that accepts one parameter - an...
ALL IN PYTHON PLEASE Problem 3: Define a VALUE-RETURNING function that accepts one parameter - an integer number. The function, which must be a value-returning function, returns 1 if the number is even or 0 if the number is odd. In the “main” function (i.e. def main()), capture the return value and print an appropriate message on screen (i.e. number is even or odd). Rubric: Correctly defined a value-returning function: 5 pts Correctly capture and use return value from a...
Define a JavaScript function named showBins which has one parameter which is a JSON blob (JSON...
Define a JavaScript function named showBins which has one parameter which is a JSON blob (JSON encoding). The parameter encodes an array of Numbers. Your function should display the value at index 0 of the array in a text element whose id is "small", display the value at index 1 of the array in a text element whose id is "med", and display the value at index 2 of the array in a text element whose id is "large".
Define a function in Javascript named secondHighest which accepts an array of numbers, and returns the...
Define a function in Javascript named secondHighest which accepts an array of numbers, and returns the second highest number from the array. If the highest value occurs more than once, then it is also the second highest (see example). Assume the input array will always have length at least two (so there is always a second highest value). The original array must NOT be modified by this function. Example secondHighest([5,3,8,6,2,7,4]) must return 7, and secondHighest([5,3,8,6,2,7,8]) must return 8. I have...
#Write a function called "load_file" that accepts one #parameter: a filename. The function should open the...
#Write a function called "load_file" that accepts one #parameter: a filename. The function should open the #file and return the contents.# # # - If the contents of the file can be interpreted as # an integer, return the contents as an integer. # - Otherwise, if the contents of the file can be # interpreted as a float, return the contents as a # float. # - Otherwise, return the contents of the file as a # string. #...
Create a function named ‘dividing’. This function will take one parameter value, which will be an...
Create a function named ‘dividing’. This function will take one parameter value, which will be an integer. For the function you will use ‘Exception Handling’ with the use of the try and except statements to try and return the results of a number divided by the parameter value given to the function. If the parameter passed to the function is the integer value of zero then your function should return ‘You tried to divide by zero!’ through the use of...
Define a function named "find" that accepts two input parameters: "s "and "ch". "s" is an...
Define a function named "find" that accepts two input parameters: "s "and "ch". "s" is an object of the type "string" and "ch" is a character value with the default argument of 'A'. The function looks for the character "ch" in the string  "s" and displays all the indices of its occurrences on the screen. For example, if the caller sends the values of "ABCDBGAB" and 'B' to the function for the parameters "s" and "ch", respectively, the function displays the...
In java Write a static method named consecutiveDigits that accepts an integer n as a parameter...
In java Write a static method named consecutiveDigits that accepts an integer n as a parameter and that returns the highest number of consecutive digits in a row from n that have the same value. For example, the number 3777785 has four consecutive occurrences of the number 7 in a row, so the call consecutiveDigits(3777785) should return 4. For many numbers the answer will be 1 because they don't have any adjacent digits that match. Below are sample calls on...
Code in Golang: Write a boolean function called share with one integer parameter which determines whether...
Code in Golang: Write a boolean function called share with one integer parameter which determines whether the sum of the digits in the inputted integer and the inputted integer share a factor other than one. If so, return true, otherwise return false. Examples: 121 sum is 4, so the function returns false 242 sum is 8, so the function returns true
Create your own function in Java that accepts one input parameter and returns a float number....
Create your own function in Java that accepts one input parameter and returns a float number. You decide the theme.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT