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

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...
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...
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?
this program is to be done in c language. Using Pointers Create a program pointerTester.c to...
this program is to be done in c language. Using Pointers Create a program pointerTester.c to experiment with pointers. Implement the following steps one by one in your program: YOU NEED TO ANSWER QUESTION Use printf to print your answers at the end(after 12). 1. Declare three integer variables a, b and c. Initialize them to 0, 100 and 225, respectively. 2. Print the value of each variable and its address. 3. Add the following declaration to your code: int...
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...
Classes and Objects Write a program that will create two classes; Services and Supplies. Class Services...
Classes and Objects Write a program that will create two classes; Services and Supplies. Class Services should have two private attributes numberOfHours and ratePerHour of type float. Class Supplies should also have two private attributes numberOfItems and pricePerItem of type float. For each class, provide its getter and setter functions, and a constructor that will take the two of its private attributes. Create method calculateSales() for each class that will calculate the cost accrued. For example, the cost accrued for...
A. What are Objects? B. How do Objects differ from Classes? C. Where are Objects stored...
A. What are Objects? B. How do Objects differ from Classes? C. Where are Objects stored in Memory? D. Why do you not need to declare when you are finished using an Object in Java? E. Can you edits the contents of a String? View keyboard shortcuts EditViewInsertFormatToolsTable 12pt Paragraph
Write this program in C++ language. Use the concept of structures. DO NOT use vectors. Q...
Write this program in C++ language. Use the concept of structures. DO NOT use vectors. Q (4) Create a structure called time. Its three members, all type int, should be called hours, minutes, and seconds. Write a program that prompts the user to enter a time value in hours, minutes, and seconds. This should be in 12:59:59 format. This entire input should be assigned first to a string variable. Then the string should be tokenized thereby assigning the 1st token...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT