First, combine the two into one set by using + (union) operator, and print out t
ID: 3672905 • Letter: F
Question
First, combine the two into one set by using + (union) operator, and print out the union set. The + operator must remove all duplicates and store one copy of any item. You also need to implement a subtraction operator (A-B means removing all elements of B from A) and print out the result. So the main function takes two sets of integers and print the result of + and - operation.
A sample input.dat may look like this. Note that we assume the input file includes only two sets of integer numbers, each number is separated by white spaces and sets are separated by a newline character. Note that you will probably have to use getline() <iostream> to get each line from the file and place it into a string, then stringstream <sstream> to parse the string into individual integers.
http://www.cplusplus.com/reference/sstream/stringstream/stringstream/ (Links to an external site.) is a good example of string stream.
3 4 5 7 5 16 7 12 11 12 3 9 9 8 1 12
15 4 3 6 1 12 3 12 7 8 19 9 11 12 8 5 -4 -100
Assume that all inputs are integers and anything else should be rejected with an error message.
Include a run-time asymptotic analysis (Best, Worst Case in terms of Big O) of member functions used in main in an analysis.txt file. Don't just say that it is Best Case O(n) and Worst Case O(N^2). Describe how many constant expressions, how many n expressions (loops), how many nested loops (n^2) etc. For Best case, describe the scenario (when x is the first value found etc.) You should submit a single lastnameHW2.zip containing: my_bag.h, my_bag.cpp, main.cpp, makefile, Readme.txt, and analysis.txt
Explanation / Answer
// FILE: bag1.cpp // From Chapter 3 of Data Structures and Other Objects (Second Edition) // ________________________________________________________________________ // // This file has been modified to work with Microsoft Visual C++ 6.0, // as described in www.cs.colorado.edu/~main/vc6.html // ________________________________________________________________________ // // CLASS IMPLEMENTED: bag (see bag1.h for documentation) // INVARIANT for the bag class: // 1. The number of items in the bag is in the member variable used; // 2. For an empty bag, we do not care what is stored in any of data; for a // non-empty bag the items in the bag are stored in data[0] through // data[used-1], and we don't care what's in the rest of data. #include // Provides copy function #include // Provides assert function #include "bag1.h" using namespace std; namespace main_savitch_3 { // (Omitted for VC++ 6.0) const bag::size_type bag::CAPACITY; bag::size_type bag::erase(const value_type& target) { size_type index = 0; size_type many_removed = 0; while (indexRelated Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.