Question

In: Computer Science

Don't use vectors use pointers ,classes & objects, functions and loop etc only C++ PROGRAM Following...

Don't use vectors use pointers ,classes & objects, functions and loop etc only

C++ PROGRAM

Following is a partial implementation of Set class.

You are required to enhance and implement the
following missing functions from the implementation:

A) UNION
B) reset
C) intersection
D) difference

A SAMPLE driver program :

int a1[] = {10,5,7,3,9};
Set s1(5);
s1.insert(a1,5);
s1.print("s1");
int a2[] = {2,9,6};
Set s2(3);
s2.insert(a2,3);
s2.print("s2");
Set s3 = s1.unionset(s2);
Set s4 = s1.intersection(s2);
Set s5 = s1.difference(s2);
s3.print("s3");
s4.print("s4");
s5.print("s5");

N.B

Don't use vectors use pointers ,functions and loop only

do display output

DO ADD COMMENTS WITH EACH LINE FOR BETTER UNDERSTANDING

Solutions

Expert Solution

C++ by calling function,loops,etc and without using vectors as mentioned

here is the which i have written

I have provided code and output of the code for proof just run and check it out

Sorry for output its not good enough to see but its correct for sure

#include <bits/stdc++.h> 
using namespace std; 

/* Function prints union of arr1[] and arr2[] 
m is the number of elements in arr1[] 
n is the number of elements in arr2[] */
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]) 
                        cout << arr1[i++] << " "; 

                else if (arr2[j] < arr1[i]) 
                        cout << arr2[j++] << " "; 

                else { 
                        cout << arr2[j++] << " "; 
                        i++; 
                } 
        } 

        /* Print remaining elements of the larger array */
        while (i < m) 
                cout << arr1[i++] << " "; 

        while (j < n) 
                cout << arr2[j++] << " \n"; 
} 
int 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 /* if arr1[i] == arr2[j] */
        { 
            cout << arr2[j] <<" \n";
            i++; 
            j++; 
        } 
    } 
} 
void symmDiff(int arr1[], int arr2[], int n, int m) 
{ 
    // Traverse both arrays simultaneously. 
    int i = 0, j = 0; 
    while (i < n && j < m) 
    { 
        // Print smaller element and move  
        // ahead in array with smaller element 
        if (arr1[i] < arr2[j]) 
        { 
            cout << arr1[i]<<" "; 
            i++; 
        } 
        else if (arr2[j] < arr1[i]) 
        { 
            cout << arr2[j]<<" "; 
            j++; 
        } 
  
        // If both elements same, move ahead 
        // in both arrays. 
        else
        { 
            i++; 
            j++; 
        } 
    } 
}
/* Driver program to test above function */
int main() 
{ 
        int arr1[] = { 1, 2, 4, 5, 6 }; 
        int arr2[] = { 2, 3, 5, 7 }; 

        int m = sizeof(arr1) / sizeof(arr1[0]); 
        int n = sizeof(arr2) / sizeof(arr2[0]); 

        // Function calling symmDiff(arr1, arr2, n, m); 
        printUnion(arr1, arr2, m, n ); 
    printIntersection(arr1, arr2, m, n);
    symmDiff(arr1, arr2, n, m); 

        return 0; 
} 

Attaching the output and program sample Screenshot just check it out for reference

Drop a comment if you have any doubt


Related Solutions

Write a C++ program (using pointers and dynamic memory allocation only) to implement the following functions...
Write a C++ program (using pointers and dynamic memory allocation only) to implement the following functions and call it from the main function. (1)Write a function whose signature looks like (char*, char) which returns true if the 1st parameter cstring contains the 2nd parameter char, or false otherwise. (2)Create an array of Planets. Populate the array and print the contents of the array using the pointer notation instead of the subscripts.
Search Benchmarks No Pointers or Vectors can be used for this program. Do not use exit,...
Search Benchmarks No Pointers or Vectors can be used for this program. Do not use exit, break, swap, or sort functions from C++. Write a program to generate an array of 100 random three-digit integers (100 – 999). The program should display the array values (formatted as columns, ten items per line). Once the numbers are generated, the user should be prompted for the search item. The program should use a linear search to find the item. The program should...
Write a C# code that creates objects and classes with their member functions for KrisFlyer, a...
Write a C# code that creates objects and classes with their member functions for KrisFlyer, a Singapore Airlines Loyalty program. You are asked to write an inheritance hierarchy discount system that benefits KrisFlyer members program to calculate their profit. A brief about KrisFlyer is that it is useful for those who fly on Singapore Airlines (its partners like Virgin Australia and Air New Zealand) frequently. KrisFlyer miles can be earned through credit cards, flying and bonus miles promotions. The miles...
IN C++ PLEASE. Use ONLY: exception handling, read and write files, arrays, vectors, functions, headers and...
IN C++ PLEASE. Use ONLY: exception handling, read and write files, arrays, vectors, functions, headers and other files, loops, conditionals, data types, assignment.   Calculating fuel economy. This program will use exceptions and stream errors to make a robust application that gets the number of miles and gallons each time the user fuels their car. It will put those values into vectors. Once the user wants to quit enter values, it will calculate the fuel economy. Create GetMiles() function that returns...
Problem: Construct a C program that will make use of user-defined functions, the do/while loop, the...
Problem: Construct a C program that will make use of user-defined functions, the do/while loop, the for loop, and selection. Using a do/while loop, your program will ask/prompt the user to enter in a positive value representing the number of values they wish to have processed by the program or a value to quit/exit. If the user enters a 0 or a negative number the program should exit with a message to the user indicating they chose to exit. If...
Java GPA calculator. Apply GUI, methods, exception handling, classes, objects, inheritance etc. The program should prompt...
Java GPA calculator. Apply GUI, methods, exception handling, classes, objects, inheritance etc. The program should prompt user for input. When done it should give an option to compute another GPA or exit.
For C++ Use arrays and or vectors, no classes. Visualize and consider 100 lockers all lined...
For C++ Use arrays and or vectors, no classes. Visualize and consider 100 lockers all lined up horizontally in a row Each locker is numbered from 1 to 100 in sequential order Every locker can be fully closed (open state = 0.00) Every locker can be fully opened (open = 1.00) Every locker can be partially open with any possible value between 0.00 and 1.00 inclusive on both ends A locker cannot ever be more closed than fully closed (open...
Write a complete C program that searches an element in array using pointers. Please use the...
Write a complete C program that searches an element in array using pointers. Please use the function called search to find the given number. //Function Prototype void search (int * array, int num, int size)
The concept of pointers in C++ is inherited from the C language, which relies extensively on the use of pointers.
  Topic: The concept of pointers in C++ is inherited from the C language, which relies extensively on the use of pointers. What are the advantages and disadvantages of having the functionality of pointers in a programming language?
Complete the provided C++ program, by adding the following functions. Use prototypes and put your functions...
Complete the provided C++ program, by adding the following functions. Use prototypes and put your functions below main. 1. Write a function harmonicMeans that repeatedly asks the user for two int values until at least one of them is 0. For each pair, the function should calculate and display the harmonic mean of the numbers. The harmonic mean of the numbers is the inverse of the average of the inverses. The harmonic mean of x and y can be calculated...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT