Question

The istime function takes a string as its parameter and return True if the string represent...

The istime function takes a string as its parameter and return True if the string represent a valid time in the format of hh:mm or hh-mm format. It returns False otherwise.

For example,

istime("12:30"), istime("04-15"), istime("02:09") all return True.

istime("ab:cd"), istime("1234"), and istime("04-98") all return False.

It's critical that you include test case code to show proper testing.

0 0
Add a comment Improve this question Transcribed image text
Answer #1

This function takes an array of character as an input parameter and returns True if the string represent a valid time in the format of hh:mm or hh-mm format otherwise returns false.


//the function to check time is valid or not
bool istime(char t[5])
{
//variable declarion
bool flag = false;
int hh, mm;
//check if : or - is present or not in the string
if(t[2] == ':' || t[2] == '-')
{
//variable declaration
int t0, t1, t3, t4;
//convert character to integer value
t0 = t[0] - 48;
t1 = t[1] - 48;
t3 = t[3] - 48;
t4 = t[4] - 48;
hh = t0 * 10 + t1;
mm = t3 * 10 + t4;
//check hour and minute value
if(hh<=24 && mm <=60)
flag = true;
}
return flag;
}

Add a comment
Know the answer?
Add Answer to:
The istime function takes a string as its parameter and return True if the string represent...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • Write a method in java named isValidEmail that takes a string as input parameter, and returns...

    Write a method in java named isValidEmail that takes a string as input parameter, and returns true if that string represents a valid email address, or false otherwise. An email address is considered valid if it follows this format “user123@domain.ext”, where:  user123 represents a sequence of word characters (i.e., letters, digits, or underscore) whose length is between 1 and 10 (inclusive), but the first character must be a letter  domain represents a sequence of alphanumeric characters (i.e., letters...

  • Write a function “ssnChecker” that takes a string “s” and validates if the string is in...

    Write a function “ssnChecker” that takes a string “s” and validates if the string is in a valid social security number format (999-99-9999). The function must return a Boolean value (True or False).

  • In C++, write a function isOdd() that takes one integer parameter. The function returns true if...

    In C++, write a function isOdd() that takes one integer parameter. The function returns true if the number if odd and false otherwise.

  • Define a function in pycharm (isValid) that takes a password as a parameter and returns true...

    Define a function in pycharm (isValid) that takes a password as a parameter and returns true if the password is valid or false if the password is invalid. A valid password must be at least 8 characters long and contains $, _, or @. Invoke the function and print valid or invalid according to the returned Boolean value. Sample, if (isValid(password) == True): print(“Valid”) Or, result = isValid(password) If (result): print(“invalid”)

  • Write a function named "find_key" that takes a key-value store as a parameter with strings as...

    Write a function named "find_key" that takes a key-value store as a parameter with strings as keys and integers as values. The function returns a boolean representing true if the string "focus" is in the input as a key, false otherwise(javascript)

  • PYTHON 3!!!!! Write a function: class Solution { public String solution(String T); } that, given a...

    PYTHON 3!!!!! Write a function: class Solution { public String solution(String T); } that, given a string T, returns the latest valid time that can be obtained from T, as a string in the format "HH:MM", where HH denotes a two-digit value for hours and MM denotes a two-digit value for minutes. Examples: 1. Given T = "2?:?8", the function should return "23:58". 2. Given T = "?8:4?", the function should return "18:49". 3. Given T = "??:??", the function...

  • Write a function that takes two string parameters which represent the names of two people and...

    Write a function that takes two string parameters which represent the names of two people and returns True if the people are a "match" and False if they are not. Determining Love Total all the ‘L’s ‘O’s ‘V’s and ‘E’s (uppercase and lowercase) found in each of their names. If the number of LOVE letters combined between both their names is odd, return True. If the number of LOVE letter combined between both their names is even, return False. *...

  • Write a recursive method isReverse(String s1, String s2) that takes two strings and returns true if...

    Write a recursive method isReverse(String s1, String s2) that takes two strings and returns true if s1 is the reverse of s2, false otherwise. Then, draw the sequence of recursive calls for the following cases. Submit your diagrams in a PDF file called isReverseTrace.pdf. isReverse("happy", "yppah") will return true isReverse("cool", "loac") will return false isReverse("", "") will return true

  • Define the is_a_valid_date() function which is passed a string as a parameter. The function returns a...

    Define the is_a_valid_date() function which is passed a string as a parameter. The function returns a boolean indicating whether the parameter string is a valid date or not. The first two lines of the function are: month_names = ["January", "February", "March","April", "May", "June", "July", "August", "September", days_in_month = (31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31) where month_names is a list of valid month names, and days_in_month is a list which contains the maximum day number...

  • Define the is_a_valid_date() function which is passed a string as a parameter. The function returns a...

    Define the is_a_valid_date() function which is passed a string as a parameter. The function returns a boolean indicating whether the parameter string is a valid date or not. The first two lines of the function are: month_names = ["January", "February", "March", "April", "May", "June", "July", "August", "September", days_in_month = [31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31] where month_names is a list of valid month names, and days_in_month is a list which contains the maximum day...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT