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...
#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. #...
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".
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...
C++ A void function named NextLeapYear() that takes an int reference parameter. If the parameter is...
C++ A void function named NextLeapYear() that takes an int reference parameter. If the parameter is positive, the function will assign it the next leap year after it; otherwise, the function will assign 4 to it.
PYTHON: Write a function named is_palindrome() that returns boolean True if a word or phrase is...
PYTHON: Write a function named is_palindrome() that returns boolean True if a word or phrase is a palindrome, and boolean False if it is not. The palindromes for this problem are contained in the list below. You must use this list in your solution. Use a for loop to retrieve each palindrome and test it. Your script should test each string in the list of palindromes below. Be aware there's a second list of palindromes embedded in the palindromes list....
Write a function, named isMultipleOfFive that accepts integer argument. When the function is called, it should...
Write a function, named isMultipleOfFive that accepts integer argument. When the function is called, it should display if the argument "is a multiple of 5" or "is not a multiple of 5".
3. Write a function named "countNonAlpha" that accepts a string. It will return the number of...
3. Write a function named "countNonAlpha" that accepts a string. It will return the number of non-alphabet characters (excluding blanks) in the string. For example, if the string is "Hello, World!", it will return 2 for ',' and '!" in the string. 4. Write a function named "deleteZeros" that takes two arguments: a. an array of integer values; b. an integer for the number of elements in the array; The function will return the number of zeros that it has...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT