Question

In: Computer Science

Write a program driver that demonstrates that your additions work. Use the following sets as part...

Write a program driver that demonstrates that
your additions work. Use the following sets as part of your demonstration
A {1,3,8}
B {2,3,5,10}
C {4,6}
show
A && B
A - B
A || B
A / B
A && C
A - C
A || C
A / C

Solutions

Expert Solution

class Question{

/* m is the number of elements in arr1[]

   n is the number of elements in arr2[]

o is the number of elements in arr3 */

    static void printIntersection(int arr1[], int arr2[], int m, int n)

    {

        int i = 0, j = 0;

        while (i < m && j < n) {

            if (arr1[i] < arr2[j])

                i++;

            else if (arr2[j] < arr1[i])

                j++;

            else {

                System.out.print(arr2[j++] + " ");

                i++;

            }

        }

    }

    static int printUnion(int arr1[], int arr2[], int m, int n)

    {

        int i = 0, j = 0;

        while (i < m && j < n) {

            if (arr1[i] < arr2[j])

                System.out.print(arr1[i++] + " ");

            else if (arr2[j] < arr1[i])

                System.out.print(arr2[j++] + " ");

            else {

                System.out.print(arr2[j++] + " ");

                i++;

            }

        }

    static void relativeComplement(int arr1[], int arr2[],int m, int n)

{

        int i = 0, j = 0;

        while (i < n && j < m)

        {

            if (arr1[i] < arr2[j])

            {

              System.out.print(arr1[i]+"");

                i++;

            }

else if (arr1[i] > arr2[j])

            {

                j++;

            }

            else if (arr1[i] == arr2[j])

            {

                i++;

                j++;

            }

        }

        while (i < n)

            System.out.print(arr1[i] + " ");

    }

    public static void main(String args[])

    {

        int arr1[] = {1,3,8};

        int arr2[] = {2,3,5,10};

  int arr2[] = {4,6};

        int m = arr1.length;

        int n = arr2.length;

  int o = arr3.length;

        printIntersection(arr1,arr2,m,n);

  printUnion(arr1,arr2,m,n);

relativeComplement(arr1,arr2,m,n)

    }

}

A\B is same as A-B both are called as Rlative Complement.

please follow the above program for other.


Related Solutions

Assignment Purpose Write a well commented java program that demonstrates the use and re-use of methods...
Assignment Purpose Write a well commented java program that demonstrates the use and re-use of methods with input validation. Instructions It is quite interesting that most of us are likely to be able to read and comprehend words, even if the alphabets of these words are scrambled (two of them) given the fact that the first and last alphabets remain the same. For example, “I dn'ot gvie a dman for a man taht can olny sepll a wrod one way.”...
Write a well-commented java program that demonstrates the use of loops, and generation of random integers...
Write a well-commented java program that demonstrates the use of loops, and generation of random integers (Code will be written in Dr. Java) You are taking some time off from your paint business and currently are on vacation in Bahamas. You decide to write a Java program that generates 10 random numbers between 1 and 20 (all integers). You cannot use arrays (even if you know what they are) to store these numbers. It then picks up the largest number...
1)Write a C++ program which clearly demonstrates how the dangling else ambiguity is resolved. Your program...
1)Write a C++ program which clearly demonstrates how the dangling else ambiguity is resolved. Your program should print distinct results depending on if C++ uses inner-if or outer-if resolution. Turn in a listing of your program, the output, and a description of how your program demonstrates the semantic resolution of the ambiguity. 2) Give a context-free grammar describing the syntax of the following; Non-empty strings of 0’s and 1’s that represent binary numbers that have odd parity
Part 1 Write a program that prompts the user to enter three sets of five double...
Part 1 Write a program that prompts the user to enter three sets of five double numbers each. These numbers represent the five grades that each of three students has received. After prompting for the grades, the program: stores the data in a previously defined 3◊5 double array computes the average of each set of 5 grades after acquiring the grades for that one student determines the maximum and minimum values of each set of 5 grades acquiring the grades...
Write an assembly program that demonstrates multiplication operation in 80x86 assy languuage
Write an assembly program that demonstrates multiplication operation in 80x86 assy languuage
Assignment Purpose The purpose of this lab is to write a well-commented java program that demonstrates...
Assignment Purpose The purpose of this lab is to write a well-commented java program that demonstrates the use of loops, and generation of random integers. Instructions You are taking some time off from your paint business and currently are on vacation in Bahamas. You decide to write a Java program that generates 10 random numbers between 1 and 20 (all integers). You cannot use arrays (even if you know what they are) to store these numbers. It then picks up...
You are currently part of a university work experience program. Your job placement is at the...
You are currently part of a university work experience program. Your job placement is at the municipal transit centre. Your supervisor is responsible for the recording and distribution of monthly transit passes to authorized vendors throughout the city. The vendors pay €50 per bus pass and sell them for €55. Your job is to prepare a monthly reconciliation of the transit passes including the quantity sold, the number actually distributed, the unsold passes, and the cash proceeds. You are unable...
Need to write a program and part 1 of the program is to write an HTML...
Need to write a program and part 1 of the program is to write an HTML code, here are the parameters, but I am new to HTML and I am confused as to how to write this. 1) HTML file shall:         - have your name(s) somewhere near the top, as a comment.         - be a complete html document with appropriate html tags.         - have 1 form with 2 parts, described as follows:         part 1:             -...
Given the following program readline.cpp and the data file e2_input.txt: // Program readline.cpp demonstrates how to...
Given the following program readline.cpp and the data file e2_input.txt: // Program readline.cpp demonstrates how to read a line of text from a file #include <iostream> #include <fstream> #include <string> using namespace std; int main() { string str1, str2, str3, str4; // declares 4 variables ifstream inData; // declares input stream ofstream outData; // declares output stream inData.open("e2_input.txt"); // binds program variable inData to the input file "input.txt" outData.open("e2_output.txt"); // binds program variable outData to the output file "output.txt" //...
Write a C program that does the following In this part, you will write more complicated...
Write a C program that does the following In this part, you will write more complicated functions. They will require parameters and return values. The purpose is to give you experience with these components, and to show you how functions can be used to break your code down into smaller parts. You will also get some more experience with iterating through arrays.Open repl project Lab: User-Defined Functions 2. Write a program that does the following: 1.(20 pts.) Allows the user...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT