Question

Use c++ programming environment to implement and test a function with the following prototype: //the parameter...

Use c++ programming environment to implement and test a function with the following prototype:

//the parameter month and day should represent a valid date
//return true if the date is between 3/8 and 10/31; false otherwise
bool is_daylight(int month, int day);

Following TDD (test-driven development), it is important to know the expected return values for different function calls.

Function call

Expected return

Function call

Expected return

is_daylight(2, 20)

false

is_daylight(3, 7)

false

is_daylight(4, 1)

true

is_daylight(10, 31)

true

is_daylight(11, 1)

false

is_daylight(12, 15)

false

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

#include<iostream>

using namespace std;

bool is_daylight(int month, int day){

switch(month){ //parameters should be valid

case 3: if(day>=8 && day <=31)

return true;

case 4:

case 6:

case 9: if(day<=30 && day >=1)

return true;

case 5:

case 7:

case 8:

case 10: if(day<=31 && day>=1)

return true; //return true if all is well

}

return false; //return false otherwise

}

int main(){

cout<<is_daylight(4,1); // one test vase

return 0;

}

Add a comment
Know the answer?
Add Answer to:
Use c++ programming environment to implement and test a function with the following prototype: //the parameter...
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
  • C++ Write a function sleepIn with two parameters 'weekday' and 'vacation'. The parameter 'weekday' is True...

    C++ Write a function sleepIn with two parameters 'weekday' and 'vacation'. The parameter 'weekday' is True if it is a weekday, and the parameter 'vacation' is True if we are on vacation. We sleep in if it is not a weekday or we're on vacation. Return True if we can sleep in. function prototype: bool sleepIn(bool weekday, bool vacation): Function Call Function Returns sleepIn(false, false); true OK      sleepIn(true, false); false OK      sleepIn(false, true); true OK      sleepIn(true, 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...

  • Write a recursive function (C++) that searches a binary tree that is NOT ordered like a...

    Write a recursive function (C++) that searches a binary tree that is NOT ordered like a BST. In other words, there is no ordering relationship among the parent, child or sibling node values. Use the following prototype and data structure: struct node { node *left; node *right; int val; }; // First parameter: pointer to a node // Second parameter: the value to find bool searchValue(node *, int); The function searchValue() should return true if the integer value in the...

  • C++ PROGRAMMING Implement a bool function whose header is given below. Inside the function, declare, ask,...

    C++ PROGRAMMING Implement a bool function whose header is given below. Inside the function, declare, ask, and get a character from the user. The function will return true if the character the user enters is NOT in either of the words, otherwise it will return false. Keep in mind that uppercase and lowercase letters are not the same. You will need to change both words and the character input by the user to the same case (upper or lower) -...

  • C++ Programming Use the following function to create a program that determines whether (n ^ 2...

    C++ Programming Use the following function to create a program that determines whether (n ^ 2 + 1) is prime for each of the primes not exceeding 1000. bool check_prime(int input) { for(int i = 2; i <= sqrt(input); ++i) {    if(input % i == 0)    {        return false;    } } return true; }

  • 6. define a C++ class having the following members: (1) 2 instance methods  the prototype...

    6. define a C++ class having the following members: (1) 2 instance methods  the prototype of the first method is double funA(int r). The parameter r represents the radius of a circle. The funA will calculate the area of a circle and the value of its radius is from the parameter r. It will return the area of the circle.  the prototype of the second method is double funB(int w, int h). The parameters w and h represent...

  • Please help with Java programming! This code is to implement a Clock class. Use my beginning...

    Please help with Java programming! This code is to implement a Clock class. Use my beginning code below to test your implementation. public class Clock { // Declare your fields here /** * The constructor builds a Clock object and sets time to 00:00 * and the alarm to 00:00, also. * */ public Clock() { setHr(0); setMin(0); setAlarmHr(0); setAlarmMin(0); } /** * setHr() will validate and set the value of the hr field * for the clock. * *...

  • C programming Write a function that gets a 2-d array of given dimensions of ints. It...

    C programming Write a function that gets a 2-d array of given dimensions of ints. It returns true if the array contains two rows with exactly the same values in the same order, and returns false otherwise, bool contains_equal_rows(int height, int width, const int ar[height] [width]) Examples: On input {{1,2,3,4}, {2,3,4,1}, {1,2,3,4}} it returns true. On input {{1,2,3,4}, {2,3,4,5}, {3,4,5,6}} it returns false. On input {{1,1,1,1}, {2,2,2,2}, {1,1,1,6}} it returns false.

  • must be done in C You will implement a function that matches one of the prototypes...

    must be done in C You will implement a function that matches one of the prototypes below. int maxArray(int size, int* arr); int maxArray(int size, int arr]); The first parameter is the number of elements in the array. The second parameter is an address to the beginning of an int array. In the body of the function, use a looping structure to identify and return the maximum (largest number) of the array. NOTE: The maximum of the same number, say...

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
ADVERTISEMENT