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.
|
#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;
}
Use c++ programming environment to implement and test a function with the following prototype: //the parameter...
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 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 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 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, 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 + 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; }
Introduction to Data Structures programming assignments can be completed either in C++ (preferred) or in Java. In both cases you cannot use libraries or packages that contain pre-built data structures, other than built-in support for objects, arrays, references, and pointers. Classes in C++ and Java can represent anything in the real world. This assignment is to write a class to represent a Date in a Calendar. Date Class Member Variables The following table identifies and describes the purpose of each...
C programming Write a function that is passed a month, day, and year and will determine if that date is valid. You can assume each parameter is passed in as an integer. Remember to check for leap year! validDate (5, 31, 1961) .... would be valid validDate (13, 4, 1967) ... would be invalid, the month is invalid
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...
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.