Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

program Write a single if test using Boolean operators and relational operators

ID: 669799 • Letter: P

Question

program Write a single if test using Boolean operators and relational operators to determine if a double variable x is between zero (exclusive) and one (inclusive). Print a message indicating that x is between zero and one inclusive. Show two ways to test for the complement of the Boolean expression. Write a static method which will take one integer argument and return a Boolean value. The function should use the modulus operator to determine if the integer input value is even or odd. If even, the return value should be true. If odd, the return value should be false.

Explanation / Answer

5.
#include<iostream.h>

void main()
{
   double x;

   cout<<"enter value for x";
   cin>>x;

   if(x>0 && x<=1)
   {
       cout<<"x is between zero and one";
   }
}

6.
#include<iostream.h>

bool static check(int n1)
{
   if(n1%2==0)
   {
       return true;
   }
   else
   {
       return false;
   }
}

void main()
{
   int n;
   bool ans;
   cout<<"Enter no";
   cin>>n;

   ans=check(n);

   cout<<ans;
}