Using good OOP, write a C++ program that will compare two arrays to test for the same elements and multiplicity.   To begin, populate the arrays with the input files, comFile1.txt and comFile2.txt.   The elements in the arrays do not need to be in the same order for them to be considered similar.  For example: array 1:    121    144    19    161    19    144    19    11 array 2:    11    121    144    19    161    19    144    19 would be considered to have the same elements because 19 appears 3 times in each array, 144 appears twice in each array, and all other elements appear once in each array. Use pointer notation instead of array notation whenever possible. Display whether or not the arrays have the same elements and multiplicity. Use private member functions and variables. Use public member functions for a constructor (where appropriate) and a driver method only. These specifications do not give a list of method names to be used.  It is assumed the program will use several methods doing one task each. This soultion below will work and I like it but what i am really trying to do is take the array and count the number time a unique number shows up and then at the end i only have to compare the vectors. this will cut down having to bubble sort large arrays. I hope that makes sense.       Expert Solution arrow_forward Step 1 Code: #include #include using namespace std; int readFile(int* array, ifstream &fin) {     int count = 0;     while(!fin.eof())     {        fin >> *(array+count);        count++;     }     return count; } void bubbleSort(int* array, int size) {     for(int i = 0; i < size-1; i++)         for(int j = 0; j < size-i-1; j++)             if(*(array + j) > *(array + j + 1))             {                int temp = *(array + j);                *(array + j) = *(array + j + 1);                *(array + j + 1) = temp;             } } int main() {     ifstream fin1, fin2;     fin1.open("comFile1.txt");     fin2.open("comFile2.txt");     int array1[20], array2[20];         int size1 = readFile(array1, fin1);     int size2 = readFile(array2, fin2);         if(size1 != size2)         cout << "The elements and multiplicity is not the same." << endl;     bubbleSort(array1, size1);     bubbleSort(array2, size2);     for(int i = 0; i < size1; i++)         if(*(array1 + i) != *(array2 + i))         {            cout << "The elements and multiplicity is not the same." << endl;            return 0;         }     cout << "The elements and multiplicity is the same." << endl;      }

Computer Networking: A Top-Down Approach (7th Edition)
7th Edition
ISBN:9780133594140
Author:James Kurose, Keith Ross
Publisher:James Kurose, Keith Ross
Chapter1: Computer Networks And The Internet
Section: Chapter Questions
Problem R1RQ: What is the difference between a host and an end system? List several different types of end...
icon
Related questions
Question

Using good OOP, write a C++ program that will compare two arrays to test for the same elements and multiplicity.   To begin, populate the arrays with the input files, comFile1.txt and comFile2.txt.   The elements in the arrays do not need to be in the same order for them to be considered similar.  For example:

array 1:    121    144    19    161    19    144    19    11
array 2:    11    121    144    19    161    19    144    19

would be considered to have the same elements because 19 appears 3 times in each array, 144 appears twice in each array, and all other elements appear once in each array.

Use pointer notation instead of array notation whenever possible.

Display whether or not the arrays have the same elements and multiplicity.

Use private member functions and variables.
Use public member functions for a constructor (where appropriate) and a driver method only.


These specifications do not give a list of method names to be used.  It is assumed the program will use several methods doing one task each.

This soultion below will work and I like it but what i am really trying to do is take the array and count the number time a unique number shows up and then at the end i only have to compare the vectors. this will cut down having to bubble sort large arrays. I hope that makes sense.

 

 

 

Expert Solution
arrow_forward
Step 1

Code:

#include <iostream>
#include <fstream>
using namespace std;
int readFile(int* array, ifstream &fin)
{
    int count = 0;
    while(!fin.eof())
    {
       fin >> *(array+count);
       count++;
    }
    return count;
}
void bubbleSort(int* array, int size)
{
    for(int i = 0; i < size-1; i++)
        for(int j = 0; j < size-i-1; j++)
            if(*(array + j) > *(array + j + 1))
            {
               int temp = *(array + j);
               *(array + j) = *(array + j + 1);
               *(array + j + 1) = temp;
            }
}
int main()
{
    ifstream fin1, fin2;
    fin1.open("comFile1.txt");
    fin2.open("comFile2.txt");
    int array1[20], array2[20];
   
    int size1 = readFile(array1, fin1);
    int size2 = readFile(array2, fin2);
   
    if(size1 != size2)
        cout << "The elements and multiplicity is not the same." << endl;
    bubbleSort(array1, size1);
    bubbleSort(array2, size2);
    for(int i = 0; i < size1; i++)
        if(*(array1 + i) != *(array2 + i))
        {
           cout << "The elements and multiplicity is not the same." << endl;
           return 0;
        }
    cout << "The elements and multiplicity is the same." << endl;     
}

Expert Solution
Problem

Using good OOP, write a C++ program that will compare two arrays to test for the same elements and multiplicity.   To begin, populate the arrays with the input files, comFile1.txt and comFile2.txt.   The elements in the arrays do not need to be in the same order for them to be considered similar.  For example:

trending now

Trending now

This is a popular solution!

steps

Step by step

Solved in 4 steps with 4 images

Blurred answer
Recommended textbooks for you
Computer Networking: A Top-Down Approach (7th Edi…
Computer Networking: A Top-Down Approach (7th Edi…
Computer Engineering
ISBN:
9780133594140
Author:
James Kurose, Keith Ross
Publisher:
PEARSON
Computer Organization and Design MIPS Edition, Fi…
Computer Organization and Design MIPS Edition, Fi…
Computer Engineering
ISBN:
9780124077263
Author:
David A. Patterson, John L. Hennessy
Publisher:
Elsevier Science
Network+ Guide to Networks (MindTap Course List)
Network+ Guide to Networks (MindTap Course List)
Computer Engineering
ISBN:
9781337569330
Author:
Jill West, Tamara Dean, Jean Andrews
Publisher:
Cengage Learning
Concepts of Database Management
Concepts of Database Management
Computer Engineering
ISBN:
9781337093422
Author:
Joy L. Starks, Philip J. Pratt, Mary Z. Last
Publisher:
Cengage Learning
Prelude to Programming
Prelude to Programming
Computer Engineering
ISBN:
9780133750423
Author:
VENIT, Stewart
Publisher:
Pearson Education
Sc Business Data Communications and Networking, T…
Sc Business Data Communications and Networking, T…
Computer Engineering
ISBN:
9781119368830
Author:
FITZGERALD
Publisher:
WILEY