Question

In this assignment you will transform that program into a function with the following prototype bool...

In this assignment you will transform that program into a function with the following prototype bool xor(bool a, bool b)
As in your original program, xor returns the exclusive or of a and b. Then write a program that calls xor for all four possible combinations of a and b( false-false, false- true, etc) The output of that program is a table with three columns a, b, and xor, appropriately labeled and the results of all four combinations listed:

a b xor(a,b)

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

C Code:

#include<stdio.h>
#include<stdbool.h>

//Function Declaration
bool xor(bool a, bool b);

int main() {
   int v,w;
   bool a[]= {false, true};
   bool b[]= {false, true};
   printf("a       b      a xor b ");
   printf("-------------------------- ");
   for(v= 0; v<=1; v++){
       for (w= 0; w<=1; w++){
           // calling the function automatically for all the combinations between a and b

           // I used 2 for loops to get all the combinations of boolean variables a and b
           bool x = xor(a[v],b[w]);
           printf(a[v] ? "true " : "false");
           printf("   ");
           printf(b[w] ? "true = " : "false = ");
           printf(x ? "true " : "false ");
       }
   }
  
   return 0;
}

// function for the XOR operator
bool xor(bool a, bool b){
    // ^ operator gives the xor results between two boolean variables
    return a^b;
}

Output:

Add a comment
Know the answer?
Add Answer to:
In this assignment you will transform that program into a function with the following prototype bool...
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
  • 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)...

  • Write a C function bool arrayEqual that compares two 2D arrays. It accepts the following arguments...

    Write a C function bool arrayEqual that compares two 2D arrays. It accepts the following arguments int a[ROW][COL], int b[ROW][COL], m, n (m and n are the size of the rows and columns correspondingly). It returns true if all the corresponding elements are equal in a and b, otherwise false. Write the main function. Initialize two arrays (e.g. 3*4 dimension).

  • Using C++ Question#1: isPalíndrome Write the following function: bool isPalindrome(int) takes an integer and returns true...

    Using C++ Question#1: isPalíndrome Write the following function: bool isPalindrome(int) takes an integer and returns true if that integer is palindrome, otherwise it returns false. The function also prints the digits of the integer in reverse order in which they were found. Write a main) function that reads an integer, calls the function is whether the integer is a palindrome or not. Palindrome), and prints Sample input/output: nter an integer: 23434 nter an integer 23432 3434 is not a palindrome...

  • LAB 7-Movie List Program Goali Your assignment is to write a C++program to implement the ADT...

    LAB 7-Movie List Program Goali Your assignment is to write a C++program to implement the ADT List by creating a list of movies. This assignment will help you practice: multiple file programming, classes, pablic and private methods, dynamie memory, constructors and destructors, arrays and files Implementation the required classes This lab assignment gives you the opportunity to practice creating classes and using dynamic memory in one of There are two classes to implement: Movie and MovieList. As you can see...

  • program. 13. What's the output of the following program? #include< iostream> #include&math> using namespace std; int...

    program. 13. What's the output of the following program? #include< iostream> #include&math> using namespace std; int p 7; void main) extern double var int p abs(-90); system( "pause"); double var = 55; 14. How many times does "#" print? forlint i 0;j< 10; +ti) if(i-2141 6) continue; cout<< "#"; 15. Write the function declaration/prototype for a, pow function b floor function 16. State True or False a. b. c. d. e. isupper function returns a double value for loop is...

  • • bool test(int a, int& b) { bool res = false; if(a > b) { b...

    • bool test(int a, int& b) { bool res = false; if(a > b) { b = a%2; res = true; } return res; } int main() { int x = 45, y = 43; test(x, y); cout << x << " " << y << endl; return 0; } Question: The output of the above code is: ________________ •Write a function that takes an integer as its sole parameter and returns -1, 0 or 1 depending upon whether the...

  • Map, Filter, and Reduce are three functions commonly used in functional programming. For this assignment you...

    Map, Filter, and Reduce are three functions commonly used in functional programming. For this assignment you will be implementing all three, along with three minor functions that can be passed to them. Map The map function takes as arguments a function pointer and a integer vector pointer. It applies the function to every element in the vector, storing the results in-order in a new vector. It then returns a pointer to a new vector. You should pass your square function...

  • Public: bool older(wine &); returns false otherwise int ageDifference(wine &); Postcondition: ret...

    public: bool older(wine &); returns false otherwise int ageDifference(wine &); Postcondition: returns the difference in years produced (must be a positive value) between the calling object and the one explicitly passed to the function bool costlier(wine &); // Postcondition: returns true if the calling objectis"costlier than the object explicitly passed to the function returns false otherwise void inputValuesForwineobj); / Prompts the user to enter type, year, and cost of the calling wine object (a bottle) // Postcondition: data members of...

  • For this assignment, you will create a program that tests a string to see if it...

    For this assignment, you will create a program that tests a string to see if it is a palindrome. A palindrome is a string such as “madam”, “radar”, “dad”, and “I”, that reads the same forwards and backwards. The empty string is regarded as a palindrome. Write a recursive function: bool isPalindrome(string str, int lower, int upper) that returns true if and only if the part of the string str in positions lower through upper (inclusive at both ends) is...

  • 7. Suppose that the equal 1ists function (page 49 of Sebesta) is called with the lists...

    7. Suppose that the equal 1ists function (page 49 of Sebesta) is called with the lists ((A (B)) (C) ) and ((A (B)) (C)) as the arguments. How many calls of equal lists will be performed altogether, including the original call and all recur- sive calls? The following is an example of a Lisp program: Lisp Example function The following code defines a Lisp predicate function that takes two lists as arguments and returns True ;if the two lists are...

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